summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Board.php2
-rw-r--r--app/Controller/Comment.php15
-rw-r--r--app/Controller/Task.php2
-rw-r--r--app/Model/Comment.php5
-rw-r--r--app/Model/UserSession.php22
-rw-r--r--app/Template/task/comments.php22
6 files changed, 56 insertions, 12 deletions
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 @@
<?php if (! empty($comments)): ?>
<div id="comments" class="task-show-section">
<div class="page-header">
- <h2><?= t('Comments') ?></h2>
+ <h2>
+ <?= t('Comments') ?>
+ <span class="comment-sorting">
+ <i class="fa fa-sort"></i>
+ <?= $this->url->link(t('change sorting'), 'comment', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
+ </span>
+ </h2>
</div>
<?php foreach ($comments as $comment): ?>
@@ -16,13 +22,13 @@
<?php if (! isset($not_editable)): ?>
<?= $this->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
)) ?>
<?php endif ?>
</div>