class.tx_typo3roadmap_pi1.php 11.8 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
<?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',
Mathias Schreiber's avatar
Mathias Schreiber committed
53
54
        'sprint' => '#e6e6e6',
        'stabilization' => '#983030'
Mathias Schreiber's avatar
Mathias Schreiber committed
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
    ];

    /**
     * @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'];
82
        $this->pageRenderer = $this->getFrontendController()->getPageRenderer();
Mathias Schreiber's avatar
Mathias Schreiber committed
83
84

        $majorVersions = $this->getMajorVersions();
85
86
        $phpVersions = $this->getAllAvailablePHPVersions();

Mathias Schreiber's avatar
Mathias Schreiber committed
87
88
89
90
        $this->renderCharts($majorVersions);

        $this->view->assign('majors', $majorVersions);
        $this->view->assign('ceUid', $this->cObj->data['uid']);
91
92
        $this->view->assign('phpVersions', $phpVersions);
        $this->view->assign('majorVersions', $majorVersions);
Mathias Schreiber's avatar
Mathias Schreiber committed
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

        $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) {
123
124
125
126
127
            foreach ($singleRow as $fieldName => $fieldValue) {
                if (t3lib_div::testInt($fieldValue)) {
                    $rows[$index][$fieldName] = (int)$fieldValue;
                }
            }
Mathias Schreiber's avatar
Mathias Schreiber committed
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
            $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;
    }

154
155
156
157
    /**
     * @param int $majorVersion
     * @return array
     */
Mathias Schreiber's avatar
Mathias Schreiber committed
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
    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');
Mathias Schreiber's avatar
Mathias Schreiber committed
205
//        $this->pageRenderer->addCssFile('https://www.amcharts.com/lib/3/plugins/export/export.css');
Mathias Schreiber's avatar
Mathias Schreiber committed
206
207
208
209
210

        $data = $this->generateChartArray($majorVersions);
        $this->view->assign('data', $data);
        $chartJs = '
        AmCharts.useUTC = true;
211
        var today = new Date();
Mathias Schreiber's avatar
Mathias Schreiber committed
212
213
214
		var chart = AmCharts.makeChart("charts", {
			"type": "gantt",
			"theme": "light",
Mathias Schreiber's avatar
Mathias Schreiber committed
215
//			"marginRight": 70,
Mathias Schreiber's avatar
Mathias Schreiber committed
216
217
218
219
220
221
222
			"period": "YYYY",
			"dataDateFormat": "YYYY-MM-DD",
			"columnWidth": 0.65,
			"precision": 1,
			"valueAxis": {
				"type": "date",
				"autoGridCount": false,
223
224
225
226
227
228
229
230
231
232
233
234
235
				"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
236
237
238
239
240
241
242
243
244
245
246
247
			},
			"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) . ',
248
249
250
251
			"valueScrollbar": {
				"autoGridCount": true,
				"color": "#555555"
			},
Mathias Schreiber's avatar
Mathias Schreiber committed
252
253
254
255
256
257
258
259
260
261
262
			"chartCursor": {
				"cursorColor": "#55bb76",
				"valueBalloonsEnabled": false,
				"cursorAlpha": 0,
				"valueLineAlpha": 0.5,
				"valueLineBalloonEnabled": true,
				"valueLineEnabled": true,
				"zoomable": false,
				"valueZoomable": true
			},
			"export": {
Mathias Schreiber's avatar
Mathias Schreiber committed
263
264
265
266
267
268
269
				"enabled": true,
				"divId": "exportContainer",
                "position": "bottom-right",
                "fileName": "typo3-support-times",
				"menu": [
				    "PNG","PDF", "SVG"
				]
Mathias Schreiber's avatar
Mathias Schreiber committed
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
			}
		});
        ';
        $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'],
Mathias Schreiber's avatar
Mathias Schreiber committed
357
                    'task' => 'Extended support (optional)'
Mathias Schreiber's avatar
Mathias Schreiber committed
358
359
360
361
362
363
364
                ];
            }
        }

        return $data;
    }

365
366
367
368
369
370
371
372
    /**
     * @return tslib_fe
     */
    protected function getFrontendController()
    {
        return $GLOBALS['TSFE'];
    }

Mathias Schreiber's avatar
Mathias Schreiber committed
373
}