summaryrefslogtreecommitdiff
path: root/app/Controller/TaskCreationController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-09-11 20:55:21 -0400
committerFrederic Guillot <fred@kanboard.net>2016-09-11 20:55:21 -0400
commit49f9b65e6ceb97afffa3d44eb95e5aca64a5ab40 (patch)
treeeb0736708dfb515b5e7ee6519ca4e562ab136102 /app/Controller/TaskCreationController.php
parentdaa184458bdd595d02bc3625ff7abacbfd830b29 (diff)
Duplicate a task quickly to multiple projects after the creation
Diffstat (limited to 'app/Controller/TaskCreationController.php')
-rw-r--r--app/Controller/TaskCreationController.php56
1 files changed, 52 insertions, 4 deletions
diff --git a/app/Controller/TaskCreationController.php b/app/Controller/TaskCreationController.php
index 5f1337e5..c68964f6 100644
--- a/app/Controller/TaskCreationController.php
+++ b/app/Controller/TaskCreationController.php
@@ -52,18 +52,46 @@ class TaskCreationController extends BaseController
list($valid, $errors) = $this->taskValidator->validateCreation($values);
- if ($valid && $this->taskCreationModel->create($values)) {
+ if ($valid && ($task_id = $this->taskCreationModel->create($values))) {
$this->flash->success(t('Task created successfully.'));
- $this->afterSave($project, $values);
+ $this->afterSave($project, $values, $task_id);
} else {
$this->flash->failure(t('Unable to create your task.'));
$this->show($values, $errors);
}
}
- private function afterSave(array $project, array &$values)
+ /**
+ * Duplicate created tasks to multiple projects
+ *
+ * @throws PageNotFoundException
+ */
+ public function duplicateProjects()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+
+ if (isset($values['project_ids'])) {
+ foreach ($values['project_ids'] as $project_id) {
+ $this->taskProjectDuplicationModel->duplicateToProject($values['task_id'], $project_id);
+ }
+ }
+
+ $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
+ }
+
+ /**
+ * Executed after the task is saved
+ *
+ * @param array $project
+ * @param array $values
+ * @param integer $task_id
+ */
+ protected function afterSave(array $project, array &$values, $task_id)
{
- if (isset($values['another_task']) && $values['another_task'] == 1) {
+ if (isset($values['duplicate_multiple_projects']) && $values['duplicate_multiple_projects'] == 1) {
+ $this->chooseProjects($project, $task_id);
+ } elseif (isset($values['another_task']) && $values['another_task'] == 1) {
$this->show(array(
'owner_id' => $values['owner_id'],
'color_id' => $values['color_id'],
@@ -97,4 +125,24 @@ class TaskCreationController extends BaseController
$values = $this->hook->merge('controller:task-creation:form:default', $values, array('default_values' => $values));
return $values;
}
+
+ /**
+ * Choose projects
+ *
+ * @param array $project
+ * @param integer $task_id
+ */
+ protected function chooseProjects(array $project, $task_id)
+ {
+ $task = $this->taskFinderModel->getById($task_id);
+ $projects = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId());
+ unset($projects[$project['id']]);
+
+ $this->response->html($this->template->render('task_creation/duplicate_projects', array(
+ 'project' => $project,
+ 'task' => $task,
+ 'projects_list' => $projects,
+ 'values' => array('task_id' => $task['id'])
+ )));
+ }
}