7a757db4bac383bbfa9aad4a3814eb7ffe857264
[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\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
22 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
23
24 /**
25 * Module 'Recycler' for the 'recycler' extension.
26 */
27 class RecyclerModuleController extends ActionController
28 {
29 /**
30 * @var string
31 */
32 protected $relativePath;
33
34 /**
35 * @var string
36 */
37 public $perms_clause;
38
39 /**
40 * @var array
41 */
42 protected $pageRecord = array();
43
44 /**
45 * @var bool
46 */
47 protected $isAccessibleForCurrentUser = false;
48
49 /**
50 * @var bool
51 */
52 protected $allowDelete = false;
53
54 /**
55 * @var int
56 */
57 protected $recordsPageLimit = 50;
58
59 /**
60 * @var int
61 */
62 protected $id;
63
64 /**
65 * @var BackendTemplateView
66 */
67 protected $view;
68
69 /**
70 * BackendTemplateView Container
71 *
72 * @var BackendTemplateView
73 */
74 protected $defaultViewObjectName = BackendTemplateView::class;
75
76 /**
77 * Initializes the Module
78 *
79 * @return void
80 */
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
107 /**
108 * Initialize the view
109 *
110 * @param ViewInterface $view The view
111 * @return void
112 */
113 public function initializeView(ViewInterface $view)
114 {
115 /** @var BackendTemplateView $view */
116 parent::initializeView($view);
117 $this->registerDocheaderButtons();
118 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
119 }
120
121 /**
122 * Renders the content of the module.
123 *
124 * @return void
125 */
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
138 /**
139 * Registers the Icons into the docheader
140 *
141 * @return void
142 * @throws \InvalidArgumentException
143 */
144 protected function registerDocheaderButtons()
145 {
146 /** @var ButtonBar $buttonBar */
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
170 /**
171 * Determines whether the current user is admin.
172 *
173 * @return bool Whether the current user is admin
174 */
175 protected function isCurrentUserAdmin()
176 {
177 return (bool)$this->getBackendUser()->user['admin'];
178 }
179
180 /**
181 * Gets the JavaScript configuration for the Ext JS interface.
182 *
183 * @return array The JavaScript configuration
184 */
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
200 /**
201 * Gets data from the session of the current backend user.
202 *
203 * @param string $identifier The identifier to be used to get the data
204 * @param string $default The default date to be used if nothing was found in the session
205 * @return string The accordant data in the session of the current backend user
206 */
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
218 /**
219 * Returns the current BE user.
220 *
221 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
222 */
223 protected function getBackendUser()
224 {
225 return $GLOBALS['BE_USER'];
226 }
227
228 /**
229 * Returns an instance of DocumentTemplate
230 *
231 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
232 */
233 protected function getDocumentTemplate()
234 {
235 return $GLOBALS['TBE_TEMPLATE'];
236 }
237
238 /**
239 * Returns an instance of LanguageService
240 *
241 * @return \TYPO3\CMS\Lang\LanguageService
242 */
243 protected function getLanguageService()
244 {
245 return $GLOBALS['LANG'];
246 }
247 }