[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Controller / RecyclerModuleController.php
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
17 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
18 use TYPO3\CMS\Backend\View\BackendTemplateView;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Type\Bitmask\Permission;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
23 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
24
25 /**
26 * Module 'Recycler' for the 'recycler' extension.
27 */
28 class RecyclerModuleController extends ActionController
29 {
30 /**
31 * @var string
32 */
33 protected $relativePath;
34
35 /**
36 * @var string
37 */
38 public $perms_clause;
39
40 /**
41 * @var array
42 */
43 protected $pageRecord = [];
44
45 /**
46 * @var bool
47 */
48 protected $isAccessibleForCurrentUser = false;
49
50 /**
51 * @var bool
52 */
53 protected $allowDelete = false;
54
55 /**
56 * @var int
57 */
58 protected $recordsPageLimit = 50;
59
60 /**
61 * @var int
62 */
63 protected $id;
64
65 /**
66 * @var BackendTemplateView
67 */
68 protected $view;
69
70 /**
71 * BackendTemplateView Container
72 *
73 * @var BackendTemplateView
74 */
75 protected $defaultViewObjectName = BackendTemplateView::class;
76
77 /**
78 * Initializes the Module
79 */
80 public function initializeAction()
81 {
82 $this->id = (int)GeneralUtility::_GP('id');
83 $backendUser = $this->getBackendUser();
84 $this->perms_clause = $backendUser->getPagePermsClause(Permission::PAGE_SHOW);
85 $this->pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
86 $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->getBackendUser()->isAdmin();
87
88 // don't access in workspace
89 if ($backendUser->workspace !== 0) {
90 $this->isAccessibleForCurrentUser = false;
91 }
92
93 // read configuration
94 $modTS = $backendUser->getTSConfig('mod.recycler');
95 if ($this->getBackendUser()->isAdmin()) {
96 $this->allowDelete = true;
97 } else {
98 $this->allowDelete = (bool)$modTS['properties']['allowDelete'];
99 }
100
101 if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
102 $this->recordsPageLimit = (int)$modTS['properties']['recordsPageLimit'];
103 }
104 }
105
106 /**
107 * Initialize the view
108 *
109 * @param ViewInterface $view The view
110 */
111 public function initializeView(ViewInterface $view)
112 {
113 /** @var BackendTemplateView $view */
114 parent::initializeView($view);
115 $this->registerDocheaderButtons();
116 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
117 }
118
119 /**
120 * Renders the content of the module.
121 */
122 public function indexAction()
123 {
124 // Integrate dynamic JavaScript such as configuration or lables:
125 $jsConfiguration = $this->getJavaScriptConfiguration();
126 $this->view->getModuleTemplate()->getPageRenderer()->addInlineSettingArray('Recycler', $jsConfiguration);
127 $this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
128 if ($this->isAccessibleForCurrentUser) {
129 $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
130 }
131
132 $this->view->assign('title', $this->getLanguageService()->getLL('title'));
133 $this->view->assign('allowDelete', $this->allowDelete);
134 }
135
136 /**
137 * Registers the Icons into the docheader
138 *
139 * @throws \InvalidArgumentException
140 */
141 protected function registerDocheaderButtons()
142 {
143 /** @var ButtonBar $buttonBar */
144 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
145 $currentRequest = $this->request;
146 $moduleName = $currentRequest->getPluginName();
147 $getVars = $this->request->getArguments();
148
149 $extensionName = $currentRequest->getControllerExtensionName();
150 if (count($getVars) === 0) {
151 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
152 $getVars = ['id', 'route', $modulePrefix];
153 }
154 $shortcutButton = $buttonBar->makeShortcutButton()
155 ->setModuleName($moduleName)
156 ->setGetVariables($getVars);
157 $buttonBar->addButton($shortcutButton);
158
159 $reloadButton = $buttonBar->makeLinkButton()
160 ->setHref('#')
161 ->setDataAttributes(['action' => 'reload'])
162 ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
163 ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
164 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
165 }
166
167 /**
168 * Gets the JavaScript configuration.
169 *
170 * @return array The JavaScript configuration
171 */
172 protected function getJavaScriptConfiguration()
173 {
174 $configuration = [
175 'pagingSize' => $this->recordsPageLimit,
176 'showDepthMenu' => 1,
177 'startUid' => (int)GeneralUtility::_GP('id'),
178 'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
179 'deleteDisable' => !$this->allowDelete,
180 'depthSelection' => $this->getDataFromSession('depthSelection', 0),
181 'tableSelection' => $this->getDataFromSession('tableSelection', ''),
182 'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
183 ];
184 return $configuration;
185 }
186
187 /**
188 * Gets data from the session of the current backend user.
189 *
190 * @param string $identifier The identifier to be used to get the data
191 * @param string $default The default date to be used if nothing was found in the session
192 * @return string The accordant data in the session of the current backend user
193 */
194 protected function getDataFromSession($identifier, $default = null)
195 {
196 $sessionData = &$this->getBackendUser()->uc['tx_recycler'];
197 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
198 $data = $sessionData[$identifier];
199 } else {
200 $data = $default;
201 }
202 return $data;
203 }
204
205 /**
206 * Returns the current BE user.
207 *
208 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
209 */
210 protected function getBackendUser()
211 {
212 return $GLOBALS['BE_USER'];
213 }
214
215 /**
216 * Returns an instance of DocumentTemplate
217 *
218 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
219 */
220 protected function getDocumentTemplate()
221 {
222 return $GLOBALS['TBE_TEMPLATE'];
223 }
224
225 /**
226 * Returns an instance of LanguageService
227 *
228 * @return \TYPO3\CMS\Core\Localization\LanguageService
229 */
230 protected function getLanguageService()
231 {
232 return $GLOBALS['LANG'];
233 }
234 }