icingadb-web/application/controllers/CommentController.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2019-11-04 09:51:28 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-11-04 09:51:28 -05:00
use Icinga\Exception\NotFoundError;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Common\CommandActions;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\Comment;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\CommentDetail;
2019-12-16 08:20:11 -05:00
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
use ipl\Web\Url;
2019-11-04 09:51:28 -05:00
class CommentController extends Controller
{
use CommandActions;
/** @var Comment The comment object */
protected $comment;
public function init()
{
$this->setTitle(t('Comment'));
2019-11-04 09:51:28 -05:00
$name = $this->params->getRequired('name');
2019-11-04 09:51:28 -05:00
$query = Comment::on($this->getDb())->with([
'host',
'host.state',
'service',
'service.state',
'service.host',
'service.host.state'
]);
2019-11-04 09:51:28 -05:00
$query->getSelectBase()
->where(['comment.name = ?' => $name]);
$this->applyRestrictions($query);
2019-11-04 09:51:28 -05:00
$comment = $query->first();
if ($comment === null) {
throw new NotFoundError(t('Comment not found'));
2019-11-04 09:51:28 -05:00
}
$this->comment = $comment;
}
2019-12-16 08:20:11 -05:00
public function indexAction()
{
$this->addControl((new CommentList([$this->comment]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setCaptionDisabled()
->setNoSubjectLink());
2019-12-16 08:20:11 -05:00
$this->addContent(new CommentDetail($this->comment));
$this->setAutorefreshInterval(10);
}
protected function fetchCommandTargets(): array
2019-11-04 09:51:28 -05:00
{
return [$this->comment];
}
protected function getCommandTargetsUrl(): Url
2019-11-04 09:51:28 -05:00
{
return Links::comment($this->comment);
}
}