2015-05-04 14:59:39 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2015-05-07 14:03:09 +02:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm;
|
2015-05-04 14:59:39 +02:00
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display detailed information about a comment
|
|
|
|
*/
|
|
|
|
class Monitoring_CommentsController extends Controller
|
|
|
|
{
|
2015-05-04 16:29:07 +02:00
|
|
|
/**
|
|
|
|
* The fetched comments
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-05-04 14:59:39 +02:00
|
|
|
protected $comments;
|
|
|
|
|
2015-05-04 16:29:07 +02:00
|
|
|
/**
|
|
|
|
* Fetch all comments matching the current filter and add tabs
|
|
|
|
*
|
|
|
|
* @throws Zend_Controller_Action_Exception
|
|
|
|
*/
|
2015-05-04 14:59:39 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->filter = Filter::fromQueryString(str_replace(
|
2015-05-04 16:29:07 +02:00
|
|
|
'comment_id',
|
|
|
|
'comment_internal_id',
|
|
|
|
(string)$this->params
|
2015-05-04 14:59:39 +02:00
|
|
|
));
|
|
|
|
$this->comments = $this->backend->select()->from('comment', array(
|
|
|
|
'id' => 'comment_internal_id',
|
|
|
|
'objecttype' => 'comment_objecttype',
|
|
|
|
'comment' => 'comment_data',
|
|
|
|
'author' => 'comment_author_name',
|
|
|
|
'timestamp' => 'comment_timestamp',
|
|
|
|
'type' => 'comment_type',
|
|
|
|
'persistent' => 'comment_is_persistent',
|
|
|
|
'expiration' => 'comment_expiration',
|
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'host_display_name',
|
|
|
|
'service_display_name'
|
|
|
|
))->addFilter($this->filter)->getQuery()->fetchAll();
|
|
|
|
|
|
|
|
if (false === $this->comments) {
|
|
|
|
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
|
|
|
|
}
|
|
|
|
|
2015-05-04 16:29:07 +02:00
|
|
|
$this->getTabs()->add(
|
|
|
|
'comments',
|
|
|
|
array(
|
|
|
|
'title' => $this->translate(
|
|
|
|
'Display detailed information about multiple comments.'
|
|
|
|
),
|
2015-05-18 17:13:46 +02:00
|
|
|
'icon' => 'comment',
|
|
|
|
'label' => $this->translate('Comments') . sprintf(' (%d)', count($this->comments)),
|
2015-05-04 16:29:07 +02:00
|
|
|
'url' =>'monitoring/comments/show'
|
|
|
|
)
|
2015-05-04 17:05:18 +02:00
|
|
|
)->activate('comments');
|
2015-05-04 14:59:39 +02:00
|
|
|
}
|
2015-05-04 16:29:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the detail view for a comment list
|
|
|
|
*/
|
2015-05-04 14:59:39 +02:00
|
|
|
public function showAction()
|
|
|
|
{
|
|
|
|
$this->view->comments = $this->comments;
|
|
|
|
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
|
|
|
->setQueryString($this->filter->toQueryString());
|
2015-05-07 17:29:46 +02:00
|
|
|
$this->view->removeAllLink = Url::fromPath('monitoring/comments/delete-all')
|
2015-05-04 14:59:39 +02:00
|
|
|
->setParams($this->params);
|
|
|
|
}
|
|
|
|
|
2015-05-04 16:29:07 +02:00
|
|
|
/**
|
|
|
|
* Display the form for removing a comment list
|
|
|
|
*/
|
2015-05-07 17:29:46 +02:00
|
|
|
public function deleteAllAction()
|
2015-05-04 14:59:39 +02:00
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/delete');
|
2015-05-07 16:37:35 +02:00
|
|
|
|
2015-05-07 17:02:34 +02:00
|
|
|
$listCommentsLink = Url::fromPath('monitoring/list/comments')
|
|
|
|
->setQueryString('comment_type=(comment|ack)');
|
2015-05-07 14:03:09 +02:00
|
|
|
$delCommentForm = new DeleteCommentsCommandForm();
|
2015-05-04 14:59:39 +02:00
|
|
|
$delCommentForm->setTitle($this->view->translate('Remove all Comments'));
|
|
|
|
$delCommentForm->addDescription(sprintf(
|
|
|
|
$this->translate('Confirm removal of %d comments.'),
|
|
|
|
count($this->comments)
|
|
|
|
));
|
2015-05-07 15:11:54 +02:00
|
|
|
$delCommentForm->setComments($this->comments)
|
2015-05-07 17:02:34 +02:00
|
|
|
->setRedirectUrl($listCommentsLink)
|
|
|
|
->handleRequest();
|
2015-05-04 14:59:39 +02:00
|
|
|
$this->view->delCommentForm = $delCommentForm;
|
2015-05-07 17:02:34 +02:00
|
|
|
$this->view->comments = $this->comments;
|
|
|
|
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
|
|
|
->setQueryString($this->filter->toQueryString());
|
2015-05-04 14:59:39 +02:00
|
|
|
}
|
|
|
|
}
|