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