class.tx_typo3roadmap_pi1.php 11.5 KB
Newer Older
Mathias Schreiber's avatar
Mathias Schreiber committed
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
142
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
<?php
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2016 Mathias Schreiber <mathias.schreiber@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * Plugin 'TYPO3 Roadmap' for the 'typo3_roadmap' extension.
 *
 * @author        Mathias Schreiber <mathias.schreiber@typo3.org>
 * @package       TYPO3
 * @subpackage    tx_typo3roadmap
 */
class tx_typo3roadmap_pi1 extends tslib_pibase
{
    public $prefixId = 'tx_typo3roadmap_pi1';        // Same as class name
    public $scriptRelPath = 'pi1/class.tx_typo3roadmap_pi1.php';    // Path to this script relative to the extension dir.
    public $extKey = 'typo3_roadmap';    // The extension key.
    public $pi_checkCHash = true;

    /**
     * @var Tx_Fluid_View_StandaloneView
     */
    protected $view;

    /**
     * Color Codes for the charts
     *
     * @var array
     */
    protected $colors = [
        'regular' => '#69A550',
        'security' => '#FF8700',
        'elts' => '#ffb767',
        'sprint' => '#8C8C8C',
        'stabilization' => '#bc0000'
    ];

    /**
     * @var t3lib_DB
     */
    protected $db;

    /**
     * @var t3lib_PageRenderer
     */
    protected $pageRenderer;

    /**
     * The main method of the Plugin.
     *
     * @param string $content The Plugin content
     * @param array  $conf    The Plugin configuration
     *
     * @return string The content that is displayed on the website
     */
    public function main($content = '', array $conf)
    {
        $this->conf = $conf;
        $this->pi_setPiVarDefaults();
        $this->pi_loadLL();
        $this->initializeView();
        $this->db = $GLOBALS['TYPO3_DB'];
        $this->pageRenderer = $GLOBALS['TSFE']->getPageRenderer();

        $majorVersions = $this->getMajorVersions();
        $this->renderCharts($majorVersions);

        $this->view->assign('majors', $majorVersions);
        $this->view->assign('ceUid', $this->cObj->data['uid']);
        $this->view->assign('phpTable', $this->renderPHPCompatibilityMatrix($this->getAllAvailablePHPVersions(), $majorVersions));


        $content .= $this->view->render();

        return $content;
    }

    /**
     * Initialize the Fluid StandAlone View and set the template
     */
    protected function initializeView()
    {
        $this->view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
        $this->view->setTemplatePathAndFilename(t3lib_extMgm::extPath($this->extKey) .
            '/Resources/Private/Templates/Roadmap.html');
    }

    /**
     * Fetches all major versions from the database
     *
     * @return array|NULL
     */
    protected function getMajorVersions()
    {
        $rows = $this->db->exec_SELECTgetRows(
            '*',
            'tx_typo3roadmap_majorversion',
            '1 = 1 ' . $this->cObj->enableFields('tx_typo3roadmap_majorversion'),
            'sorting'
        );
        foreach ($rows as $index => $singleRow) {
            $rows[$index]['minorversions'] = $this->getMinorVersions($singleRow['uid']);
            $rows[$index]['phpVersions'] = $this->getSupportedPHPVersions($singleRow['uid']);
        }

        return $rows;
    }

    /**
     * Fetches the minor versions of a given major version
     *
     * @param int $majorVersion The major version uid to fetch the minors for
     *
     * @return array|NULL
     */
    protected function getMinorVersions($majorVersion)
    {
        $rows = $this->db->exec_SELECTgetRows(
            '*',
            'tx_typo3roadmap_minorversion',
            'parent = ' . (int)$majorVersion . '' . $this->cObj->enableFields('tx_typo3roadmap_minorversion'),
            'sorting'
        );

        return $rows;
    }

    protected function getSupportedPHPVersions($majorVersion)
    {
        $rows = $this->db->exec_SELECTgetRows(
            'uid, version',
            'tx_typo3roadmap_majorversion_phpversions_mm
  INNER JOIN tx_typo3roadmap_phpversion ON tx_typo3roadmap_phpversion.uid = tx_typo3roadmap_majorversion_phpversions_mm.uid_foreign',
        'tx_typo3roadmap_majorversion_phpversions_mm.uid_local = '.(int)$majorVersion . $this->cObj->enableFields('tx_typo3roadmap_phpversion'),
            '',
            '',
            '',
            'uid'
        );
        return $rows;
    }

    /**
     * @return array|NULL
     */
    protected function getAllAvailablePHPVersions()
    {
        $rows = $this->db->exec_SELECTgetRows(
            'uid, version',
            'tx_typo3roadmap_phpversion',
            '1 = 1 ' . $this->cObj->enableFields('tx_typo3roadmap_phpversion'),
            '',
            'version ASC',
            '',
            'uid'
        );
        if($rows === null) {
            return [];
        }
        return $rows;
    }

