summaryrefslogtreecommitdiff
path: root/app/Controller/TaskBulkController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-15 20:09:43 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-15 20:09:43 -0400
commit8a6f02735b628033a3284d06a9f633bd260e19ef (patch)
tree57d0c2acb22d6afe0412903a088ed77ac0ba3596 /app/Controller/TaskBulkController.php
parent67b836164997527b91452b19adbcb8aa3c5decf1 (diff)
Added task creation menu for all projects views
Diffstat (limited to 'app/Controller/TaskBulkController.php')
-rw-r--r--app/Controller/TaskBulkController.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/app/Controller/TaskBulkController.php b/app/Controller/TaskBulkController.php
new file mode 100644
index 00000000..4b4a2594
--- /dev/null
+++ b/app/Controller/TaskBulkController.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Class TaskBulkController
+ *
+ * @package Kanboard\Controller
+ */
+class TaskBulkController extends BaseController
+{
+ /**
+ * 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'],
+ ));
+ }
+ }
+ }
+}