summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'controllers')
-rw-r--r--controllers/task.php85
1 files changed, 68 insertions, 17 deletions
diff --git a/controllers/task.php b/controllers/task.php
index a895d6b2..89e1ee6c 100644
--- a/controllers/task.php
+++ b/controllers/task.php
@@ -39,18 +39,34 @@ class Task extends Base
$this->response->text('FAILED');
}
- // Show a task
- public function show()
+ // Display the template show task, common between different task view
+ private function showTask(array $task, array $comment_form = array(), array $description_form = array())
{
- $task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
+ if (empty($comment_form)) {
+
+ $comment_form = array(
+ 'values' => array(
+ 'task_id' => $task['id'],
+ 'user_id' => $this->acl->getUserId()
+ ),
+ 'errors' => array()
+ );
+ }
- if (! $task) $this->notfound();
- $this->checkProjectPermissions($task['project_id']);
+ if (empty($description_form)) {
+
+ $description_form = array(
+ 'values' => array(
+ 'id' => $task['id'],
+ ),
+ 'errors' => array()
+ );
+ }
$this->response->html($this->template->layout('task_show', array(
+ 'comment_form' => $comment_form,
+ 'description_form' => $description_form,
'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(),
@@ -59,6 +75,17 @@ class Task extends Base
)));
}
+ // Show a task
+ public function show()
+ {
+ $task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
+
+ if (! $task) $this->notfound();
+ $this->checkProjectPermissions($task['project_id']);
+
+ $this->showTask($task);
+ }
+
// Add a comment
public function comment()
{
@@ -82,16 +109,40 @@ class Task extends Base
$this->response->redirect('?controller=task&action=show&task_id='.$task['id']);
}
- $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'],
- )));
+ $this->showTask(
+ $task,
+ array('values' => $values, 'errors' => $errors)
+ );
+ }
+
+ // Add a description from the show task page
+ public function description()
+ {
+ $task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
+ $values = $this->request->getValues();
+
+ if (! $task) $this->notfound();
+ $this->checkProjectPermissions($task['project_id']);
+
+ list($valid, $errors) = $this->task->validateDescriptionCreation($values);
+
+ if ($valid) {
+
+ if ($this->task->update($values)) {
+ $this->session->flash(t('Task updated successfully.'));
+ }
+ else {
+ $this->session->flashError(t('Unable to update your task.'));
+ }
+
+ $this->response->redirect('?controller=task&action=show&task_id='.$task['id']);
+ }
+
+ $this->showTask(
+ $task,
+ array(),
+ array('values' => $values, 'errors' => $errors)
+ );
}
// Display a form to create a new task