summaryrefslogtreecommitdiff
path: root/app/Formatter/ProjectGanttFormatter.php
blob: 532e6822bf704c86d18df416129b22a673bc49fd (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\Formatter;

use Kanboard\Core\Filter\FormatterInterface;

/**
 * Gantt chart formatter for projects
 *
 * @package  formatter
 * @author   Frederic Guillot
 */
class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface
{
    /**
     * Format projects to be displayed in the Gantt chart
     *
     * @access public
     * @return array
     */
    public function format()
    {
        $projects = $this->query->findAll();
        $colors = $this->color->getDefaultColors();
        $bars = array();

        foreach ($projects as $project) {
            $start = empty($project['start_date']) ? time() : strtotime($project['start_date']);
            $end = empty($project['end_date']) ? $start : strtotime($project['end_date']);
            $color = next($colors) ?: reset($colors);

            $bars[] = array(
                'type' => 'project',
                'id' => $project['id'],
                'title' => $project['name'],
                'start' => array(
                    (int) date('Y', $start),
                    (int) date('n', $start),
                    (int) date('j', $start),
                ),
                'end' => array(
                    (int) date('Y', $end),
                    (int) date('n', $end),
                    (int) date('j', $end),
                ),
                'link' => $this->helper->url->href('ProjectViewController', 'show', array('project_id' => $project['id'])),
                'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])),
                'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])),
                'color' => $color,
                'not_defined' => empty($project['start_date']) || empty($project['end_date']),
                'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']),
            );
        }

        return $bars;
    }
}