From 6ff7882fc03f9e23b559dac209941b0d54cb84bb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:52:27 +0200 Subject: [PATCH] monitoring: Reduce complexity of the CommentController --- .../controllers/CommentController.php | 49 ++++++------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 3328ffb79..1b86ff1c9 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -16,7 +16,7 @@ class CommentController extends Controller /** * The fetched comment * - * @var stdClass + * @var object */ protected $comment; @@ -43,19 +43,18 @@ class CommentController extends Controller ))->where('comment_internal_id', $commentId); $this->applyRestriction('monitoring/filter/objects', $query); - $this->comment = $query->getQuery()->fetchRow(); - if ($this->comment === false) { + if (false === $this->comment = $query->getQuery()->fetchRow()) { $this->httpNotFound($this->translate('Comment not found')); } $this->getTabs()->add( 'comment', array( + 'icon' => 'comment', + 'label' => $this->translate('Comment'), 'title' => $this->translate( 'Display detailed information about a comment.' ), - 'icon' => 'comment', - 'label' => $this->translate('Comment'), 'url' =>'monitoring/comments/show' ) )->activate('comment')->extend(new DashboardAction()); @@ -66,37 +65,19 @@ class CommentController extends Controller */ public function showAction() { - $listCommentsLink = Url::fromPath('monitoring/list/comments') - ->setQueryString('comment_type=(comment|ack)'); - $this->view->comment = $this->comment; + if ($this->hasPermission('monitoring/command/comment/delete')) { - $this->view->delCommentForm = $this->createDelCommentForm(); - $this->view->delCommentForm->populate( - array( - 'redirect' => $listCommentsLink, - 'comment_id' => $this->comment->id, - 'comment_is_service' => isset($this->comment->service_description) - ) - ); + $listUrl = Url::fromPath('monitoring/list/comments')->setQueryString('comment_type=(comment|ack)'); + $form = new DeleteCommentCommandForm(); + $form + ->populate(array( + 'redirect' => $listUrl, + 'comment_id' => $this->comment->id, + 'comment_is_service' => isset($this->comment->service_description) + )) + ->handleRequest(); + $this->view->delCommentForm = $form; } } - - /** - * Create a command form to delete a single comment - * - * @return DeleteCommentsCommandForm - */ - private function createDelCommentForm() - { - $this->assertPermission('monitoring/command/comment/delete'); - - $delCommentForm = new DeleteCommentCommandForm(); - $delCommentForm->setAction( - Url::fromPath('monitoring/comment/show') - ->setParam('comment_id', $this->comment->id) - ); - $delCommentForm->handleRequest(); - return $delCommentForm; - } }