[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Controller / ReportController.php
1 <?php
2 namespace TYPO3\CMS\Reports\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Reports controller
18 *
19 */
20 class ReportController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
21
22 /**
23 * Redirect to the saved report
24 *
25 * @return void
26 */
27 public function initializeAction() {
28 $vars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('tx_reports_system_reportstxreportsm1');
29 if (!isset($vars['redirect']) && $vars['action'] !== 'index' && !isset($vars['extension']) && is_array($GLOBALS['BE_USER']->uc['reports']['selection'])) {
30 $previousSelection = $GLOBALS['BE_USER']->uc['reports']['selection'];
31 if (!empty($previousSelection['extension']) && !empty($previousSelection['report'])) {
32 $this->redirect('detail', 'Report', NULL, array('extension' => $previousSelection['extension'], 'report' => $previousSelection['report'], 'redirect' => 1));
33 } else {
34 $this->redirect('index');
35 }
36 }
37 }
38
39 /**
40 * Overview
41 *
42 * @return void
43 */
44 public function indexAction() {
45 $this->view->assignMultiple(array(
46 'reports' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'],
47 'menu' => $this->getMenu()
48 ));
49 $this->saveState();
50 }
51
52 /**
53 * Display a single report
54 *
55 * @param string $extension Extension
56 * @param string $report Report
57 * @return void
58 */
59 public function detailAction($extension, $report) {
60 $content = ($error = '');
61 $reportClass = NULL;
62 if (
63 isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
64 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
65 && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
66 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
67 && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'])
68 ) {
69 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'];
70 }
71
72 // If extension has been uninstalled/removed redirect to index
73 if ($reportClass === NULL) {
74 $this->redirect('index');
75 }
76
77 $reportInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($reportClass, $this);
78 if ($reportInstance instanceof \TYPO3\CMS\Reports\ReportInterface) {
79 $content = $reportInstance->getReport();
80 $this->saveState($extension, $report);
81 } else {
82 $error = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
83 }
84 $this->view->assignMultiple(array(
85 'content' => $content,
86 'error' => $error,
87 'report' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report],
88 'menu' => $this->getMenu()
89 ));
90 }
91
92 /**
93 * Generate the menu
94 *
95 * @return array Menu items
96 */
97 protected function getMenu() {
98 $reportsMenuItems = array();
99 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
100 foreach ($reports as $reportName => $report) {
101 $reportsMenuItems[] = array(
102 'title' => $GLOBALS['LANG']->sL($report['title']),
103 'extension' => $extKey,
104 'report' => $reportName
105 );
106 }
107 }
108 return $reportsMenuItems;
109 }
110
111 /**
112 * Save the selected report
113 *
114 * @param string $extension Extension name
115 * @param string $report Report name
116 * @return void
117 */
118 protected function saveState($extension = '', $report = '') {
119 $GLOBALS['BE_USER']->uc['reports']['selection'] = array('extension' => $extension, 'report' => $report);
120 $GLOBALS['BE_USER']->writeUC();
121 }
122
123 }