summaryrefslogtreecommitdiff
path: root/app/Controller/Taskcreation.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-19 18:14:20 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-19 18:14:20 -0400
commit401b0bdfb10ebfe75c9a392de52d37cc3c22c062 (patch)
tree841bf69b8d404a29ab92692a9ebfb8d5a7e500e1 /app/Controller/Taskcreation.php
parentfcdd71af2cabdd1252172ac83a24be8672ca34cc (diff)
Split task controller into smaller classes
Diffstat (limited to 'app/Controller/Taskcreation.php')
-rw-r--r--app/Controller/Taskcreation.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php
new file mode 100644
index 00000000..7c841e10
--- /dev/null
+++ b/app/Controller/Taskcreation.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Controller;
+
+use Model\Project as ProjectModel;
+
+/**
+ * Task Creation controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Taskcreation extends Base
+{
+ /**
+ * Display a form to create a new task
+ *
+ * @access public
+ */
+ public function create(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+ $method = $this->request->isAjax() ? 'render' : 'layout';
+ $swimlanes_list = $this->swimlane->getList($project['id'], false, true);
+
+ if (empty($values)) {
+
+ $values = array(
+ 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanes_list)),
+ 'column_id' => $this->request->getIntegerParam('column_id'),
+ 'color_id' => $this->request->getStringParam('color_id', $this->color->getDefaultColor()),
+ 'owner_id' => $this->request->getIntegerParam('owner_id'),
+ 'another_task' => $this->request->getIntegerParam('another_task'),
+ );
+ }
+
+ $this->response->html($this->template->$method('task_creation/form', array(
+ 'ajax' => $this->request->isAjax(),
+ 'errors' => $errors,
+ 'values' => $values + array('project_id' => $project['id']),
+ 'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE),
+ 'columns_list' => $this->board->getColumnsList($project['id']),
+ 'users_list' => $this->projectPermission->getMemberList($project['id'], true, false, true),
+ 'colors_list' => $this->color->getList(),
+ 'categories_list' => $this->category->getList($project['id']),
+ 'swimlanes_list' => $swimlanes_list,
+ 'date_format' => $this->config->get('application_date_format'),
+ 'date_formats' => $this->dateParser->getAvailableFormats(),
+ 'title' => $project['name'].' &gt; '.t('New task')
+ )));
+ }
+
+ /**
+ * Validate and save a new task
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+
+ list($valid, $errors) = $this->taskValidator->validateCreation($values);
+
+ if ($valid) {
+
+ if ($this->taskCreation->create($values)) {
+ $this->session->flash(t('Task created successfully.'));
+
+ if (isset($values['another_task']) && $values['another_task'] == 1) {
+ unset($values['title']);
+ unset($values['description']);
+ $this->response->redirect($this->helper->url->to('taskcreation', 'create', $values));
+ }
+ else {
+ $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])));
+ }
+ }
+ else {
+ $this->session->flashError(t('Unable to create your task.'));
+ }
+ }
+
+ $this->create($values, $errors);
+ }
+}