summaryrefslogtreecommitdiff
path: root/app/Controller/TaskGanttCreationController.php
blob: 0fbac8bb85e0aa45498587f29abf3276e12ccc1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

namespace Kanboard\Controller;

/**
 * Class TaskGanttCreationController
 *
 * @package Kanboard\Controller
 * @author  Frederic Guillot
 */
class TaskGanttCreationController extends BaseController
{
    /**
     * Simplified form to create a new task
     *
     * @access public
     * @param  array $values
     * @param  array $errors
     * @throws \Kanboard\Core\Controller\PageNotFoundException
     */
    public function show(array $values = array(), array $errors = array())
    {
        $project = $this->getProject();

        $values = $values + array(
                'project_id' => $project['id'],
                'column_id' => $this->columnModel->getFirstColumnId($project['id']),
                'position' => 1
            );

        $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values));
        $values = $this->hook->merge('controller:gantt:task:form:default', $values, array('default_values' => $values));

        $this->response->html($this->template->render('task_gantt_creation/show', array(
            'project' => $project,
            'errors' => $errors,
            'values' => $values,
            'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, true),
            'categories_list' => $this->categoryModel->getList($project['id']),
            'swimlanes_list' => $this->swimlaneModel->getList($project['id'], false, true),
        )));
    }

    /**
     * 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 && $this->taskCreationModel->create($values)) {
            $this->flash->success(t('Task created successfully.'));
            $this->response->redirect($this->helper->url->to('TaskGanttController', 'show', array('project_id' => $project['id'])));
        } else {
            $this->flash->failure(t('Unable to create your task.'));
            $this->show($values, $errors);
        }
    }
}