TYPO3 CMS  TYPO3_8-7
ReportController.php
Go to the documentation of this file.
1 <?php
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 
51  public function initializeAction()
52  {
53  $vars = GeneralUtility::_GET('tx_reports_system_reportstxreportsm1');
54  if (!isset($vars['redirect']) && $vars['action'] !== 'index' && !isset($vars['extension']) && is_array($GLOBALS['BE_USER']->uc['reports']['selection'])) {
55  $previousSelection = $GLOBALS['BE_USER']->uc['reports']['selection'];
56  if (!empty($previousSelection['extension']) && !empty($previousSelection['report'])) {
57  $this->redirect('detail', 'Report', null, [
58  'extension' => $previousSelection['extension'],
59  'report' => $previousSelection['report'],
60  'redirect' => 1,
61  ]);
62  } else {
63  $this->redirect('index');
64  }
65  }
66  }
67 
73  protected function initializeView(ViewInterface $view)
74  {
76  parent::initializeView($view);
77  $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
78  $this->generateMenu();
79  $this->generateButtons();
80  }
81 
85  public function indexAction()
86  {
87  $this->view->assign('reports', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']);
88  $this->saveState();
89  }
90 
97  public function detailAction($extension, $report)
98  {
99  $content = ($error = '');
100  $reportClass = null;
101  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
102  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
103  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
104  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
105  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'])
106  ) {
107  $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'];
108  }
109 
110  // If extension has been uninstalled/removed redirect to index
111  if ($reportClass === null) {
112  $this->redirect('index');
113  }
114 
115  $reportInstance = GeneralUtility::makeInstance($reportClass, $this);
116  if ($reportInstance instanceof ReportInterface) {
117  $content = $reportInstance->getReport();
118  $this->saveState($extension, $report);
119  } else {
120  $error = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
121  }
122  $this->view->assignMultiple([
123  'content' => $content,
124  'error' => $error,
125  'report' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report],
126  ]);
127  }
128 
132  protected function generateMenu()
133  {
134  $lang = $this->getLanguageService();
135  $lang->includeLLFile('EXT:reports/Resources/Private/Language/locallang.xlf');
136  $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
137  $menu->setIdentifier('WebFuncJumpMenu');
138  $menuItem = $menu
139  ->makeMenuItem()
140  ->setHref(
141  $this->uriBuilder->reset()->uriFor('index', null, 'Report')
142  )
143  ->setTitle($lang->getLL('reports_overview'));
144  $menu->addMenuItem($menuItem);
145  $this->shortcutName = $lang->getLL('reports_overview');
146  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
147  foreach ($reports as $reportName => $report) {
148  $menuItem = $menu
149  ->makeMenuItem()
150  ->setHref($this->uriBuilder->reset()->uriFor('detail', ['extension' => $extKey, 'report' => $reportName], 'Report'))
151  ->setTitle($this->getLanguageService()->sL($report['title']));
152  if ($this->arguments->hasArgument('extension') && $this->arguments->hasArgument('report')) {
153  if ($this->arguments->getArgument('extension')->getValue() === $extKey && $this->arguments->getArgument('report')->getValue() === $reportName) {
154  $menuItem->setActive(true);
155  $this->shortcutName = $menuItem->getTitle();
156  }
157  }
158  $menu->addMenuItem($menuItem);
159  }
160  }
161  $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
162  }
163 
167  protected function generateButtons()
168  {
169  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
170  $moduleName = $this->request->getPluginName();
171  $getVars = $this->request->hasArgument('getVars') ? $this->request->getArgument('getVars') : [];
172  $setVars = $this->request->hasArgument('setVars') ? $this->request->getArgument('setVars') : [];
173  if (count($getVars) === 0) {
174  $modulePrefix = strtolower('tx_' . $this->request->getControllerExtensionName() . '_' . $moduleName);
175  $getVars = ['id', 'M', $modulePrefix];
176  }
177  $shortcutButton = $buttonBar->makeShortcutButton()
178  ->setModuleName($moduleName)
179  ->setGetVariables($getVars)
180  ->setDisplayName($this->shortcutName)
181  ->setSetVariables($setVars);
182  $buttonBar->addButton($shortcutButton);
183  }
184 
191  protected function saveState($extension = '', $report = '')
192  {
193  $this->getBackendUser()->uc['reports']['selection'] = [
194  'extension' => $extension,
195  'report' => $report,
196  ];
197  $this->getBackendUser()->writeUC();
198  }
199 
203  protected function getBackendUser()
204  {
205  return $GLOBALS['BE_USER'];
206  }
207 
211  protected function getLanguageService()
212  {
213  return $GLOBALS['LANG'];
214  }
215 }
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']