TYPO3 CMS  TYPO3_7-6
RecyclerModuleController.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 
23 
28 {
32  protected $relativePath;
33 
37  public $perms_clause;
38 
42  protected $pageRecord = [];
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  if ($this->isAccessibleForCurrentUser) {
133  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
134  }
135 
136  $this->view->assign('title', $this->getLanguageService()->getLL('title'));
137  $this->view->assign('allowDelete', $this->allowDelete);
138  }
139 
146  protected function registerDocheaderButtons()
147  {
149  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
150  $currentRequest = $this->request;
151  $moduleName = $currentRequest->getPluginName();
152  $getVars = $this->request->getArguments();
153 
154  $extensionName = $currentRequest->getControllerExtensionName();
155  if (count($getVars) === 0) {
156  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
157  $getVars = ['id', 'M', $modulePrefix];
158  }
159  $shortcutButton = $buttonBar->makeShortcutButton()
160  ->setModuleName($moduleName)
161  ->setGetVariables($getVars);
162  $buttonBar->addButton($shortcutButton);
163 
164  $reloadButton = $buttonBar->makeLinkButton()
165  ->setHref('#')
166  ->setDataAttributes(['action' => 'reload'])
167  ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
168  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
169  $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
170  }
171 
177  protected function isCurrentUserAdmin()
178  {
179  return (bool)$this->getBackendUser()->user['admin'];
180  }
181 
187  protected function getJavaScriptConfiguration()
188  {
189  $configuration = [
190  'pagingSize' => $this->recordsPageLimit,
191  'showDepthMenu' => 1,
192  'startUid' => (int)GeneralUtility::_GP('id'),
193  'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
194  'deleteDisable' => !$this->allowDelete,
195  'depthSelection' => $this->getDataFromSession('depthSelection', 0),
196  'tableSelection' => $this->getDataFromSession('tableSelection', ''),
197  'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
198  ];
199  return $configuration;
200  }
201 
209  protected function getDataFromSession($identifier, $default = null)
210  {
211  $sessionData = &$this->getBackendUser()->uc['tx_recycler'];
212  if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
213  $data = $sessionData[$identifier];
214  } else {
215  $data = $default;
216  }
217  return $data;
218  }
219 
225  protected function getBackendUser()
226  {
227  return $GLOBALS['BE_USER'];
228  }
229 
235  protected function getDocumentTemplate()
236  {
237  return $GLOBALS['TBE_TEMPLATE'];
238  }
239 
245  protected function getLanguageService()
246  {
247  return $GLOBALS['LANG'];
248  }
249 }
static readPageAccess($id, $perms_clause)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']