TYPO3  7.6
RecyclerModuleController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recycler\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  */
16 
23 
28 {
32  protected $relativePath;
33 
37  public $perms_clause;
38 
42  protected $pageRecord = array();
43 
47  protected $isAccessibleForCurrentUser = false;
48 
52  protected $allowDelete = false;
53 
57  protected $recordsPageLimit = 50;
58 
62  protected $id;
63 
67  protected $view;
68 
74  protected $defaultViewObjectName = BackendTemplateView::class;
75 
81  public function initializeAction()
82  {
83  $this->id = (int)GeneralUtility::_GP('id');
84  $backendUser = $this->getBackendUser();
85  $this->perms_clause = $backendUser->getPagePermsClause(1);
86  $this->pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
87  $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin();
88 
89  // don't access in workspace
90  if ($backendUser->workspace !== 0) {
91  $this->isAccessibleForCurrentUser = false;
92  }
93 
94  // read configuration
95  $modTS = $backendUser->getTSConfig('mod.recycler');
96  if ($this->isCurrentUserAdmin()) {
97  $this->allowDelete = true;
98  } else {
99  $this->allowDelete = (bool)$modTS['properties']['allowDelete'];
100  }
101 
102  if (isset($modTS['properties']['recordsPageLimit']) && intval($modTS['properties']['recordsPageLimit']) > 0) {
103  $this->recordsPageLimit = intval($modTS['properties']['recordsPageLimit']);
104  }
105  }
106 
113  public function initializeView(ViewInterface $view)
114  {
116  parent::initializeView($view);
117  $this->registerDocheaderButtons();
118  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
119  }
120 
126  public function indexAction()
127  {
128  // Integrate dynamic JavaScript such as configuration or lables:
129  $jsConfiguration = $this->getJavaScriptConfiguration();
130  $this->view->getModuleTemplate()->getPageRenderer()->addInlineSettingArray('Recycler', $jsConfiguration);
131  $this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
132  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
133 
134  $this->view->assign('title', $this->getLanguageService()->getLL('title'));
135  $this->view->assign('allowDelete', $this->allowDelete);
136  }
137 
144  protected function registerDocheaderButtons()
145  {
147  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
148  $currentRequest = $this->request;
149  $moduleName = $currentRequest->getPluginName();
150  $getVars = $this->request->getArguments();
151 
152  $extensionName = $currentRequest->getControllerExtensionName();
153  if (count($getVars) === 0) {
154  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
155  $getVars = array('id', 'M', $modulePrefix);
156  }
157  $shortcutButton = $buttonBar->makeShortcutButton()
158  ->setModuleName($moduleName)
159  ->setGetVariables($getVars);
160  $buttonBar->addButton($shortcutButton);
161 
162  $reloadButton = $buttonBar->makeLinkButton()
163  ->setHref('#')
164  ->setDataAttributes(['action' => 'reload'])
165  ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload', true))
166  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
167  $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_LEFT);
168  }
169 
175  protected function isCurrentUserAdmin()
176  {
177  return (bool)$this->getBackendUser()->user['admin'];
178  }
179 
185  protected function getJavaScriptConfiguration()
186  {
187  $configuration = array(
188  'pagingSize' => $this->recordsPageLimit,
189  'showDepthMenu' => 1,
190  'startUid' => (int)GeneralUtility::_GP('id'),
191  'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
192  'deleteDisable' => !$this->allowDelete,
193  'depthSelection' => $this->getDataFromSession('depthSelection', 0),
194  'tableSelection' => $this->getDataFromSession('tableSelection', ''),
195  'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
196  );
197  return $configuration;
198  }
199 
207  protected function getDataFromSession($identifier, $default = null)
208  {
209  $sessionData = &$this->getBackendUser()->uc['tx_recycler'];
210  if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
211  $data = $sessionData[$identifier];
212  } else {
213  $data = $default;
214  }
215  return $data;
216  }
217 
223  protected function getBackendUser()
224  {
225  return $GLOBALS['BE_USER'];
226  }
227 
233  protected function getDocumentTemplate()
234  {
235  return $GLOBALS['TBE_TEMPLATE'];
236  }
237 
243  protected function getLanguageService()
244  {
245  return $GLOBALS['LANG'];
246  }
247 }