monitoring: Fix mess in CommentsController and the related view script

This commit is contained in:
Eric Lippmann 2015-08-27 16:04:24 +02:00
parent 78701ab2b6
commit 2533ebc8d5
2 changed files with 28 additions and 27 deletions

View File

@ -9,28 +9,33 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm;
use Icinga\Web\Url;
/**
* Display detailed information about a comment
* Display detailed information about comments
*/
class CommentsController extends Controller
{
/**
* The fetched comments
* The comments view
*
* @var array
* @var \Icinga\Module\Monitoring\DataView\Comment
*/
protected $comments;
/**
* Fetch all comments matching the current filter and add tabs
* Filter from request
*
* @throws Zend_Controller_Action_Exception
* @var Filter
*/
protected $filter;
/**
* Fetch all comments matching the current filter and add tabs
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace(
'comment_id',
'comment_internal_id',
(string)$this->params
(string) $this->params
));
$query = $this->backend->select()->from('comment', array(
'id' => 'comment_internal_id',
@ -48,19 +53,16 @@ class CommentsController extends Controller
))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query);
$this->comments = $query->getQuery()->fetchAll();
if (false === $this->comments) {
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
}
$this->comments = $query;
$this->getTabs()->add(
'comments',
array(
'icon' => 'comment',
'label' => $this->translate('Comments') . sprintf(' (%d)', $query->count()),
'title' => $this->translate(
'Display detailed information about multiple comments.'
),
'icon' => 'comment',
'label' => $this->translate('Comments') . sprintf(' (%d)', count($this->comments)),
'url' =>'monitoring/comments/show'
)
)->activate('comments');
@ -91,9 +93,9 @@ class CommentsController extends Controller
$delCommentForm->setTitle($this->view->translate('Remove all Comments'));
$delCommentForm->addDescription(sprintf(
$this->translate('Confirm removal of %d comments.'),
count($this->comments)
$this->comments->count()
));
$delCommentForm->setComments($this->comments)
$delCommentForm->setComments($this->comments->fetchAll())
->setRedirectUrl($listCommentsLink)
->handleRequest();
$this->view->delCommentForm = $delCommentForm;

View File

@ -1,19 +1,18 @@
<div class="controls">
<?php if (! $this->compact): ?>
<?= $this->tabs; ?>
<?php endif ?>
<?php if (! $this->compact): ?>
<?= $this->tabs ?>
<?php endif ?>
<div data-base-target='_next'>
<?= $this->render('partials/comment/comments-header.phtml'); ?>
<?= $this->render('partials/comment/comments-header.phtml') ?>
</div>
</div>
<div class="content multi-commands">
<h3><?= $this->icon('reschedule') ?> <?= $this->translate('Commands') ?> </h3>
<h3><?= $this->icon('reschedule') ?><?= $this->translate('Commands') ?></h3>
<?= $this->qlink(
sprintf(
$this->translate('Remove %d comments'),
count($comments)
$comments->count()
),
$removeAllLink,
null,