[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / ReviewController.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\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\Core\Utility\GeneralUtility;
18
19 /**
20 * Review controller.
21 *
22 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
23 */
24 class ReviewController extends \TYPO3\CMS\Workspaces\Controller\AbstractController {
25
26 /**
27 * Renders the review module user dependent with all workspaces.
28 * The module will show all records of one workspace.
29 *
30 * @return void
31 */
32 public function indexAction() {
33 $wsService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
34 $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
35 $this->view->assign('showAllWorkspaceTab', TRUE);
36 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
37 $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
38 $wsList = $wsService->getAvailableWorkspaces();
39 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
40 $performWorkspaceSwitch = FALSE;
41 // Only admins see multiple tabs, we decided to use it this
42 // way for usability reasons. Regular users might be confused
43 // by switching workspaces with the tabs in a module.
44 if (!$GLOBALS['BE_USER']->isAdmin()) {
45 $wsCur = array($activeWorkspace => TRUE);
46 $wsList = array_intersect_key($wsList, $wsCur);
47 } else {
48 if (strlen(GeneralUtility::_GP('workspace'))) {
49 $switchWs = (int)GeneralUtility::_GP('workspace');
50 if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) {
51 $activeWorkspace = $switchWs;
52 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
53 $performWorkspaceSwitch = TRUE;
54 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
55 } elseif ($switchWs == \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES) {
56 $this->redirect('fullIndex');
57 }
58 }
59 }
60 $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$GLOBALS['BE_USER']->workspace === 0 ? TRUE : FALSE);
61 $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace));
62 $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
63 $this->pageRenderer->addInlineSetting('Workspaces', 'PATH_typo3', GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . TYPO3_mainDir);
64 $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch);
65 $this->view->assign('workspaceList', $wsList);
66 $this->view->assign('activeWorkspaceUid', $activeWorkspace);
67 $this->view->assign('activeWorkspaceTitle', \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($activeWorkspace));
68 $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
69 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
70 }
71
72 /**
73 * Renders the review module user dependent.
74 * The module will show all records of all workspaces.
75 *
76 * @return void
77 */
78 public function fullIndexAction() {
79 $wsService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
80 $wsList = $wsService->getAvailableWorkspaces();
81
82 if (!$GLOBALS['BE_USER']->isAdmin()) {
83 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
84 $wsCur = array($activeWorkspace => TRUE);
85 $wsList = array_intersect_key($wsList, $wsCur);
86 }
87
88 $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES));
89 $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
90 $this->pageRenderer->addInlineSetting('Workspaces', 'PATH_typo3', GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . TYPO3_mainDir);
91 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
92 $this->view->assign('showGrid', TRUE);
93 $this->view->assign('showLegend', TRUE);
94 $this->view->assign('showAllWorkspaceTab', TRUE);
95 $this->view->assign('workspaceList', $wsList);
96 $this->view->assign('activeWorkspaceUid', \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
97 $this->view->assign('showPreviewLink', FALSE);
98 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
99 // set flag for javascript
100 $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
101 }
102
103 /**
104 * Renders the review module for a single page. This is used within the
105 * workspace-preview frame.
106 *
107 * @return void
108 */
109 public function singleIndexAction() {
110 $wsService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
111 $wsList = $wsService->getAvailableWorkspaces();
112 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
113 $wsCur = array($activeWorkspace => TRUE);
114 $wsList = array_intersect_key($wsList, $wsCur);
115 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
116 $this->view->assign('showGrid', TRUE);
117 $this->view->assign('showAllWorkspaceTab', FALSE);
118 $this->view->assign('workspaceList', $wsList);
119 $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
120 $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
121 }
122
123 /**
124 * Initializes the controller before invoking an action method.
125 *
126 * @return void
127 */
128 protected function initializeAction() {
129 parent::initializeAction();
130 $this->template->setExtDirectStateProvider();
131 if (\TYPO3\CMS\Workspaces\Service\WorkspaceService::isOldStyleWorkspaceUsed()) {
132 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:warning.oldStyleWorkspaceInUser'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
133 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
134 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
135 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
136 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
137 $defaultFlashMessageQueue->enqueue($flashMessage);
138 }
139 $this->pageRenderer->loadExtJS();
140 $this->pageRenderer->enableExtJSQuickTips();
141 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
142 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
143 // Load JavaScript:
144 $this->pageRenderer->addExtDirectCode(array(
145 'TYPO3.Workspaces'
146 ));
147 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/flashmessages.js');
148 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.grid.RowExpander.js');
149 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.app.SearchField.js');
150 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.ux.FitToParent.js');
151 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
152
153 // @todo Integrate additional stylesheet resources
154 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/GridFilters.css');
155 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/RangeMenu.css');
156
157 $filters = array(
158 $resourcePath. 'gridfilters/menu/RangeMenu.js',
159 $resourcePath. 'gridfilters/menu/ListMenu.js',
160 $resourcePath .'gridfilters/GridFilters.js',
161 $resourcePath . 'gridfilters/filter/Filter.js',
162 $resourcePath . 'gridfilters/filter/StringFilter.js',
163 $resourcePath . 'gridfilters/filter/DateFilter.js',
164 $resourcePath . 'gridfilters/filter/ListFilter.js',
165 $resourcePath . 'gridfilters/filter/NumericFilter.js',
166 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
167 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
168 );
169
170 $custom = $this->getAdditionalResourceService()->getJavaScriptResources();
171
172 $resources = array(
173 $resourcePath . 'Component/RowDetailTemplate.js',
174 $resourcePath . 'Component/RowExpander.js',
175 $resourcePath . 'Component/TabPanel.js',
176 $resourcePath . 'Store/mainstore.js',
177 $resourcePath . 'configuration.js',
178 $resourcePath . 'helpers.js',
179 $resourcePath . 'actions.js',
180 $resourcePath . 'component.js',
181 $resourcePath . 'toolbar.js',
182 $resourcePath . 'grid.js',
183 $resourcePath . 'workspaces.js'
184 );
185
186 $javaScriptFiles = array_merge($filters, $custom, $resources);
187
188 foreach ($javaScriptFiles as $javaScriptFile) {
189 $this->pageRenderer->addJsFile($javaScriptFile);
190 }
191 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('record_history'));
192 }
193
194 /**
195 * Prepares available workspace tabs.
196 *
197 * @param array $workspaceList
198 * @param int $activeWorkspace
199 * @return array
200 */
201 protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace) {
202 $tabs = array();
203
204 if ($activeWorkspace !== \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES) {
205 $tabs[] = array(
206 'title' => $workspaceList[$activeWorkspace],
207 'itemId' => 'workspace-' . $activeWorkspace,
208 'workspaceId' => $activeWorkspace,
209 'triggerUrl' => $this->getModuleUri($activeWorkspace),
210 );
211 }
212
213 $tabs[] = array(
214 'title' => 'All workspaces',
215 'itemId' => 'workspace-' . \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES,
216 'workspaceId' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES,
217 'triggerUrl' => $this->getModuleUri(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES),
218 );
219
220 foreach ($workspaceList as $workspaceId => $workspaceTitle) {
221 if ($workspaceId === $activeWorkspace) {
222 continue;
223 }
224 $tabs[] = array(
225 'title' => $workspaceTitle,
226 'itemId' => 'workspace-' . $workspaceId,
227 'workspaceId' => $workspaceId,
228 'triggerUrl' => $this->getModuleUri($workspaceId),
229 );
230 }
231
232 return $tabs;
233 }
234
235 /**
236 * Gets the module URI.
237 *
238 * @param int $workspaceId
239 * @return string
240 */
241 protected function getModuleUri($workspaceId) {
242 $parameters = array(
243 'id' => (int)$this->pageId,
244 'workspace' => (int)$workspaceId,
245 );
246 // The "all workspaces" tab is handled in fullIndexAction
247 // which is required as additional GET parameter in the URI then
248 if ($workspaceId === \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES) {
249 $this->uriBuilder->reset()->uriFor('fullIndex');
250 $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
251 }
252 return \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
253 }
254
255 }