summaryrefslogtreecommitdiffstats
path: root/application/controllers/NotificationController.php
blob: 97fa0f4d060e21297d0c2bfb83da00eaf2dd19da (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
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
<?php

namespace Icinga\Module\Director\Controllers;

use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaNotification;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;

class NotificationController extends ObjectController
{
    protected function checkDirectorPermissions()
    {
        $this->assertPermission('director/notifications');
    }

    // TODO: KILL IT
    public function init()
    {
        parent::init();
        // TODO: Check if this is still needed, remove it otherwise
        /** @var \Icinga\Web\Widget\Tab $tab */
        if ($this->object && $this->object->object_type === 'apply') {
            if ($host = $this->params->get('host')) {
                foreach ($this->getTabs()->getTabs() as $tab) {
                    $tab->getUrl()->setParam('host', $host);
                }
            }

            if ($service = $this->params->get('service')) {
                foreach ($this->getTabs()->getTabs() as $tab) {
                    $tab->getUrl()->setParam('service', $service);
                }
            }
        }
    }

    /**
     * @param DirectorObjectForm $form
     */
    protected function onObjectFormLoaded(DirectorObjectForm $form)
    {
        if (! $this->object) {
            return;
        }

        if ($this->object->isTemplate()) {
            $form->setListUrl('director/notifications/templates');
        } else {
            $form->setListUrl('director/notifications/applyrules');
        }
    }

    protected function hasBasketSupport()
    {
        return $this->object->isTemplate() || $this->object->isApplyRule();
    }

    protected function loadObject()
    {
        if ($this->object === null) {
            if ($name = $this->params->get('name')) {
                $params = array('object_name' => $name);
                $db = $this->db();

                if ($hostname = $this->params->get('host')) {
                    $this->view->host = IcingaHost::load($hostname, $db);
                    $params['host_id'] = $this->view->host->id;
                }

                if ($service = $this->params->get('service')) {
                    $this->view->service = IcingaService::load($service, $db);
                    $params['service_id'] = $this->view->service->id;
                }

                $this->object = IcingaNotification::load($params, $db);
            } else {
                parent::loadObject();
            }
        }

        return $this->object;
    }
}