RoadmapController.php 8.26 KB
Newer Older
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
65
<?php
namespace T3o\Typo3Roadmap\Controller;

/**
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use \TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use \T3o\Typo3Roadmap\Domain\Model\MajorVersion;

/**
 * Class \T3o\Typo3Roadmap\Controller\RoadmapController
 * @author Sebastian Diez
 */
class RoadmapController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
    /*
     * Color Codes for the charts
     */
    const COLOR_CODE_REGULAR = '#69A550';
    const COLOR_CODE_SECURITY = '#FF8700';
    const COLOR_CODE_ELTS = '#ffb767';
    const COLOR_CODE_SPRINT = '#e6e6e6';
    const COLOR_CODE_STABILIZATION = '#983030';

    /**
     * majorVersionRepository
     *
     * @var \T3o\Typo3Roadmap\Domain\Repository\MajorVersionRepository
     * @inject
     */
    protected $majorVersionRepository = null;

    /**
     * majorVersionRepository
     *
     * @var \T3o\Typo3Roadmap\Domain\Repository\PhpVersionRepository
     * @inject
     */
    protected $phpVersionRepository = null;

    /**
     * pageRenderer
     *
     * @var \TYPO3\CMS\Core\Page\PageRenderer
     * @inject
     */
    protected $pageRenderer = null;

    /**
     * action roadmap
     *
     * @return void
     */
    public function roadmapAction()
    {
66
        $majorVersions = array_reverse($this->majorVersionRepository->findAll()->toArray());
67
68
69
70
71
72
73
74
75
76
77
78
79
        $this->view->assign('majorVersions', $majorVersions);
        $phpVersions = $this->phpVersionRepository->findAll()->toArray();
        $this->view->assign('phpVersions', $phpVersions);
        $this->renderCharts($majorVersions);
    }

    /**
     * Renders the LTS charts
     *
     * @param MajorVersion[] $majorVersions
     */
    protected function renderCharts($majorVersions)
    {
Thomas Löffler's avatar
Thomas Löffler committed
80
81
82
83
84
85
        $this->pageRenderer->addJsLibrary('amcharts', 'EXT:typo3_roadmap/Resources/Public/JavaScript/amcharts.min.js');
        $this->pageRenderer->addJsLibrary('amcharts_serial', 'EXT:typo3_roadmap/Resources/Public/JavaScript/serial.min.js');
        $this->pageRenderer->addJsLibrary('amcharts_gantt', 'EXT:typo3_roadmap/Resources/Public/JavaScript/gantt.min.js');
        $this->pageRenderer->addJsLibrary('amcharts_lightheme', 'EXT:typo3_roadmap/Resources/Public/JavaScript/lighttheme.min.js');
        $this->pageRenderer->addJsLibrary('amcharts_export', 'EXT:typo3_roadmap/Resources/Public/JavaScript/export.min.js');
        $this->pageRenderer->addCssFile('EXT:typo3_roadmap/Resources/Public/Css/export.css');
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// @TODO comment css
        $data = $this->generateChartArray($majorVersions);
        $this->view->assign('data', $data);
        $chartJs = '
        AmCharts.useUTC = true;
        var today = new Date();
		var chart = AmCharts.makeChart("charts", {
			"type": "gantt",
			"theme": "light",
			"period": "YYYY",
			"dataDateFormat": "YYYY-MM-DD",
			"columnWidth": 0.65,
			"precision": 1,
			"valueAxis": {
				"type": "date",
				"autoGridCount": false,
				"gridCount": 24,
				"guides": [
				    {
					"value": today,
					"toValue": today,
					"lineAlpha": 1,
					"lineThickness": 1,
					"inside": true,
					"labelRotation": 90,
					"label": "Today",
					"above": true
				    }
				]
			},
			"graph": {
				"fillAlphas": 1,
				"balloonText": "<b>[[task]]</b>: [[open]]-[[value]]"
			},
			"rotate": true,
			"categoryField": "version",
			"segmentsField": "segments",
			"colorField": "color",
			"startDateField": "start",
			"endDateField": "end",
			"dataProvider": ' . json_encode($data) . ',
			"valueScrollbar": {
				"autoGridCount": true,
				"color": "#555555"
			},
			"chartCursor": {
				"cursorColor": "#55bb76",
				"valueBalloonsEnabled": false,
				"cursorAlpha": 0,
				"valueLineAlpha": 0.5,
				"valueLineBalloonEnabled": true,
				"valueLineEnabled": true,
				"zoomable": false,
				"valueZoomable": true
			},
			"export": {
142
				"enabled": false,
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
				"menu": [
				    "PNG","PDF", "SVG"
				]
			}
		});
        ';
        $this->pageRenderer->addJsFooterInlineCode('ltsChart', $chartJs);
    }

    /**
     * Central date formatter
     *
     * @param int $timeStamp
     *
     * @return bool|string
     */
    protected function dateFromTimestamp($timeStamp = 0)
    {
        return date('Y-m-d', $timeStamp);
    }

    /**
     * Creates the raw JSON data for the chart
     * This is rather complex so take your time
     *
     * @param MajorVersion[] $majorVersions
     *
     * @return array
     */
    protected function generateChartArray($majorVersions)
    {
        $data = array();
        foreach ($majorVersions as $index => $majorVersion) {
            $firstStart = (int)$majorVersion->getDevelopmentStart();
            $data[$index]['version'] = $majorVersion->getTitle();
            foreach ($majorVersion->getMinorVersions() as $minorIndex => $minorVersion) {
                /* @var \T3o\Typo3Roadmap\Domain\Model\MinorVersion $minorVersion */
                $realDate = (int)$minorVersion->getEstimated();
                if ((int)$minorVersion->getReleased() >= (int)$minorVersion->getEstimated()) {
                    $realDate = (int)$minorVersion->getReleased();
                }

                // Check if we are in the first loop
                if ($minorIndex === 0) {
                    $sprintStart = $firstStart = (int)$majorVersion->getDevelopmentStart();
                } else {
                    /* @var \T3o\Typo3Roadmap\Domain\Model\MinorVersion $minorVersion */
                    $previousMinorVersion = $majorVersion->getMinorVersions()[$minorIndex - 1];
                    $sprintStart = $previousMinorVersion->getEstimated();
                    if ((int)$previousMinorVersion->getReleased() >= (int)$previousMinorVersion->getEstimated()) {
                        $sprintStart = (int)$previousMinorVersion->getReleased();
                    }
                }

                //Sprint Segment
                $data[$index]['segments'][] = array(
                    'start' => $this->dateFromTimestamp($sprintStart),
                    'end'   => $this->dateFromTimestamp($realDate - 1209600),
                    'color' => self::COLOR_CODE_SPRINT,
                    'task'  => 'Sprint Phase ' . $minorVersion->getVersion()
                );

                //Stabilization Segment
                $data[$index]['segments'][] = array(
                    'start' => $this->dateFromTimestamp($realDate - 1209600),
                    'end'   => $this->dateFromTimestamp($realDate),
                    'color' => self::COLOR_CODE_STABILIZATION,
                    'task'  => 'Stabilization Phase ' . $minorVersion->getVersion()
                );
                // Set the last release date as start of maintenance
                $firstStart = $realDate;
            }
            /**
             * Set Maintenance Times
             */
            // Regular Maintenance
            $data[$index]['segments'][] = array(
                'start' => $this->dateFromTimestamp($firstStart),
                'end'   => $this->dateFromTimestamp($majorVersion->getRegularSupport()),
                'color' => self::COLOR_CODE_REGULAR,
                'task'  => 'Regular Maintenance'
            );
            // Security Maintenance
            $data[$index]['segments'][] = array(
                'start' => $this->dateFromTimestamp($majorVersion->getRegularSupport()),
                'end'   => $this->dateFromTimestamp($majorVersion->getPrioritySupport()),
                'color' => self::COLOR_CODE_SECURITY,
                'task'  => 'Priority bugfixes'
            );
            // ELTS Maintenance
            if ($majorVersion->getExtendedSupport() > 0) {
                $data[$index]['segments'][] = array(
                    'start' => $this->dateFromTimestamp($majorVersion->getPrioritySupport()),
                    'end'   => $this->dateFromTimestamp($majorVersion->getExtendedSupport()),
                    'color' => self::COLOR_CODE_ELTS,
                    'task'  => 'Extended support (optional)'
                );
            }
        }

        return $data;
    }
}