TYPO3 CMS  TYPO3_8-7
TaskModuleController.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  */
16 
27 
32 {
36  protected $pageinfo;
37 
43  protected $moduleTemplate;
44 
50  protected $moduleName = 'user_task';
51 
55  public function __construct()
56  {
57  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
58  $this->getLanguageService()->includeLLFile('EXT:taskcenter/Resources/Private/Language/locallang_task.xlf');
59  $this->MCONF = [
60  'name' => $this->moduleName
61  ];
62  parent::init();
63  }
64 
68  public function menuConfig()
69  {
70  $this->MOD_MENU = ['mode' => []];
71  $this->MOD_MENU['mode']['information'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_overview');
72  $this->MOD_MENU['mode']['tasks'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_tasks');
73  /* Copied from parent::menuConfig, because parent is hardcoded to menu.function,
74  * however menu.function is already used for the individual tasks.
75  * Therefore we use menu.mode here.
76  */
77  // Page/be_user TSconfig settings and blinding of menu-items
78  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
79  $this->MOD_MENU['mode'] = $this->mergeExternalItems($this->MCONF['name'], 'mode', $this->MOD_MENU['mode']);
80  $this->MOD_MENU['mode'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['mode'], 'menu.mode');
81  parent::menuConfig();
82  }
83 
89  protected function generateMenu()
90  {
91  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
92  $menu->setIdentifier('WebFuncJumpMenu');
93  foreach ($this->MOD_MENU['mode'] as $controller => $title) {
94  $item = $menu
95  ->makeMenuItem()
96  ->setHref(
97  BackendUtility::getModuleUrl(
98  $this->moduleName,
99  [
100  'id' => $this->id,
101  'SET' => [
102  'mode' => $controller
103  ]
104  ]
105  )
106  )
107  ->setTitle($title);
108  if ($controller === $this->MOD_SETTINGS['mode']) {
109  $item->setActive(true);
110  }
111  $menu->addMenuItem($item);
112  }
113  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
114  }
115 
124  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
125  {
126  $GLOBALS['SOBE'] = $this;
127  $this->main();
128 
129  $this->moduleTemplate->setContent($this->content);
130 
131  $response->getBody()->write($this->moduleTemplate->renderContent());
132  return $response;
133  }
134 
139  public function main()
140  {
141  $this->getButtons();
142  $this->generateMenu();
143  $this->moduleTemplate->addJavaScriptCode(
144  'TaskCenterInlineJavascript',
145  'if (top.fsMod) { top.fsMod.recentIds["web"] = 0; }'
146  );
147 
148  // Render content depending on the mode
149  $mode = (string)$this->MOD_SETTINGS['mode'];
150  if ($mode === 'information') {
151  $this->renderInformationContent();
152  } else {
153  $this->renderModuleContent();
154  }
155  // Renders the module page
156  $this->moduleTemplate->setTitle($this->getLanguageService()->getLL('title'));
157  }
158 
164  public function printContent()
165  {
167  echo $this->content;
168  }
169 
173  protected function renderModuleContent()
174  {
175  $chosenTask = (string)$this->MOD_SETTINGS['function'];
176  // Render the taskcenter task as default
177  if (empty($chosenTask) || $chosenTask === 'index') {
178  $chosenTask = 'taskcenter.tasks';
179  }
180  // Render the task
181  $actionContent = '';
182  $flashMessage = null;
183  list($extKey, $taskClass) = explode('.', $chosenTask, 2);
184  if (class_exists($taskClass)) {
185  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
186  if ($taskInstance instanceof TaskInterface) {
187  // Check if the task is restricted to admins only
188  if ($this->checkAccess($extKey, $taskClass)) {
189  $actionContent .= $taskInstance->getTask();
190  } else {
191  $flashMessage = GeneralUtility::makeInstance(
192  FlashMessage::class,
193  $this->getLanguageService()->getLL('error-access'),
194  $this->getLanguageService()->getLL('error_header'),
196  );
197  }
198  } else {
199  // Error if the task is not an instance of \TYPO3\CMS\Taskcenter\TaskInterface
200  $flashMessage = GeneralUtility::makeInstance(
201  FlashMessage::class,
202  sprintf($this->getLanguageService()->getLL('error_no-instance'), $taskClass, TaskInterface::class),
203  $this->getLanguageService()->getLL('error_header'),
205  );
206  }
207  } else {
208  $flashMessage = GeneralUtility::makeInstance(
209  FlashMessage::class,
210  $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_labels_tabdescr'),
211  $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
213  );
214  }
215 
216  if ($flashMessage) {
218  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
220  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
221  $defaultFlashMessageQueue->enqueue($flashMessage);
222  }
223 
224  $assigns = [];
225  $assigns['reports'] = $this->indexAction();
226  $assigns['taskClass'] = strtolower(str_replace('\\', '-', htmlspecialchars(($extKey . '-' . $taskClass))));
227  $assigns['actionContent'] = $actionContent;
228 
229  // Rendering of the output via fluid
230  $view = GeneralUtility::makeInstance(StandaloneView::class);
231  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
232  'EXT:taskcenter/Resources/Private/Templates/ModuleContent.html'
233  ));
234  $view->assignMultiple($assigns);
235  $this->content .= $view->render();
236  }
237 
241  protected function renderInformationContent()
242  {
243  $assigns = [];
244  $assigns['LLPrefix'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:';
245  $assigns['LLPrefixMod'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:';
246  $assigns['LLPrefixTask'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang_task.xlf:';
247  $assigns['admin'] = $this->getBackendUser()->isAdmin();
248 
249  // Rendering of the output via fluid
250  $view = GeneralUtility::makeInstance(StandaloneView::class);
251  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:taskcenter/Resources/Private/Templates')]);
252  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:taskcenter/Resources/Private/Partials')]);
253  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
254  'EXT:taskcenter/Resources/Private/Templates/InformationContent.html'
255  ));
256  $view->assignMultiple($assigns);
257  $this->content .= $view->render();
258  }
259 
267  public function description($title, $description = '')
268  {
269  $descriptionView = GeneralUtility::makeInstance(StandaloneView::class);
270  $descriptionView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
271  'EXT:taskcenter/Resources/Private/Partials/Description.html'
272  ));
273  $descriptionView->assign('title', $title);
274  $descriptionView->assign('description', $description);
275  return $descriptionView->render();
276  }
277 
293  public function renderListMenu($items, $mainMenu = false)
294  {
295  $assigns = [];
296  $assigns['mainMenu'] = $mainMenu;
297 
298  // Change the sorting of items to the user's one
299  if ($mainMenu) {
300  $userSorting = unserialize($this->getBackendUser()->uc['taskcenter']['sorting']);
301  if (is_array($userSorting)) {
302  $newSorting = [];
303  foreach ($userSorting as $item) {
304  if (isset($items[$item])) {
305  $newSorting[] = $items[$item];
306  unset($items[$item]);
307  }
308  }
309  $items = $newSorting + $items;
310  }
311  }
312  if (is_array($items) && !empty($items)) {
313  foreach ($items as $itemKey => &$item) {
314  // Check for custom icon
315  if (!empty($item['icon'])) {
316  if (strpos($item['icon'], '<img ') === false) {
317  $iconFile = GeneralUtility::getFileAbsFileName($item['icon']);
318  if (@is_file($iconFile)) {
319  $item['iconFile'] = PathUtility::getAbsoluteWebPath($iconFile);
320  }
321  }
322  }
323  $id = $this->getUniqueKey($item['uid']);
324  $contentId = strtolower(str_replace('\\', '-', $id));
325  $item['uniqueKey'] = $id;
326  $item['contentId'] = $contentId;
327  // Collapsed & expanded menu items
328  if (isset($this->getBackendUser()->uc['taskcenter']['states'][$id]) && $this->getBackendUser()->uc['taskcenter']['states'][$id]) {
329  $item['ariaExpanded'] = 'true';
330  $item['collapseIcon'] = 'actions-view-list-expand';
331  $item['collapsed'] = '';
332  } else {
333  $item['ariaExpanded'] = 'false';
334  $item['collapseIcon'] = 'actions-view-list-collapse';
335  $item['collapsed'] = 'in';
336  }
337  // Active menu item
338  $panelState = (string)$this->MOD_SETTINGS['function'] == $item['uid'] ? 'panel-active' : 'panel-default';
339  $item['panelState'] = $panelState;
340  }
341  }
342  $assigns['items'] = $items;
343 
344  // Rendering of the output via fluid
345  $view = GeneralUtility::makeInstance(StandaloneView::class);
346  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
347  'EXT:taskcenter/Resources/Private/Templates/ListMenu.html'
348  ));
349  $view->assignMultiple($assigns);
350  return $view->render();
351  }
352 
358  protected function indexAction()
359  {
360  $content = '';
361  $tasks = [];
362  $defaultIcon = 'EXT:taskcenter/Resources/Public/Icons/module-taskcenter.svg';
363  // Render the tasks only if there are any available
364  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && !empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'])) {
365  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
366  foreach ($extensionReports as $taskClass => $task) {
367  if (!$this->checkAccess($extKey, $taskClass)) {
368  continue;
369  }
370  $link = BackendUtility::getModuleUrl('user_task') . '&SET[function]=' . $extKey . '.' . $taskClass;
371  $taskTitle = $this->getLanguageService()->sL($task['title']);
372  $taskDescriptionHtml = '';
373 
374  if (class_exists($taskClass)) {
375  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
376  if ($taskInstance instanceof TaskInterface) {
377  $taskDescriptionHtml = $taskInstance->getOverview();
378  }
379  }
380  // Generate an array of all tasks
381  $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
382  $tasks[$uniqueKey] = [
383  'title' => $taskTitle,
384  'descriptionHtml' => $taskDescriptionHtml,
385  'description' => $this->getLanguageService()->sL($task['description']),
386  'icon' => !empty($task['icon']) ? $task['icon'] : $defaultIcon,
387  'link' => $link,
388  'uid' => $extKey . '.' . $taskClass
389  ];
390  }
391  }
392  $content .= $this->renderListMenu($tasks, true);
393  } else {
394  $flashMessage = GeneralUtility::makeInstance(
395  FlashMessage::class,
396  $this->getLanguageService()->getLL('no-tasks'),
397  '',
399  );
401  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
403  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
404  $defaultFlashMessageQueue->enqueue($flashMessage);
405  }
406  return $content;
407  }
408 
413  protected function getButtons()
414  {
415  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
416 
417  // Shortcut
418  $shortcutButton = $buttonBar->makeShortcutButton()
419  ->setModuleName($this->moduleName)
420  ->setSetVariables(['function']);
421  $buttonBar->addButton($shortcutButton);
422  }
423 
434  protected function checkAccess($extKey, $taskClass)
435  {
436  // Check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
437  $tsConfig = $this->getBackendUser()->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
438  if (isset($tsConfig['value']) && (int)$tsConfig['value'] === 0) {
439  return false;
440  }
441  // Admins are always allowed
442  if ($this->getBackendUser()->isAdmin()) {
443  return true;
444  }
445  // Check if task is restricted to admins
446  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin'] === 1) {
447  return false;
448  }
449  return true;
450  }
451 
458  public function urlInIframe($url)
459  {
460  $urlView = GeneralUtility::makeInstance(StandaloneView::class);
461  $urlView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
462  'EXT:taskcenter/Resources/Private/Partials/UrlInIframe.html'
463  ));
464  $urlView->assign('url', $url);
465  return $urlView->render();
466  }
467 
475  protected function getUniqueKey($string)
476  {
477  $search = ['.', '_'];
478  $replace = ['-', ''];
479  return str_replace($search, $replace, $string);
480  }
481 
487  protected function getBackendUser()
488  {
489  return $GLOBALS['BE_USER'];
490  }
491 
497  protected function getLanguageService()
498  {
499  return $GLOBALS['LANG'];
500  }
501 
505  public function getModuleTemplate()
506  {
507  return $this->moduleTemplate;
508  }
509 }
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40
mergeExternalItems($modName, $menuKey, $menuArr)
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static unsetMenuItems($modTSconfig, $itemArray, $TSref)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']