mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 01:04:09 +02:00
commit
24983c344c
@ -31,11 +31,11 @@ class LayoutController extends ActionController
|
|||||||
{
|
{
|
||||||
$topbarHtmlParts = array();
|
$topbarHtmlParts = array();
|
||||||
|
|
||||||
/** @var Hook\Layout\TopBar $hook */
|
/** @var Hook\TopBarHook $hook */
|
||||||
$hook = null;
|
$hook = null;
|
||||||
|
|
||||||
foreach (Hook::all('TopBar') as $hook) {
|
foreach (Hook::all('TopBar') as $hook) {
|
||||||
$topbarHtmlParts[] = $hook->getHtml($this->getRequest(), $this->view);
|
$topbarHtmlParts[] = $hook->getHtml($this->getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->topbarHtmlParts = $topbarHtmlParts;
|
$this->view->topbarHtmlParts = $topbarHtmlParts;
|
||||||
|
@ -41,6 +41,15 @@ class Hook
|
|||||||
*/
|
*/
|
||||||
public static $BASE_NS = 'Icinga\\Web\\Hook\\';
|
public static $BASE_NS = 'Icinga\\Web\\Hook\\';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append this string to base class
|
||||||
|
*
|
||||||
|
* All base classes renamed to *Hook
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public static $classSuffix = 'Hook';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset object state
|
* Reset object state
|
||||||
*/
|
*/
|
||||||
@ -114,7 +123,7 @@ class Hook
|
|||||||
*/
|
*/
|
||||||
private static function assertValidHook($instance, $name)
|
private static function assertValidHook($instance, $name)
|
||||||
{
|
{
|
||||||
$base_class = self::$BASE_NS . ucfirst($name);
|
$base_class = self::$BASE_NS . ucfirst($name) . self::$classSuffix;
|
||||||
if (!$instance instanceof $base_class) {
|
if (!$instance instanceof $base_class) {
|
||||||
throw new ProgrammingError(
|
throw new ProgrammingError(
|
||||||
'%s is not an instance of %s',
|
'%s is not an instance of %s',
|
||||||
|
@ -10,15 +10,14 @@ use Zend_View;
|
|||||||
/**
|
/**
|
||||||
* Hook to extend topbar items
|
* Hook to extend topbar items
|
||||||
*/
|
*/
|
||||||
abstract class TopBarHook
|
abstract class TopBarHook extends WebBaseHook
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Function to generate top bar content
|
* Function to generate top bar content
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Zend_View $view
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
abstract public function getHtml($request, $view);
|
abstract public function getHtml($request);
|
||||||
}
|
}
|
||||||
|
51
library/Icinga/Web/Hook/WebBaseHook.php
Normal file
51
library/Icinga/Web/Hook/WebBaseHook.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Web\Hook;
|
||||||
|
|
||||||
|
use Zend_Controller_Action_HelperBroker;
|
||||||
|
use Zend_View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for web hooks
|
||||||
|
*
|
||||||
|
* The class provides access to the view
|
||||||
|
*/
|
||||||
|
class WebBaseHook
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View instance
|
||||||
|
*
|
||||||
|
* @var Zend_View
|
||||||
|
*/
|
||||||
|
private $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the view instance
|
||||||
|
*
|
||||||
|
* @param Zend_View $view
|
||||||
|
*/
|
||||||
|
public function setView(Zend_View $view)
|
||||||
|
{
|
||||||
|
$this->view = $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the view instance
|
||||||
|
*
|
||||||
|
* @return Zend_View
|
||||||
|
*/
|
||||||
|
public function getView()
|
||||||
|
{
|
||||||
|
if ($this->view === null) {
|
||||||
|
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
|
||||||
|
if ($viewRenderer->view === null) {
|
||||||
|
$viewRenderer->initView();
|
||||||
|
}
|
||||||
|
$this->view = $viewRenderer->view;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->view;
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,10 @@ class TopBar extends TopBarHook
|
|||||||
* Function to generate top bar content
|
* Function to generate top bar content
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Zend_View $view
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getHtml($request, $view)
|
public function getHtml($request)
|
||||||
{
|
{
|
||||||
$hostSummary = StatusSummaryView::fromRequest(
|
$hostSummary = StatusSummaryView::fromRequest(
|
||||||
$request,
|
$request,
|
||||||
@ -50,7 +49,7 @@ class TopBar extends TopBarHook
|
|||||||
)
|
)
|
||||||
)->getQuery()->fetchRow();
|
)->getQuery()->fetchRow();
|
||||||
|
|
||||||
return $view->partial(
|
return $this->getView()->partial(
|
||||||
'layout/topbar.phtml',
|
'layout/topbar.phtml',
|
||||||
'monitoring',
|
'monitoring',
|
||||||
array(
|
array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user