[TASK] Reports module based on extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Controller / ReportController.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Georg Ringer <typo3@ringerge.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Reports controller
27 *
28 * @package TYPO3
29 * @subpackage tx_reports
30 */
31 class Tx_Reports_Controller_ReportController extends Tx_Extbase_MVC_Controller_ActionController {
32
33
34 /**
35 * Redirect to the saved report
36 *
37 * @return void
38 */
39 public function initializeAction() {
40 $vars = t3lib_div::_GET('tx_reports_tools_reportstxreportsm1');
41
42 if (!isset($vars['redirect']) && $vars['action'] !== 'index' && !isset($vars['extension']) && is_array($GLOBALS['BE_USER']->uc['reports']['selection'])) {
43 $previousSelection = $GLOBALS['BE_USER']->uc['reports']['selection'];
44 if (!empty($previousSelection['extension']) && !empty($previousSelection['report'])) {
45 $this->redirect('detail', 'Report', NULL, array('extension' => $previousSelection['extension'], 'report' => $previousSelection['report'], 'redirect' => 1));
46 } else {
47 $this->redirect('index');
48 }
49 }
50 }
51
52 /**
53 * Overview
54 *
55 * @return void
56 */
57 public function indexAction() {
58 $this->view->assignMultiple(array(
59 'reports' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'],
60 'menu' => $this->getMenu()
61 ));
62 $this->saveState();
63 }
64
65 /**
66 * Display a single report
67 *
68 * @param string $extension Extension
69 * @param string $report Report
70 * @return void
71 */
72 public function detailAction($extension, $report) {
73 $content = $error = '';
74 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'];
75
76 $reportInstance = t3lib_div::makeInstance($reportClass, $this);
77
78 if ($reportInstance instanceof tx_reports_Report) {
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
85 $this->view->assignMultiple(array(
86 'content' => $content,
87 'error' => $error,
88 'report' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report],
89 'menu' => $this->getMenu()
90 ));
91 }
92
93 /**
94 * Generate the menu
95 *
96 * @return array Menu items
97 */
98 protected function getMenu() {
99 $reportsMenuItems = array();
100
101 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
102 foreach ($reports as $reportName => $report) {
103 $reportsMenuItems[] = array(
104 'title' => $GLOBALS['LANG']->sL($report['title']),
105 'extension' => $extKey,
106 'report' => $reportName
107 );
108 }
109 }
110 return $reportsMenuItems;
111 }
112
113 /**
114 * Save the selected report
115 *
116 * @param string $extension Extension name
117 * @param string $report Report name
118 * @return void
119 */
120 protected function saveState($extension = '', $report = '') {
121 $GLOBALS['BE_USER']->uc['reports']['selection'] = array('extension' => $extension, 'report' => $report);
122 $GLOBALS['BE_USER']->writeUC();
123 }
124
125 }
126
127 ?>