diff options
Diffstat (limited to 'app/Controller/Task.php')
-rw-r--r-- | app/Controller/Task.php | 336 |
1 files changed, 228 insertions, 108 deletions
diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 1b20cf15..dc83f7b1 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -22,20 +22,21 @@ class Task extends Base $project = $this->project->getByToken($this->request->getStringParam('token')); // Token verification - if (! $project) { + if (empty($project)) { $this->forbidden(true); } $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id')); - if (! $task) { + if (empty($task)) { $this->notfound(true); } - $this->response->html($this->template->layout('task_public', array( + $this->response->html($this->template->layout('task/public', array( 'project' => $project, 'comments' => $this->comment->getAll($task['id']), - 'subtasks' => $this->subTask->getAll($task['id']), + 'subtasks' => $this->subtask->getAll($task['id']), + 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->color->getList(), @@ -54,7 +55,7 @@ class Task extends Base public function show() { $task = $this->getTask(); - $subtasks = $this->subTask->getAll($task['id']); + $subtasks = $this->subtask->getAll($task['id']); $values = array( 'id' => $task['id'], @@ -65,20 +66,41 @@ class Task extends Base $this->dateParser->format($values, array('date_started')); - $this->response->html($this->taskLayout('task_show', array( + $this->response->html($this->taskLayout('task/show', array( 'project' => $this->project->getById($task['project_id']), - 'files' => $this->file->getAll($task['id']), + 'files' => $this->file->getAllDocuments($task['id']), + 'images' => $this->file->getAllImages($task['id']), 'comments' => $this->comment->getAll($task['id']), 'subtasks' => $subtasks, + 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), 'task' => $task, 'values' => $values, - 'timesheet' => $this->timeTracking->getTaskTimesheet($task, $subtasks), + 'link_label_list' => $this->link->getList(0, false), 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->color->getList(), 'date_format' => $this->config->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats(), - 'menu' => 'tasks', + 'title' => $task['project_name'].' > '.$task['title'], + 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + ))); + } + + /** + * Display task activities + * + * @access public + */ + public function activites() + { + $task = $this->getTask(); + + $this->response->html($this->taskLayout('task/activity', array( 'title' => $task['title'], + 'task' => $task, + 'ajax' => $this->request->isAjax(), + 'events' => $this->projectActivity->getTask($task['id']), ))); } @@ -87,29 +109,36 @@ class Task extends Base * * @access public */ - public function create() + public function create(array $values = array(), array $errors = array()) { - $project_id = $this->request->getIntegerParam('project_id'); - $this->checkProjectPermissions($project_id); + $project = $this->getProject(); + $method = $this->request->isAjax() ? 'render' : 'layout'; + $swimlanes_list = $this->swimlane->getList($project['id'], false, true); - $this->response->html($this->template->layout('task_new', array( - 'errors' => array(), - 'values' => array( - 'project_id' => $project_id, + if (empty($values)) { + + $values = array( + 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanes_list)), 'column_id' => $this->request->getIntegerParam('column_id'), 'color_id' => $this->request->getStringParam('color_id'), 'owner_id' => $this->request->getIntegerParam('owner_id'), 'another_task' => $this->request->getIntegerParam('another_task'), - ), + ); + } + + $this->response->html($this->template->$method('task/new', array( + 'ajax' => $this->request->isAjax(), + 'errors' => $errors, + 'values' => $values + array('project_id' => $project['id']), 'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE), - 'columns_list' => $this->board->getColumnsList($project_id), - 'users_list' => $this->projectPermission->getUsersList($project_id), + 'columns_list' => $this->board->getColumnsList($project['id']), + 'users_list' => $this->projectPermission->getMemberList($project['id'], true, false, true), 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project_id), + 'categories_list' => $this->category->getList($project['id']), + 'swimlanes_list' => $swimlanes_list, 'date_format' => $this->config->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats(), - 'menu' => 'tasks', - 'title' => t('New task') + 'title' => $project['name'].' > '.t('New task') ))); } @@ -120,16 +149,15 @@ class Task extends Base */ public function save() { + $project = $this->getProject(); $values = $this->request->getValues(); - $values['creator_id'] = $this->acl->getUserId(); - - $this->checkProjectPermissions($values['project_id']); + $values['creator_id'] = $this->userSession->getId(); list($valid, $errors) = $this->taskValidator->validateCreation($values); if ($valid) { - if ($this->task->create($values)) { + if ($this->taskCreation->create($values)) { $this->session->flash(t('Task created successfully.')); if (isset($values['another_task']) && $values['another_task'] == 1) { @@ -138,7 +166,7 @@ class Task extends Base $this->response->redirect('?controller=task&action=create&'.http_build_query($values)); } else { - $this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']); + $this->response->redirect('?controller=board&action=show&project_id='.$project['id']); } } else { @@ -146,19 +174,7 @@ class Task extends Base } } - $this->response->html($this->template->layout('task_new', array( - 'errors' => $errors, - 'values' => $values, - 'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE), - 'columns_list' => $this->board->getColumnsList($values['project_id']), - 'users_list' => $this->projectPermission->getUsersList($values['project_id']), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($values['project_id']), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), - 'menu' => 'tasks', - 'title' => t('New task') - ))); + $this->create($values, $errors); } /** @@ -166,32 +182,34 @@ class Task extends Base * * @access public */ - public function edit() + public function edit(array $values = array(), array $errors = array()) { $task = $this->getTask(); $ajax = $this->request->isAjax(); - $this->dateParser->format($task, array('date_due')); + if (empty($values)) { + $values = $task; + } + + $this->dateParser->format($values, array('date_due')); $params = array( - 'values' => $task, - 'errors' => array(), + 'values' => $values, + 'errors' => $errors, 'task' => $task, - 'users_list' => $this->projectPermission->getUsersList($task['project_id']), + 'users_list' => $this->projectPermission->getMemberList($task['project_id']), 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($task['project_id']), 'date_format' => $this->config->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats(), 'ajax' => $ajax, - 'menu' => 'tasks', - 'title' => t('Edit a task') ); if ($ajax) { - $this->response->html($this->template->load('task_edit', $params)); + $this->response->html($this->template->render('task/edit', $params)); } else { - $this->response->html($this->taskLayout('task_edit', $params)); + $this->response->html($this->taskLayout('task/edit', $params)); } } @@ -209,14 +227,14 @@ class Task extends Base if ($valid) { - if ($this->task->update($values)) { + if ($this->taskModification->update($values)) { $this->session->flash(t('Task updated successfully.')); if ($this->request->getIntegerParam('ajax')) { $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); } else { - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); } } else { @@ -224,20 +242,7 @@ class Task extends Base } } - $this->response->html($this->taskLayout('task_edit', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'columns_list' => $this->board->getColumnsList($values['project_id']), - 'users_list' => $this->projectPermission->getUsersList($values['project_id']), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($values['project_id']), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), - 'menu' => 'tasks', - 'title' => t('Edit a task'), - 'ajax' => $this->request->isAjax(), - ))); + $this->edit($values, $errors); } /** @@ -250,16 +255,16 @@ class Task extends Base $task = $this->getTask(); $values = $this->request->getValues(); - list($valid, $errors) = $this->taskValidator->validateTimeModification($values); + list($valid,) = $this->taskValidator->validateTimeModification($values); - if ($valid && $this->task->update($values)) { + if ($valid && $this->taskModification->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->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); } /** @@ -270,24 +275,35 @@ class Task extends Base public function close() { $task = $this->getTask(); + $redirect = $this->request->getStringParam('redirect'); if ($this->request->getStringParam('confirmation') === 'yes') { $this->checkCSRFParam(); - if ($this->task->close($task['id'])) { + if ($this->taskStatus->close($task['id'])) { $this->session->flash(t('Task closed successfully.')); } else { $this->session->flashError(t('Unable to close this task.')); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); + if ($redirect === 'board') { + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); + } + + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } - $this->response->html($this->taskLayout('task_close', array( + if ($this->request->isAjax()) { + $this->response->html($this->template->render('task/close', array( + 'task' => $task, + 'redirect' => $redirect, + ))); + } + + $this->response->html($this->taskLayout('task/close', array( 'task' => $task, - 'menu' => 'tasks', - 'title' => t('Close a task') + 'redirect' => $redirect, ))); } @@ -304,19 +320,17 @@ class Task extends Base $this->checkCSRFParam(); - if ($this->task->open($task['id'])) { + if ($this->taskStatus->open($task['id'])) { $this->session->flash(t('Task opened successfully.')); } else { $this->session->flashError(t('Unable to open this task.')); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); } - $this->response->html($this->taskLayout('task_open', array( + $this->response->html($this->taskLayout('task/open', array( 'task' => $task, - 'menu' => 'tasks', - 'title' => t('Open a task') ))); } @@ -346,10 +360,8 @@ class Task extends Base $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); } - $this->response->html($this->taskLayout('task_remove', array( + $this->response->html($this->taskLayout('task/remove', array( 'task' => $task, - 'menu' => 'tasks', - 'title' => t('Remove a task') ))); } @@ -365,21 +377,19 @@ class Task extends Base if ($this->request->getStringParam('confirmation') === 'yes') { $this->checkCSRFParam(); - $task_id = $this->task->duplicateToSameProject($task); + $task_id = $this->taskDuplication->duplicate($task['id']); if ($task_id) { $this->session->flash(t('Task created successfully.')); - $this->response->redirect('?controller=task&action=show&task_id='.$task_id); + $this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$task['project_id']); } else { $this->session->flashError(t('Unable to create this task.')); - $this->response->redirect('?controller=task&action=duplicate&task_id='.$task['id']); + $this->response->redirect('?controller=task&action=duplicate&task_id='.$task['id'].'&project_id='.$task['project_id']); } } - $this->response->html($this->taskLayout('task_duplicate', array( + $this->response->html($this->taskLayout('task/duplicate', array( 'task' => $task, - 'menu' => 'tasks', - 'title' => t('Duplicate a task') ))); } @@ -401,7 +411,7 @@ class Task extends Base if ($valid) { - if ($this->task->update($values)) { + if ($this->taskModification->update($values)) { $this->session->flash(t('Task updated successfully.')); } else { @@ -412,7 +422,7 @@ class Task extends Base $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); } else { - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); } } } @@ -426,49 +436,123 @@ class Task extends Base 'errors' => $errors, 'task' => $task, 'ajax' => $ajax, - 'menu' => 'tasks', - 'title' => t('Edit the description'), ); if ($ajax) { - $this->response->html($this->template->load('task_edit_description', $params)); + $this->response->html($this->template->render('task/edit_description', $params)); } else { - $this->response->html($this->taskLayout('task_edit_description', $params)); + $this->response->html($this->taskLayout('task/edit_description', $params)); } } /** - * Move a task to another project + * Edit recurrence form * * @access public */ - public function move() + public function recurrence() { - $this->toAnotherProject('move'); + $task = $this->getTask(); + $ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax'); + + if ($this->request->isPost()) { + + $values = $this->request->getValues(); + + list($valid, $errors) = $this->taskValidator->validateEditRecurrence($values); + + if ($valid) { + + if ($this->taskModification->update($values)) { + $this->session->flash(t('Task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } + + if ($ajax) { + $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); + } + else { + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); + } + } + } + else { + $values = $task; + $errors = array(); + } + + $params = array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'ajax' => $ajax, + 'recurrence_status_list' => $this->task->getRecurrenceStatusList(), + 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + ); + + if ($ajax) { + $this->response->html($this->template->render('task/edit_recurrence', $params)); + } + else { + $this->response->html($this->taskLayout('task/edit_recurrence', $params)); + } } /** - * Duplicate a task to another project + * Move a task to another project * * @access public */ - public function copy() + public function move() { - $this->toAnotherProject('duplicate'); + $task = $this->getTask(); + $values = $task; + $errors = array(); + $projects_list = $this->projectPermission->getActiveMemberProjects($this->userSession->getId()); + + unset($projects_list[$task['project_id']]); + + if ($this->request->isPost()) { + + $values = $this->request->getValues(); + list($valid, $errors) = $this->taskValidator->validateProjectModification($values); + + if ($valid) { + + if ($this->taskDuplication->moveToProject($task['id'], $values['project_id'])) { + $this->session->flash(t('Task updated successfully.')); + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$values['project_id']); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } + } + } + + $this->response->html($this->taskLayout('task/move_project', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'projects_list' => $projects_list, + ))); } /** - * Common methods between the actions "move" and "copy" + * Duplicate a task to another project * - * @access private + * @access public */ - private function toAnotherProject($action) + public function copy() { $task = $this->getTask(); $values = $task; $errors = array(); - $projects_list = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); + $projects_list = $this->projectPermission->getActiveMemberProjects($this->userSession->getId()); unset($projects_list[$task['project_id']]); @@ -478,10 +562,10 @@ class Task extends Base list($valid, $errors) = $this->taskValidator->validateProjectModification($values); if ($valid) { - $task_id = $this->task->{$action.'ToAnotherProject'}($values['project_id'], $task); + $task_id = $this->taskDuplication->duplicateToProject($task['id'], $values['project_id']); if ($task_id) { $this->session->flash(t('Task created successfully.')); - $this->response->redirect('?controller=task&action=show&task_id='.$task_id); + $this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$values['project_id']); } else { $this->session->flashError(t('Unable to create your task.')); @@ -489,13 +573,49 @@ class Task extends Base } } - $this->response->html($this->taskLayout('task_'.$action.'_project', array( + $this->response->html($this->taskLayout('task/duplicate_project', array( 'values' => $values, 'errors' => $errors, 'task' => $task, 'projects_list' => $projects_list, - 'menu' => 'tasks', - 'title' => t(ucfirst($action).' the task to another project') + ))); + } + + /** + * Display the time tracking details + * + * @access public + */ + public function timesheet() + { + $task = $this->getTask(); + + $subtask_paginator = $this->paginator + ->setUrl('task', 'timesheet', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'pagination' => 'subtasks')) + ->setMax(15) + ->setOrder('start') + ->setDirection('DESC') + ->setQuery($this->subtaskTimeTracking->getTaskQuery($task['id'])) + ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); + + $this->response->html($this->taskLayout('task/time_tracking', array( + 'task' => $task, + 'subtask_paginator' => $subtask_paginator, + ))); + } + + /** + * Display the task transitions + * + * @access public + */ + public function transitions() + { + $task = $this->getTask(); + + $this->response->html($this->taskLayout('task/transitions', array( + 'task' => $task, + 'transitions' => $this->transition->getAllByTask($task['id']), ))); } } |