summaryrefslogtreecommitdiff
path: root/app/Controller/TaskDuplicationController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-28 13:41:54 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-28 13:41:54 -0400
commit1353929a7dbd3f2e897fa7d3ab88e959ca573f9f (patch)
tree30bdbac4e466e74c3dfb4d451422f03c62bcbe41 /app/Controller/TaskDuplicationController.php
parentab48a09f0d674b703467975b376c5ac7352670ae (diff)
Rename controllers
Diffstat (limited to 'app/Controller/TaskDuplicationController.php')
-rw-r--r--app/Controller/TaskDuplicationController.php141
1 files changed, 141 insertions, 0 deletions
diff --git a/app/Controller/TaskDuplicationController.php b/app/Controller/TaskDuplicationController.php
new file mode 100644
index 00000000..ab7b6b42
--- /dev/null
+++ b/app/Controller/TaskDuplicationController.php
@@ -0,0 +1,141 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Task Duplication controller
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class TaskDuplicationController extends BaseController
+{
+ /**
+ * Duplicate a task
+ *
+ * @access public
+ */
+ public function duplicate()
+ {
+ $task = $this->getTask();
+
+ if ($this->request->getStringParam('confirmation') === 'yes') {
+ $this->checkCSRFParam();
+ $task_id = $this->taskDuplication->duplicate($task['id']);
+
+ if ($task_id > 0) {
+ $this->flash->success(t('Task created successfully.'));
+ return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task_id)));
+ } else {
+ $this->flash->failure(t('Unable to create this task.'));
+ return $this->response->redirect($this->helper->url->to('TaskDuplicationController', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true);
+ }
+ }
+
+ return $this->response->html($this->template->render('task_duplication/duplicate', array(
+ 'task' => $task,
+ )));
+ }
+
+ /**
+ * Move a task to another project
+ *
+ * @access public
+ */
+ public function move()
+ {
+ $task = $this->getTask();
+
+ if ($this->request->isPost()) {
+ $values = $this->request->getValues();
+ list($valid, ) = $this->taskValidator->validateProjectModification($values);
+
+ if ($valid && $this->taskDuplication->moveToProject($task['id'],
+ $values['project_id'],
+ $values['swimlane_id'],
+ $values['column_id'],
+ $values['category_id'],
+ $values['owner_id'])) {
+ $this->flash->success(t('Task updated successfully.'));
+ return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task['id'])));
+ }
+
+ $this->flash->failure(t('Unable to update your task.'));
+ }
+
+ return $this->chooseDestination($task, 'task_duplication/move');
+ }
+
+ /**
+ * Duplicate a task to another project
+ *
+ * @access public
+ */
+ public function copy()
+ {
+ $task = $this->getTask();
+
+ if ($this->request->isPost()) {
+ $values = $this->request->getValues();
+ list($valid, ) = $this->taskValidator->validateProjectModification($values);
+
+ if ($valid) {
+ $task_id = $this->taskDuplication->duplicateToProject(
+ $task['id'], $values['project_id'], $values['swimlane_id'],
+ $values['column_id'], $values['category_id'], $values['owner_id']
+ );
+
+ if ($task_id > 0) {
+ $this->flash->success(t('Task created successfully.'));
+ return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task_id)));
+ }
+ }
+
+ $this->flash->failure(t('Unable to create your task.'));
+ }
+
+ return $this->chooseDestination($task, 'task_duplication/copy');
+ }
+
+ /**
+ * Choose destination when move/copy task to another project
+ *
+ * @access private
+ * @param array $task
+ * @param string $template
+ */
+ private function chooseDestination(array $task, $template)
+ {
+ $values = array();
+ $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
+
+ unset($projects_list[$task['project_id']]);
+
+ if (! empty($projects_list)) {
+ $dst_project_id = $this->request->getIntegerParam('dst_project_id', key($projects_list));
+
+ $swimlanes_list = $this->swimlane->getList($dst_project_id, false, true);
+ $columns_list = $this->column->getList($dst_project_id);
+ $categories_list = $this->category->getList($dst_project_id);
+ $users_list = $this->projectUserRole->getAssignableUsersList($dst_project_id);
+
+ $values = $this->taskDuplication->checkDestinationProjectValues($task);
+ $values['project_id'] = $dst_project_id;
+ } else {
+ $swimlanes_list = array();
+ $columns_list = array();
+ $categories_list = array();
+ $users_list = array();
+ }
+
+ $this->response->html($this->template->render($template, array(
+ 'values' => $values,
+ 'task' => $task,
+ 'projects_list' => $projects_list,
+ 'swimlanes_list' => $swimlanes_list,
+ 'columns_list' => $columns_list,
+ 'categories_list' => $categories_list,
+ 'users_list' => $users_list,
+ )));
+ }
+}