File: CommentController.php

package info (click to toggle)
icingadb-web 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,260 kB
  • sloc: php: 33,601; javascript: 640; sh: 17; xml: 16; makefile: 4
file content (53 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download
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
<?php

/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Controllers;

use Icinga\Exception\NotFoundError;
use Icinga\Module\Icingadb\Model\Comment;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\CommentDetail;
use Icinga\Module\Icingadb\Widget\Detail\ObjectHeader;
use ipl\Stdlib\Filter;

class CommentController extends Controller
{
    /** @var Comment The comment object */
    protected $comment;

    public function init()
    {
        $this->addTitleTab(t('Comment'));

        $name = $this->params->getRequired('name');

        $query = Comment::on($this->getDb())->with([
            'host',
            'host.state',
            'service',
            'service.state',
            'service.host',
            'service.host.state'
        ]);
        $query->filter(Filter::equal('comment.name', $name));

        $this->applyRestrictions($query);

        $comment = $query->first();
        if ($comment === null) {
            throw new NotFoundError(t('Comment not found'));
        }

        $this->comment = $comment;
    }

    public function indexAction()
    {
        $this->addControl(new ObjectHeader($this->comment));

        $this->addContent(new CommentDetail($this->comment));

        $this->setAutorefreshInterval(10);
    }
}