summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/BoardTooltipController.php16
-rw-r--r--app/Controller/CommentController.php21
-rw-r--r--app/Controller/CommentListController.php50
3 files changed, 59 insertions, 28 deletions
diff --git a/app/Controller/BoardTooltipController.php b/app/Controller/BoardTooltipController.php
index 79b9b509..7bee8dab 100644
--- a/app/Controller/BoardTooltipController.php
+++ b/app/Controller/BoardTooltipController.php
@@ -70,22 +70,6 @@ class BoardTooltipController extends BaseController
}
/**
- * Display comments during a task mouseover
- *
- * @access public
- */
- public function comments()
- {
- $task = $this->getTask();
- $commentSortingDirection = $this->userMetadataCacheDecorator->get(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, 'ASC');
-
- $this->response->html($this->template->render('board/tooltip_comments', array(
- 'task' => $task,
- 'comments' => $this->commentModel->getAll($task['id'], $commentSortingDirection)
- )));
- }
-
- /**
* Display task description
*
* @access public
diff --git a/app/Controller/CommentController.php b/app/Controller/CommentController.php
index 526bd2bf..9a89103e 100644
--- a/app/Controller/CommentController.php
+++ b/app/Controller/CommentController.php
@@ -4,7 +4,6 @@ namespace Kanboard\Controller;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Core\Controller\PageNotFoundException;
-use Kanboard\Model\UserMetadataModel;
/**
* Comment Controller
@@ -17,12 +16,12 @@ class CommentController extends BaseController
/**
* Get the current comment
*
- * @access private
+ * @access protected
* @return array
* @throws PageNotFoundException
* @throws AccessForbiddenException
*/
- private function getComment()
+ protected function getComment()
{
$comment = $this->commentModel->getById($this->request->getIntegerParam('comment_id'));
@@ -77,6 +76,8 @@ class CommentController extends BaseController
{
$task = $this->getTask();
$values = $this->request->getValues();
+ $values['task_id'] = $task['id'];
+ $values['user_id'] = $this->userSession->getId();
list($valid, $errors) = $this->commentValidator->validateCreation($values);
@@ -118,7 +119,6 @@ class CommentController extends BaseController
'errors' => $errors,
'comment' => $comment,
'task' => $task,
- 'title' => t('Edit a comment')
)));
}
@@ -142,10 +142,11 @@ class CommentController extends BaseController
$this->flash->failure(t('Unable to update your comment.'));
}
- return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), false);
+ $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true);
+ return;
}
- return $this->edit($values, $errors);
+ $this->edit($values, $errors);
}
/**
@@ -182,7 +183,7 @@ class CommentController extends BaseController
$this->flash->failure(t('Unable to remove this comment.'));
}
- $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'));
+ $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true);
}
/**
@@ -193,11 +194,7 @@ class CommentController extends BaseController
public function toggleSorting()
{
$task = $this->getTask();
-
- $oldDirection = $this->userMetadataCacheDecorator->get(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, 'ASC');
- $newDirection = $oldDirection === 'ASC' ? 'DESC' : 'ASC';
-
- $this->userMetadataCacheDecorator->set(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, $newDirection);
+ $this->helper->comment->toggleSorting();
$this->response->redirect($this->helper->url->to(
'TaskViewController',
diff --git a/app/Controller/CommentListController.php b/app/Controller/CommentListController.php
new file mode 100644
index 00000000..63d20663
--- /dev/null
+++ b/app/Controller/CommentListController.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Kanboard\Controller;
+
+use Kanboard\Model\UserMetadataModel;
+
+/**
+ * Class CommentListController
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class CommentListController extends BaseController
+{
+ public function show()
+ {
+ $project = $this->getProject();
+ $task = $this->getTask();
+ $commentSortingDirection = $this->userMetadataCacheDecorator->get(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, 'ASC');
+
+ $this->response->html($this->template->render('comment_list/show', array(
+ 'project' => $project,
+ 'task' => $task,
+ 'comments' => $this->commentModel->getAll($task['id'], $commentSortingDirection),
+ 'editable' => $this->helper->user->hasProjectAccess('CommentController', 'edit', $task['project_id']),
+ )));
+ }
+
+ public function save()
+ {
+ $task = $this->getTask();
+ $values = $this->request->getValues();
+ $values['task_id'] = $task['id'];
+ $values['user_id'] = $this->userSession->getId();
+
+ list($valid, ) = $this->commentValidator->validateCreation($values);
+
+ if ($valid && $this->commentModel->create($values) !== false) {
+ $this->flash->success(t('Comment added successfully.'));
+ }
+
+ $this->show();
+ }
+
+ public function toggleSorting()
+ {
+ $this->helper->comment->toggleSorting();
+ $this->show();
+ }
+}