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;
|
2021-10-07 02:23:28 -04:00
|
|
|
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()
|
|
|
|
|
{
|
2020-04-24 08:36:37 -04:00
|
|
|
$this->setTitle(t('Comment'));
|
2019-11-04 09:51:28 -05:00
|
|
|
|
2021-08-31 06:34:18 -04:00
|
|
|
$name = $this->params->getRequired('name');
|
2019-11-04 09:51:28 -05:00
|
|
|
|
2020-01-15 09:08:11 -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]);
|
|
|
|
|
|
2021-01-28 06:38:03 -05:00
|
|
|
$this->applyRestrictions($query);
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-11-04 09:51:28 -05:00
|
|
|
$comment = $query->first();
|
|
|
|
|
if ($comment === null) {
|
2020-04-24 08:36:37 -04:00
|
|
|
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()
|
|
|
|
|
{
|
2021-04-29 09:36:47 -04:00
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 04:21:15 -04:00
|
|
|
protected function fetchCommandTargets(): array
|
2019-11-04 09:51:28 -05:00
|
|
|
{
|
|
|
|
|
return [$this->comment];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 02:23:28 -04:00
|
|
|
protected function getCommandTargetsUrl(): Url
|
2019-11-04 09:51:28 -05:00
|
|
|
{
|
|
|
|
|
return Links::comment($this->comment);
|
|
|
|
|
}
|
|
|
|
|
}
|