Add comments sorting
This commit is contained in:
@@ -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())
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user