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