summaryrefslogtreecommitdiff
path: root/app/Controller/ProjectGanttController.php
blob: 1c6ace582d5db017ab475ca61b02b3bce62691e5 (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
<?php

namespace Kanboard\Controller;

use Kanboard\Filter\ProjectIdsFilter;
use Kanboard\Filter\ProjectStatusFilter;
use Kanboard\Filter\ProjectTypeFilter;
use Kanboard\Formatter\ProjectGanttFormatter;
use Kanboard\Model\Project;

/**
 * Projects Gantt Controller
 *
 * @package Kanboard\Controller
 * @author  Frederic Guillot
 */
class ProjectGanttController extends BaseController
{
    /**
     * Show Gantt chart for all projects
     */
    public function show()
    {
        $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId());
        $filter = $this->projectQuery
            ->withFilter(new ProjectTypeFilter(Project::TYPE_TEAM))
            ->withFilter(new ProjectStatusFilter(Project::ACTIVE))
            ->withFilter(new ProjectIdsFilter($project_ids));

        $filter->getQuery()->asc(Project::TABLE.'.start_date');

        $this->response->html($this->helper->layout->app('project_gantt/show', array(
            'projects' => $filter->format(new ProjectGanttFormatter($this->container)),
            'title' => t('Gantt chart for all projects'),
        )));
    }

    /**
     * Save new project start date and end date
     */
    public function save()
    {
        $values = $this->request->getJson();

        $result = $this->project->update(array(
            'id' => $values['id'],
            'start_date' => $this->dateParser->getIsoDate(strtotime($values['start'])),
            'end_date' => $this->dateParser->getIsoDate(strtotime($values['end'])),
        ));

        if (! $result) {
            $this->response->json(array('message' => 'Unable to save project'), 400);
        } else {
            $this->response->json(array('message' => 'OK'), 201);
        }
    }
}