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