summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-13 21:44:31 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-13 21:44:31 -0400
commit10f662ce07cdc0924cb6688fcb2d502e7aa21acc (patch)
tree33e58c1978e0b5908c97d786d7145d6dbc7e4a7b /app/Controller
parenta1a48b8374523fc19b3fb8596649baff0f3fa4a4 (diff)
Add tasks in bulk from the board
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/TaskBulk.php88
-rw-r--r--app/Controller/Taskcreation.php2
2 files changed, 89 insertions, 1 deletions
diff --git a/app/Controller/TaskBulk.php b/app/Controller/TaskBulk.php
new file mode 100644
index 00000000..4e9d4443
--- /dev/null
+++ b/app/Controller/TaskBulk.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Class TaskBulk
+ *
+ * @package Kanboard\Controller
+ */
+class TaskBulk extends Base
+{
+ /**
+ * Show the form
+ *
+ * @param array $values
+ * @param array $errors
+ */
+ public function show(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+
+ if (empty($values)) {
+ $values = array(
+ 'swimlane_id' => $this->request->getIntegerParam('swimlane_id'),
+ 'column_id' => $this->request->getIntegerParam('column_id'),
+ 'project_id' => $project['id'],
+ );
+ }
+
+ $this->response->html($this->template->render('task_bulk/show', array(
+ 'project' => $project,
+ 'values' => $values,
+ 'errors' => $errors,
+ 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true),
+ 'colors_list' => $this->color->getList(),
+ 'categories_list' => $this->category->getList($project['id']),
+ )));
+ }
+
+ /**
+ * Save all tasks in the database
+ */
+ public function save()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->taskValidator->validateBulkCreation($values);
+
+ if ($valid) {
+ $this->createTasks($project, $values);
+ $this->response->redirect($this->helper->url->to(
+ 'Board',
+ 'show',
+ array('project_id' => $project['id']),
+ 'swimlane-'. $values['swimlane_id']
+ ), true);
+ } else {
+ $this->show($values, $errors);
+ }
+ }
+
+ /**
+ * Create all tasks
+ *
+ * @param array $project
+ * @param array $values
+ */
+ protected function createTasks(array $project, array $values)
+ {
+ $tasks = preg_split('/\r\n|[\r\n]/', $values['tasks']);
+
+ foreach ($tasks as $title) {
+ $title = trim($title);
+
+ if (! empty($title)) {
+ $this->taskCreation->create(array(
+ 'title' => $title,
+ 'column_id' => $values['column_id'],
+ 'swimlane_id' => $values['swimlane_id'],
+ 'category_id' => empty($values['category_id']) ? 0 : $values['category_id'],
+ 'owner_id' => empty($values['owner_id']) ? 0 : $values['owner_id'],
+ 'color_id' => $values['color_id'],
+ 'project_id' => $project['id'],
+ ));
+ }
+ }
+ }
+}
diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php
index 1d8a0e29..1c9e0d82 100644
--- a/app/Controller/Taskcreation.php
+++ b/app/Controller/Taskcreation.php
@@ -79,6 +79,6 @@ class Taskcreation extends Base
));
}
- $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])));
+ $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])), true);
}
}