From e6d0658a0eedeb6a641c003d1c492af0f9a7502c Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 1 Sep 2014 19:36:40 -0800 Subject: Add the possibility to duplicate a task to another project --- app/Controller/Task.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'app/Controller') diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 6936185f..35ef6965 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -432,6 +432,26 @@ class Task extends Base * @access public */ public function move() + { + $this->toAnotherProject('move'); + } + + /** + * Duplicate a task to another project + * + * @access public + */ + public function copy() + { + $this->toAnotherProject('duplicate'); + } + + /** + * Common methods between the actions "move" and "copy" + * + * @access private + */ + private function toAnotherProject($action) { $task = $this->getTask(); $values = $task; @@ -446,23 +466,24 @@ class Task extends Base list($valid, $errors) = $this->task->validateProjectModification($values); if ($valid) { - if ($this->task->moveToAnotherProject($values['project_id'], $task)) { - $this->session->flash(t('Task updated successfully.')); - $this->response->redirect('?controller=task&action=show&task_id='.$values['id']); + $task_id = $this->task->{$action.'ToAnotherProject'}($values['project_id'], $task); + if ($task_id) { + $this->session->flash(t('Task created successfully.')); + $this->response->redirect('?controller=task&action=show&task_id='.$task_id); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->session->flashError(t('Unable to create your task.')); } } } - $this->response->html($this->taskLayout('task_move_project', array( + $this->response->html($this->taskLayout('task_'.$action.'_project', array( 'values' => $values, 'errors' => $errors, 'task' => $task, 'projects_list' => $projects_list, 'menu' => 'tasks', - 'title' => t('Move the task to another project') + 'title' => t(ucfirst($action).' the task to another project') ))); } } -- cgit v1.2.3