    /**
     * Renders the LTS charts
     *
     * @param array $majorVersions
     */
    protected function renderCharts(array $majorVersions)
    {
        $this->pageRenderer->addJsLibrary('amcharts', 'https://www.amcharts.com/lib/3/amcharts.js');
        $this->pageRenderer->addJsLibrary('amcharts_serial', 'https://www.amcharts.com/lib/3/serial.js');
        $this->pageRenderer->addJsLibrary('amcharts_gantt', 'https://www.amcharts.com/lib/3/gantt.js');
        $this->pageRenderer->addJsLibrary('amcharts_lightheme', 'https://www.amcharts.com/lib/3/themes/light.js');
        $this->pageRenderer->addJsLibrary('amcharts_export', 'https://www.amcharts.com/lib/3/plugins/export/export.js');
        $this->pageRenderer->addCssFile('https://www.amcharts.com/lib/3/plugins/export/export.css');

        $data = $this->generateChartArray($majorVersions);
        $this->view->assign('data', $data);
        $chartJs = '
        AmCharts.useUTC = true;
200
        var today = new Date();
Mathias Schreiber's avatar
Mathias Schreiber committed
201
202
203
204
205
206
207
208
209
210
211
		var chart = AmCharts.makeChart("charts", {
			"type": "gantt",
			"theme": "light",
			"marginRight": 70,
			"period": "YYYY",
			"dataDateFormat": "YYYY-MM-DD",
			"columnWidth": 0.65,
			"precision": 1,
			"valueAxis": {
				"type": "date",
				"autoGridCount": false,
212
213
214
215
216
217
218
219
220
221
222
223
224
				"gridCount": 24,
				"guides": [
				    {
					"value": today,
					"toValue": today,
					"lineAlpha": 1,
					"lineThickness": 1,
					"inside": true,
					"labelRotation": 90,
					"label": "Today",
					"above": true
				    }
				]
Mathias Schreiber's avatar
Mathias Schreiber committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
			},
			"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
			},
			"chartCursor": {
				"cursorColor": "#55bb76",
				"valueBalloonsEnabled": false,
				"cursorAlpha": 0,
				"valueLineAlpha": 0.5,
				"valueLineBalloonEnabled": true,
				"valueLineEnabled": true,
				"zoomable": false,
				"valueZoomable": true
			},
			"export": {
				"enabled": true
			}
		});
        ';
        $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 array $majorVersions
     *
     * @return array
     */
    protected function generateChartArray(array $majorVersions)
    {
        $data = [];
        foreach ($majorVersions as $index => $majorVersion) {
            $firstStart = (int)$majorVersion['developmentstart'];
            $data[$index]['version'] = $majorVersion['title'];
            foreach ($majorVersion['minorversions'] as $minorIndex => $minorVersion) {
                $realDate = (int)$minorVersion['estimated'];
                if ((int)$minorVersion['released'] >= (int)$minorVersion['estimated']) {
                    $realDate = (int)$minorVersion['released'];
                }

                // Check if we are in the first loop
                if ($minorIndex === 0) {
                    $sprintStart = $firstStart = (int)$majorVersion['developmentstart'];
                } else {
                    //@todo check correct field
                    $sprintStart = $majorVersion['minorversions'][$minorIndex-1]['estimated'];
                }

                //Sprint Segment
                $data[$index]['segments'][] = [
                    'start' => $this->dateFromTimestamp($sprintStart),
                    'end' => $this->dateFromTimestamp($realDate - 1209600),
                    'color' => $this->colors['sprint'],
                    'task' => 'Sprint Phase ' . $minorVersion['version']
                ];

                //Stabilization Segment
                $data[$index]['segments'][] = [
                    'start' => $this->dateFromTimestamp($realDate - 1209600),
                    'end' => $this->dateFromTimestamp($realDate),
                    'color' => $this->colors['stabilization'],
                    'task' => 'Stabilization Phase ' . $minorVersion['version']
                ];
                // Set the last release date as start of maintenance
                $firstStart = $realDate;
            }
            /**
             * Set Maintenance Times
             */
            // Regular Maintenance
            $data[$index]['segments'][] = [
                'start' => $this->dateFromTimestamp($firstStart),
                'end' => $this->dateFromTimestamp($majorVersion['regularsupport']),
                'color' => $this->colors['regular'],
                'task' => 'Regular Maintenance'
            ];
            // Security Maintenance
            $data[$index]['segments'][] = [
                'start' => $this->dateFromTimestamp($majorVersion['regularsupport']),
                'end' => $this->dateFromTimestamp($majorVersion['prioritysupport']),
                'color' => $this->colors['security'],
                'task' => 'Priority bugfixes'
            ];
            // ELTS Maintenance
            if ($majorVersion['extendedsupport'] > 0) {
                $data[$index]['segments'][] = [
                    'start' => $this->dateFromTimestamp($majorVersion['prioritysupport']),
                    'end' => $this->dateFromTimestamp($majorVersion['extendedsupport']),
                    'color' => $this->colors['elts'],
                    'task' => 'Extended support'
                ];
            }
        }

        return $data;
    }

    protected function renderPHPCompatibilityMatrix(array $allVersions, array $majorVersions)
    {
        $content = '<table border="1">';
        $content .= '<tr>';
        foreach ($allVersions as $index => $allVersion) {
            $content .= '<td>' . $allVersion['version'] . '</td>';
        }
        $content .= '</tr>';
        $content .= '</table>';
        return $content;
    }

}