summaryrefslogtreecommitdiff
path: root/app/Controller/SubtaskController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-10-20 14:47:04 -0700
committerFrederic Guillot <fred@kanboard.net>2017-10-20 14:47:04 -0700
commited98f95cfa4a31609b98fc8354b62a8895f68cda (patch)
tree48f213463e2683a1848228631a381daa86937f14 /app/Controller/SubtaskController.php
parentf1ef49823c38227cab4f28a0a2378556893850c2 (diff)
Add bulk subtasks creation
Diffstat (limited to 'app/Controller/SubtaskController.php')
-rw-r--r--app/Controller/SubtaskController.php53
1 files changed, 37 insertions, 16 deletions
diff --git a/app/Controller/SubtaskController.php b/app/Controller/SubtaskController.php
index b9bb0934..d5db9b2e 100644
--- a/app/Controller/SubtaskController.php
+++ b/app/Controller/SubtaskController.php
@@ -67,29 +67,50 @@ class SubtaskController extends BaseController
$task = $this->getTask();
$values = $this->request->getValues();
$values['task_id'] = $task['id'];
+ $subtasks = explode("\r\n", isset($values['title']) ? $values['title'] : '');
+ $subtasksAdded = 0;
- list($valid, $errors) = $this->subtaskValidator->validateCreation($values);
+ foreach ($subtasks as $subtask) {
+ $subtask = trim($subtask);
- if ($valid) {
- if ($this->subtaskModel->create($values) !== false) {
- $this->flash->success(t('Sub-task added successfully.'));
- } else {
- $this->flash->failure(t('Unable to create your sub-task.'));
- }
+ if (! empty($subtask)) {
+ $subtaskValues = $values;
+ $subtaskValues['title'] = $subtask;
+
+ list($valid, $errors) = $this->subtaskValidator->validateCreation($subtaskValues);
+
+ if (! $valid) {
+ $this->create($values, $errors);
+ return false;
+ }
- if (isset($values['another_subtask']) && $values['another_subtask'] == 1) {
- return $this->create(array(
- 'project_id' => $task['project_id'],
- 'task_id' => $task['id'],
- 'user_id' => $values['user_id'],
- 'another_subtask' => 1
- ));
+ if (! $this->subtaskModel->create($subtaskValues)) {
+ $this->flash->failure(t('Unable to create your sub-task.'));
+ $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true);
+ return false;
+ }
+
+ $subtasksAdded++;
}
+ }
- return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true);
+ if (isset($values['another_subtask']) && $values['another_subtask'] == 1) {
+ return $this->create(array(
+ 'project_id' => $task['project_id'],
+ 'task_id' => $task['id'],
+ 'user_id' => $values['user_id'],
+ 'another_subtask' => 1,
+ 'subtasks_added' => $subtasksAdded,
+ ));
+ } else if ($subtasksAdded > 0) {
+ if ($subtasksAdded === 1) {
+ $this->flash->success(t('Subtask added successfully.'));
+ } else {
+ $this->flash->success(t('%d subtasks added successfully.', $subtasksAdded));
+ }
}
- return $this->create($values, $errors);
+ $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true);
}
/**