From 2533ebc8d5794b66d6d6f1b9e2dc657cc59cfe95 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:04:24 +0200 Subject: [PATCH] monitoring: Fix mess in CommentsController and the related view script --- .../controllers/CommentsController.php | 36 ++++++++++--------- .../views/scripts/comments/show.phtml | 19 +++++----- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index 011ccf8df..c47f69b0b 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -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'); @@ -73,9 +75,9 @@ class CommentsController extends Controller { $this->view->comments = $this->comments; $this->view->listAllLink = Url::fromPath('monitoring/list/comments') - ->setQueryString($this->filter->toQueryString()); + ->setQueryString($this->filter->toQueryString()); $this->view->removeAllLink = Url::fromPath('monitoring/comments/delete-all') - ->setParams($this->params); + ->setParams($this->params); } /** @@ -91,14 +93,14 @@ 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; $this->view->comments = $this->comments; $this->view->listAllLink = Url::fromPath('monitoring/list/comments') - ->setQueryString($this->filter->toQueryString()); + ->setQueryString($this->filter->toQueryString()); } } diff --git a/modules/monitoring/application/views/scripts/comments/show.phtml b/modules/monitoring/application/views/scripts/comments/show.phtml index 4f9c64d47..0ae91f5bf 100644 --- a/modules/monitoring/application/views/scripts/comments/show.phtml +++ b/modules/monitoring/application/views/scripts/comments/show.phtml @@ -1,24 +1,23 @@
- compact): ?> - tabs; ?> - - -
- render('partials/comment/comments-header.phtml'); ?> -
+compact): ?> + tabs ?> + +
+ render('partials/comment/comments-header.phtml') ?> +
-

icon('reschedule') ?> translate('Commands') ?>

+

icon('reschedule') ?>translate('Commands') ?>

qlink( sprintf( $this->translate('Remove %d comments'), - count($comments) + $comments->count() ), $removeAllLink, null, array( - 'icon' => 'trash', + 'icon' => 'trash', 'title' => $this->translate('Remove all selected comments.') ) ) ?>