2015-04-30 18:18:09 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
use Icinga\Module\Monitoring\Controller;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display detailed information about a comment
|
|
|
|
*/
|
|
|
|
class Monitoring_CommentController extends Controller
|
|
|
|
{
|
2015-05-04 16:29:07 +02:00
|
|
|
/**
|
|
|
|
* The fetched comment
|
|
|
|
*
|
|
|
|
* @var stdClass
|
|
|
|
*/
|
2015-04-30 18:18:09 +02:00
|
|
|
protected $comment;
|
|
|
|
|
2015-05-04 16:29:07 +02:00
|
|
|
/**
|
|
|
|
* Fetch the first comment with the given id and add tabs
|
|
|
|
*/
|
2015-04-30 18:18:09 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2015-05-22 09:20:27 +02:00
|
|
|
$commentId = $this->params->getRequired('comment_id');
|
|
|
|
|
2015-06-15 15:58:15 +02:00
|
|
|
$query = $this->backend->select()->from('comment', array(
|
2015-05-04 16:29:07 +02:00
|
|
|
'id' => 'comment_internal_id',
|
2015-05-29 15:38:03 +02:00
|
|
|
'objecttype' => 'object_type',
|
2015-04-30 18:18:09 +02:00
|
|
|
'comment' => 'comment_data',
|
2015-05-04 16:29:07 +02:00
|
|
|
'author' => 'comment_author_name',
|
2015-04-30 18:18:09 +02:00
|
|
|
'timestamp' => 'comment_timestamp',
|
|
|
|
'type' => 'comment_type',
|
|
|
|
'persistent' => 'comment_is_persistent',
|
|
|
|
'expiration' => 'comment_expiration',
|
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'host_display_name',
|
|
|
|
'service_display_name'
|
2015-06-15 15:58:15 +02:00
|
|
|
))->where('comment_internal_id', $commentId);
|
|
|
|
$this->applyRestriction('monitoring/filter/objects', $query);
|
2015-05-22 09:20:27 +02:00
|
|
|
|
2015-06-15 15:58:15 +02:00
|
|
|
$this->comment = $query->getQuery()->fetchRow();
|
2015-05-22 09:20:27 +02:00
|
|
|
if ($this->comment === false) {
|
|
|
|
$this->httpNotFound($this->translate('Comment not found'));
|
2015-04-30 18:18:09 +02:00
|
|
|
}
|
2015-05-04 16:29:07 +02:00
|
|
|
|
|
|
|
$this->getTabs()->add(
|
|
|
|
'comment',
|
|
|
|
array(
|
|
|
|
'title' => $this->translate(
|
|
|
|
'Display detailed information about a comment.'
|
|
|
|
),
|
|
|
|
'icon' => 'comment',
|
|
|
|
'label' => $this->translate('Comment'),
|
|
|
|
'url' =>'monitoring/comments/show'
|
|
|
|
)
|
2015-04-30 18:18:09 +02:00
|
|
|
)->activate('comment')->extend(new DashboardAction());
|
|
|
|
}
|
2015-05-04 16:29:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display comment detail view
|
|
|
|
*/
|
2015-04-30 18:18:09 +02:00
|
|
|
public function showAction()
|
|
|
|
{
|
2015-05-07 17:02:34 +02:00
|
|
|
$listCommentsLink = Url::fromPath('monitoring/list/comments')
|
|
|
|
->setQueryString('comment_type=(comment|ack)');
|
|
|
|
|
2015-04-30 18:18:09 +02:00
|
|
|
$this->view->comment = $this->comment;
|
|
|
|
if ($this->hasPermission('monitoring/command/comment/delete')) {
|
|
|
|
$this->view->delCommentForm = $this->createDelCommentForm();
|
2015-05-07 14:03:09 +02:00
|
|
|
$this->view->delCommentForm->populate(
|
|
|
|
array(
|
2015-05-07 17:02:34 +02:00
|
|
|
'redirect' => $listCommentsLink,
|
2015-05-07 14:03:09 +02:00
|
|
|
'comment_id' => $this->comment->id,
|
|
|
|
'comment_is_service' => isset($this->comment->service_description)
|
|
|
|
)
|
|
|
|
);
|
2015-04-30 18:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 16:29:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a command form to delete a single comment
|
|
|
|
*
|
2015-05-07 14:03:09 +02:00
|
|
|
* @return DeleteCommentsCommandForm
|
2015-05-04 16:29:07 +02:00
|
|
|
*/
|
2015-04-30 18:18:09 +02:00
|
|
|
private function createDelCommentForm()
|
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/delete');
|
2015-05-22 09:20:27 +02:00
|
|
|
|
2015-04-30 18:18:09 +02:00
|
|
|
$delCommentForm = new DeleteCommentCommandForm();
|
|
|
|
$delCommentForm->setAction(
|
|
|
|
Url::fromPath('monitoring/comment/show')
|
|
|
|
->setParam('comment_id', $this->comment->id)
|
|
|
|
);
|
|
|
|
$delCommentForm->handleRequest();
|
|
|
|
return $delCommentForm;
|
|
|
|
}
|
|
|
|
}
|