summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/library/Monitoring/Hook/ObjectActionsHook.php
blob: eb2d9107d6e00fa39c5f531dfd0c98649d3adc3c (plain)
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
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Monitoring\Hook;

use Icinga\Web\Navigation\Navigation;
use Icinga\Module\Monitoring\Object\MonitoredObject;

/**
 * Base class for object action hooks
 */
abstract class ObjectActionsHook
{
    /**
     * Return the action navigation for the given object
     *
     * @return  Navigation
     */
    public function getNavigation(MonitoredObject $object)
    {
        $urls = $this->getActionsForObject($object);
        if (is_array($urls)) {
            $navigation = new Navigation();
            foreach ($urls as $label => $url) {
                $navigation->addItem($label, array('url' => $url));
            }
        } else {
            $navigation = $urls;
        }

        return $navigation;
    }

    /**
     * Create and return a new Navigation object
     *
     * @param   array   $actions    Optional array of actions to add to the returned object
     *
     * @return  Navigation
     */
    protected function createNavigation(array $actions = null)
    {
        return empty($actions) ? new Navigation() : Navigation::fromArray($actions);
    }

    abstract public function getActionsForObject(MonitoredObject $object);
}