TYPO3  7.6
ReportController.php
Go to the documentation of this file.
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  */
23 
28 {
29 
33  protected $view;
34 
40  protected $defaultViewObjectName = BackendTemplateView::class;
41 
47  protected $shortcutName;
48 
54  public function initializeAction()
55  {
56  $vars = GeneralUtility::_GET('tx_reports_system_reportstxreportsm1');
57  if (!isset($vars['redirect']) && $vars['action'] !== 'index' && !isset($vars['extension']) && is_array($GLOBALS['BE_USER']->uc['reports']['selection'])) {
58  $previousSelection = $GLOBALS['BE_USER']->uc['reports']['selection'];
59  if (!empty($previousSelection['extension']) && !empty($previousSelection['report'])) {
60  $this->redirect('detail', 'Report', null, array(
61  'extension' => $previousSelection['extension'],
62  'report' => $previousSelection['report'],
63  'redirect' => 1,
64  ));
65  } else {
66  $this->redirect('index');
67  }
68  }
69  }
70 
78  protected function initializeView(ViewInterface $view)
79  {
81  parent::initializeView($view);
82  $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
83  $this->generateMenu();
84  $this->generateButtons();
85  }
86 
92  public function indexAction()
93  {
94  $this->view->assign(
95  'reports', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']
96  );
97  $this->saveState();
98  }
99 
108  public function detailAction($extension, $report)
109  {
110  $content = ($error = '');
111  $reportClass = null;
112  if (
113  isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
114  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
115  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
116  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
117  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'])
118  ) {
119  $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'];
120  }
121 
122  // If extension has been uninstalled/removed redirect to index
123  if ($reportClass === null) {
124  $this->redirect('index');
125  }
126 
127  $reportInstance = GeneralUtility::makeInstance($reportClass, $this);
128  if ($reportInstance instanceof ReportInterface) {
129  $content = $reportInstance->getReport();
130  $this->saveState($extension, $report);
131  } else {
132  $error = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
133  }
134  $this->view->assignMultiple(array(
135  'content' => $content,
136  'error' => $error,
137  'report' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report],
138  ));
139  }
140 
144  protected function generateMenu()
145  {
146  $lang = $this->getLanguageService();
147  $lang->includeLLFile('EXT:reports/Resources/Private/Language/locallang.xlf');
148  $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
149  $menu->setIdentifier('WebFuncJumpMenu');
150  $menuItem = $menu
151  ->makeMenuItem()
152  ->setHref(
153  $this->uriBuilder->reset()->uriFor('index', null, 'Report')
154  )
155  ->setTitle($lang->getLL('reports_overview'));
156  $menu->addMenuItem($menuItem);
157  $this->shortcutName = $lang->getLL('reports_overview');
158  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
159  foreach ($reports as $reportName => $report) {
160  $menuItem = $menu
161  ->makeMenuItem()
162  ->setHref($this->uriBuilder->reset()->uriFor('detail',
163  array('extension' => $extKey, 'report' => $reportName), 'Report'))
164  ->setTitle($this->getLanguageService()->sL($report['title']));
165  if ($this->arguments->hasArgument('extension') && $this->arguments->hasArgument('report')) {
166  if ($this->arguments->getArgument('extension')->getValue() === $extKey && $this->arguments->getArgument('report')->getValue() === $reportName) {
167  $menuItem->setActive(true);
168  $this->shortcutName = $menuItem->getTitle();
169  }
170  }
171  $menu->addMenuItem($menuItem);
172  }
173  }
174  $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
175  }
176 
180  protected function generateButtons()
181  {
182  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
183  $moduleName = $this->request->getPluginName();
184  $getVars = $this->request->hasArgument('getVars') ? $this->request->getArgument('getVars') : [];
185  $setVars = $this->request->hasArgument('setVars') ? $this->request->getArgument('setVars') : [];
186  if (count($getVars) === 0) {
187  $modulePrefix = strtolower('tx_' . $this->request->getControllerExtensionName() . '_' . $moduleName);
188  $getVars = array('id', 'M', $modulePrefix);
189  }
190  $shortcutButton = $buttonBar->makeShortcutButton()
191  ->setModuleName($moduleName)
192  ->setGetVariables($getVars)
193  ->setDisplayName($this->shortcutName)
194  ->setSetVariables($setVars);
195  $buttonBar->addButton($shortcutButton);
196  }
197 
206  protected function saveState($extension = '', $report = '')
207  {
208  $GLOBALS['BE_USER']->uc['reports']['selection'] = array(
209  'extension' => $extension,
210  'report' => $report,
211  );
212  $GLOBALS['BE_USER']->writeUC();
213  }
214 
218  protected function getBackendUser()
219  {
220  return $GLOBALS['BE_USER'];
221  }
222 
226  protected function getLanguageService()
227  {
228  return $GLOBALS['LANG'];
229  }
230 }