diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
commit | 19409360ca7d4c00d070b16bbfcc6cd02543cdca (patch) | |
tree | 3eb3a3d0fce2d74c550135f3119182e1d1aa0fe2 /controllers/task.php | |
parent | ccc54c65cf2191e35bd0294c0ffbae761b29f151 (diff) |
Improve comments
Diffstat (limited to 'controllers/task.php')
-rw-r--r-- | controllers/task.php | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/controllers/task.php b/controllers/task.php index 75d08958..a895d6b2 100644 --- a/controllers/task.php +++ b/controllers/task.php @@ -45,43 +45,53 @@ class Task extends Base $task = $this->task->getById($this->request->getIntegerParam('task_id'), true); if (! $task) $this->notfound(); - $this->checkProjectPermissions($task['project_id']); - $values = $values = $this->request->getValues(); - $errors = $this->comment($values, $task['id']); - $comments = $this->task->getCommentsByTask($task['id']); - $this->response->html($this->template->layout('task_show', array( + 'comments' => $this->comment->getAll($task['id']), + 'comment_errors' => array(), + 'comment_values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title'], - 'comments' => $comments, - 'errors' => $errors, - 'values' => $values ))); } - //add a comment - public function comment(array $values, $task_id) + // Add a comment + public function comment() { - $errors = array(); + $task = $this->task->getById($this->request->getIntegerParam('task_id'), true); + $values = $this->request->getValues(); - if ($_POST) { - list($valid, $errors) = $this->task->validateComment($values); + if (! $task) $this->notfound(); + $this->checkProjectPermissions($task['project_id']); + + list($valid, $errors) = $this->comment->validateCreation($values); + + if ($valid) { - if ($valid) { - $this->task->addComment(array( - 'task_id' => $task_id, - 'comment' => $values['comment'], - 'user_id' => $this->acl->getUserId() - )); + if ($this->comment->create($values)) { + $this->session->flash(t('Comment added successfully.')); } + else { + $this->session->flashError(t('Unable to create your comment.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); } - return $errors; + $this->response->html($this->template->layout('task_show', array( + 'comments' => $this->comment->getAll($task['id']), + 'comment_errors' => $errors, + 'comment_values' => $values, + 'task' => $task, + 'columns_list' => $this->board->getColumnsList($task['project_id']), + 'colors_list' => $this->task->getColors(), + 'menu' => 'tasks', + 'title' => $task['title'], + ))); } // Display a form to create a new task |