From ffe615d2018bdfb789667715bbde062dd696d320 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 11 Oct 2015 18:21:54 -0400 Subject: Add comments sorting --- app/Controller/Board.php | 2 +- app/Controller/Comment.php | 15 +++++++++++++++ app/Controller/Task.php | 2 +- app/Model/Comment.php | 5 +++-- app/Model/UserSession.php | 22 ++++++++++++++++++++++ app/Template/task/comments.php | 22 ++++++++++++++-------- 6 files changed, 56 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 840db05b..a2cde287 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -195,7 +195,7 @@ class Board extends Base $task = $this->getTask(); $this->response->html($this->template->render('board/tooltip_comments', array( - 'comments' => $this->comment->getAll($task['id']) + 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()) ))); } diff --git a/app/Controller/Comment.php b/app/Controller/Comment.php index 81fd7215..cf0af615 100644 --- a/app/Controller/Comment.php +++ b/app/Controller/Comment.php @@ -183,4 +183,19 @@ class Comment extends Base $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); } + + /** + * Toggle comment sorting + * + * @access public + */ + public function toggleSorting() + { + $task = $this->getTask(); + + $order = $this->userSession->getCommentSorting() === 'ASC' ? 'DESC' : 'ASC'; + $this->userSession->setCommentSorting($order); + + $this->response->redirect($this->helper->url->href('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'comments')); + } } diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 0770fcd1..8e577839 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -68,7 +68,7 @@ class Task extends Base 'project' => $this->project->getById($task['project_id']), 'files' => $this->file->getAllDocuments($task['id']), 'images' => $this->file->getAllImages($task['id']), - 'comments' => $this->comment->getAll($task['id']), + 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()), 'subtasks' => $subtasks, 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), 'task' => $task, diff --git a/app/Model/Comment.php b/app/Model/Comment.php index e3ffc1be..c1c800c3 100644 --- a/app/Model/Comment.php +++ b/app/Model/Comment.php @@ -34,9 +34,10 @@ class Comment extends Base * * @access public * @param integer $task_id Task id + * @param string $sorting ASC/DESC * @return array */ - public function getAll($task_id) + public function getAll($task_id, $sorting = 'ASC') { return $this->db ->table(self::TABLE) @@ -51,7 +52,7 @@ class Comment extends Base User::TABLE.'.email' ) ->join(User::TABLE, 'id', 'user_id') - ->orderBy(self::TABLE.'.date_creation', 'ASC') + ->orderBy(self::TABLE.'.date_creation', $sorting) ->eq(self::TABLE.'.task_id', $task_id) ->findAll(); } diff --git a/app/Model/UserSession.php b/app/Model/UserSession.php index 1ae3fdf4..4c0364ce 100644 --- a/app/Model/UserSession.php +++ b/app/Model/UserSession.php @@ -154,4 +154,26 @@ class UserSession extends Base { $_SESSION['board_collapsed'][$project_id] = $collapsed; } + + /** + * Set comments sorting + * + * @access public + * @param string $order + */ + public function setCommentSorting($order) + { + $this->session['comment_sorting'] = $order; + } + + /** + * Get comments sorting direction + * + * @access public + * @return string + */ + public function getCommentSorting() + { + return $this->session['comment_sorting'] ?: 'ASC'; + } } diff --git a/app/Template/task/comments.php b/app/Template/task/comments.php index a09862f9..070de320 100644 --- a/app/Template/task/comments.php +++ b/app/Template/task/comments.php @@ -1,7 +1,13 @@
@@ -16,13 +22,13 @@ render('comment/create', array( - 'skip_cancel' => true, - 'values' => array( - 'user_id' => $this->user->getId(), - 'task_id' => $task['id'], - ), - 'errors' => array(), - 'task' => $task + 'skip_cancel' => true, + 'values' => array( + 'user_id' => $this->user->getId(), + 'task_id' => $task['id'], + ), + 'errors' => array(), + 'task' => $task )) ?>
-- cgit v1.2.3