diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/TaskCreationController.php | 56 | ||||
-rw-r--r-- | app/Model/TaskCreationModel.php | 2 | ||||
-rw-r--r-- | app/Model/TaskModificationModel.php | 2 | ||||
-rw-r--r-- | app/Template/task_creation/duplicate_projects.php | 28 | ||||
-rw-r--r-- | app/Template/task_creation/show.php | 1 |
5 files changed, 83 insertions, 6 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']) + ))); + } } diff --git a/app/Model/TaskCreationModel.php b/app/Model/TaskCreationModel.php index b9b07d5e..bd95c1a4 100644 --- a/app/Model/TaskCreationModel.php +++ b/app/Model/TaskCreationModel.php @@ -61,7 +61,7 @@ class TaskCreationModel extends Base $values = $this->dateParser->convert($values, array('date_due')); $values = $this->dateParser->convert($values, array('date_started'), true); - $this->helper->model->removeFields($values, array('another_task')); + $this->helper->model->removeFields($values, array('another_task', 'duplicate_multiple_projects')); $this->helper->model->resetFields($values, array('creator_id', 'owner_id', 'swimlane_id', 'date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); if (empty($values['column_id'])) { diff --git a/app/Model/TaskModificationModel.php b/app/Model/TaskModificationModel.php index 6e16fbec..0ae29293 100644 --- a/app/Model/TaskModificationModel.php +++ b/app/Model/TaskModificationModel.php @@ -101,7 +101,7 @@ class TaskModificationModel extends Base $values = $this->dateParser->convert($values, array('date_due')); $values = $this->dateParser->convert($values, array('date_started'), true); - $this->helper->model->removeFields($values, array('another_task', 'id')); + $this->helper->model->removeFields($values, array('id')); $this->helper->model->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); $this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); diff --git a/app/Template/task_creation/duplicate_projects.php b/app/Template/task_creation/duplicate_projects.php new file mode 100644 index 00000000..dc0fa105 --- /dev/null +++ b/app/Template/task_creation/duplicate_projects.php @@ -0,0 +1,28 @@ +<div class="page-header"> + <h2><?= $this->text->e($project['name']) ?> > <?= $this->text->e($task['title']) ?></h2> +</div> + +<?php if (empty($projects_list)): ?> + <p class="alert"><?= t('There is no destination project available.') ?></p> + <div class="form-actions"> + <?= $this->url->link(t('cancel'), 'BoardViewController', 'show', array('project_id' => $task['project_id']), false, 'close-popover btn') ?> + </div> +<?php else: ?> + <form class="popover-form" method="post" action="<?= $this->url->href('TaskCreationController', 'duplicateProjects', array('project_id' => $task['project_id'])) ?>" autocomplete="off"> + <?= $this->form->csrf() ?> + <?= $this->form->hidden('task_id', $values) ?> + + <?= $this->form->select( + 'project_ids[]', + $projects_list, + $values, + array(), + array('multiple') + ) ?> + + <div class="form-actions"> + <button type="submit" class="btn btn-blue"><?= t('Duplicate') ?></button> + <?= t('or') ?> <?= $this->url->link(t('cancel'), 'BoardViewController', 'show', array('project_id' => $task['project_id']), false, 'close-popover') ?> + </div> + </form> +<?php endif ?> diff --git a/app/Template/task_creation/show.php b/app/Template/task_creation/show.php index 1a8a17d5..c2cc4aac 100644 --- a/app/Template/task_creation/show.php +++ b/app/Template/task_creation/show.php @@ -13,6 +13,7 @@ <?php if (! isset($duplicate)): ?> <?= $this->form->checkbox('another_task', t('Create another task'), 1, isset($values['another_task']) && $values['another_task'] == 1) ?> + <?= $this->form->checkbox('duplicate_multiple_projects', t('Duplicate to multiple projects'), 1) ?> <?php endif ?> <?= $this->hook->render('template:task:form:first-column', array('values' => $values, 'errors' => $errors)) ?> |