summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/application/controllers/CommentController.php
blob: e50473fb642dffb1f95ef51fb6697734fce9bb95 (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
86
87
88
89
90
91
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Monitoring\Controllers;

use Icinga\Application\Hook;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;

/**
 * Display detailed information about a comment
 */
class CommentController extends Controller
{
    /**
     * The fetched comment
     *
     * @var object
     */
    protected $comment;

    /**
     * Fetch the first comment with the given id and add tabs
     */
    public function init()
    {
        $commentId = $this->params->getRequired('comment_id');

        $query = $this->backend->select()->from('comment', array(
            'id'         => 'comment_internal_id',
            'objecttype' => 'object_type',
            'comment'    => 'comment_data',
            'author'     => 'comment_author_name',
            'timestamp'  => 'comment_timestamp',
            'type'       => 'comment_type',
            'persistent' => 'comment_is_persistent',
            'expiration' => 'comment_expiration',
            'name'       => 'comment_name',
            'host_name',
            'service_description',
            'host_display_name',
            'service_display_name'
        ))->where('comment_internal_id', $commentId);
        $this->applyRestriction('monitoring/filter/objects', $query);

        if (false === $this->comment = $query->fetchRow()) {
            $this->httpNotFound($this->translate('Comment not found'));
        }

        $this->getTabs()->add(
            'comment',
            array(
                'icon'  => 'comment-empty',
                'label' => $this->translate('Comment'),
                'title' => $this->translate('Display detailed information about a comment.'),
                'url'   =>'monitoring/comments/show'
            )
        )->activate('comment')->extend(new DashboardAction())->extend(new MenuAction());

        if (Hook::has('ticket')) {
            $this->view->tickets = Hook::first('ticket');
        }
    }

    /**
     * Display comment detail view
     */
    public function showAction()
    {
        $this->view->comment = $this->comment;
        $this->view->title = $this->translate('Comments');

        if ($this->hasPermission('monitoring/command/comment/delete')) {
            $listUrl = Url::fromPath('monitoring/list/comments')
                ->setQueryString('comment_type=comment|comment_type=ack');
            $form = new DeleteCommentCommandForm();
            $form
                ->populate(array(
                    'comment_id'            => $this->comment->id,
                    'comment_is_service'    => isset($this->comment->service_description),
                    'comment_name'          => $this->comment->name,
                    'redirect'              => $listUrl
                ))
                ->handleRequest();
            $this->view->delCommentForm = $form;
        }
    }
}