1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
<?php
/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Eventdb\Hook;
use Icinga\Application\ClassLoader;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Module\Eventdb\Event;
use Icinga\Web\View;
/**
* Base class for hooks extending the detail view of events
*
* Extend this class if you want to extend the detail view of events with custom HTML.
*/
abstract class DetailviewExtensionHook
{
/**
* The view the generated HTML will be included in
*
* @var View
*/
private $view;
/**
* The module of the derived class
*
* @var Module
*/
private $module;
/**
* Create a new hook
*
* @see init() For hook initialization.
*/
final public function __construct()
{
$this->init();
}
/**
* Overwrite this function for hook initialization, e.g. loading the hook's config
*/
protected function init()
{
}
/**
* Shall return valid HTML to include in the detail view
*
* @param Event $event The event to generate HTML for
*
* @return string
*/
abstract public function getHtmlForEvent(Event $event);
/**
* Shall return valid HTML to include in the multi-select view for events
*
* @param Event[] $events The events to generate HTML for
*
* @return string
*/
public function getHtmlForEvents($events)
{
return '';
}
/**
* Get {@link view}
*
* @return View
*/
public function getView()
{
return $this->view;
}
/**
* Set {@link view}
*
* @param View $view
*
* @return $this
*/
public function setView($view)
{
$this->view = $view;
return $this;
}
/**
* Get the module of the derived class
*
* @return Module
*/
public function getModule()
{
if ($this->module === null) {
$class = get_class($this);
if (ClassLoader::classBelongsToModule($class)) {
$this->module = Icinga::app()->getModuleManager()->getModule(ClassLoader::extractModuleName($class));
}
}
return $this->module;
}
/**
* Set the module of the derived class
*
* @param Module $module
*
* @return $this
*/
public function setModule(Module $module)
{
$this->module = $module;
return $this;
}
}
|