TYPO3 CMS  TYPO3_7-6
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 
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(
94  'reports', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']
95  );
96  $this->saveState();
97  }
98 
107  public function detailAction($extension, $report)
108  {
109  $content = ($error = '');
110  $reportClass = null;
111  if (
112  isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
113  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension])
114  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
115  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report])
116  && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'])
117  ) {
118  $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report]['report'];
119  }
120 
121  // If extension has been uninstalled/removed redirect to index
122  if ($reportClass === null) {
123  $this->redirect('index');
124  }
125 
126  $reportInstance = GeneralUtility::makeInstance($reportClass, $this);
127  if ($reportInstance instanceof ReportInterface) {
128  $content = $reportInstance->getReport();
129  $this->saveState($extension, $report);
130  } else {
131  $error = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
132  }
133  $this->view->assignMultiple([
134  'content' => $content,
135  'error' => $error,
136  'report' => $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extension][$report],
137  ]);
138  }
139 
143  protected function generateMenu()
144  {
145  $lang = $this->getLanguageService();
146  $lang->includeLLFile('EXT:reports/Resources/Private/Language/locallang.xlf');
147  $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
148  $menu->setIdentifier('WebFuncJumpMenu');
149  $menuItem = $menu
150  ->makeMenuItem()
151  ->setHref(
152  $this->uriBuilder->reset()->uriFor('index', null, 'Report')
153  )
154  ->setTitle($lang->getLL('reports_overview'));
155  $menu->addMenuItem($menuItem);
156  $this->shortcutName = $lang->getLL('reports_overview');
157  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
158  foreach ($reports as $reportName => $report) {
159  $menuItem = $menu
160  ->makeMenuItem()
161  ->setHref($this->uriBuilder->reset()->uriFor('detail',
162  ['extension' => $extKey, 'report' => $reportName], 'Report'))
163  ->setTitle($this->getLanguageService()->sL($report['title']));
164  if ($this->arguments->hasArgument('extension') && $this->arguments->hasArgument('report')) {
165  if ($this->arguments->getArgument('extension')->getValue() === $extKey && $this->arguments->getArgument('report')->getValue() === $reportName) {
166  $menuItem->setActive(true);
167  $this->shortcutName = $menuItem->getTitle();
168  }
169  }
170  $menu->addMenuItem($menuItem);
171  }
172  }
173  $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
174  }
175 
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  $GLOBALS['BE_USER']->uc['reports']['selection'] = [
208  'extension' => $extension,
209  'report' => $report,
210  ];
211  $GLOBALS['BE_USER']->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']