940ebc077b19c1b9cd2dad1bf38a8a99913639af
[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 (strlen(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->pageRenderer->addInlineSetting('Workspaces', 'PATH_typo3', GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . TYPO3_mainDir);
70 $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch);
71 $this->view->assign('workspaceList', $wsList);
72 $this->view->assign('activeWorkspaceUid', $activeWorkspace);
73 $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace));
74 $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
75 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
76 }
77
78 /**
79 * Renders the review module user dependent.
80 * The module will show all records of all workspaces.
81 *
82 * @return void
83 */
84 public function fullIndexAction() {
85 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
86 $wsList = $wsService->getAvailableWorkspaces();
87
88 if (!$GLOBALS['BE_USER']->isAdmin()) {
89 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
90 $wsCur = array($activeWorkspace => TRUE);
91 $wsList = array_intersect_key($wsList, $wsCur);
92 }
93
94 $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, WorkspaceService::SELECT_ALL_WORKSPACES));
95 $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', WorkspaceService::SELECT_ALL_WORKSPACES);
96 $this->pageRenderer->addInlineSetting('Workspaces', 'PATH_typo3', GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . TYPO3_mainDir);
97 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
98 $this->view->assign('showGrid', TRUE);
99 $this->view->assign('showLegend', TRUE);
100 $this->view->assign('showAllWorkspaceTab', TRUE);
101 $this->view->assign('workspaceList', $wsList);
102 $this->view->assign('activeWorkspaceUid', WorkspaceService::SELECT_ALL_WORKSPACES);
103 $this->view->assign('showPreviewLink', FALSE);
104 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', WorkspaceService::SELECT_ALL_WORKSPACES);
105 // set flag for javascript
106 $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
107 }
108
109 /**
110 * Renders the review module for a single page. This is used within the
111 * workspace-preview frame.
112 *
113 * @return void
114 */
115 public function singleIndexAction() {
116 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
117 $wsList = $wsService->getAvailableWorkspaces();
118 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
119 $wsCur = array($activeWorkspace => TRUE);
120 $wsList = array_intersect_key($wsList, $wsCur);
121 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
122 $this->view->assign('showGrid', TRUE);
123 $this->view->assign('showAllWorkspaceTab', FALSE);
124 $this->view->assign('workspaceList', $wsList);
125 $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
126 $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
127 }
128
129 /**
130 * Initializes the controller before invoking an action method.
131 *
132 * @return void
133 */
134 protected function initializeAction() {
135 parent::initializeAction();
136 $this->template->setExtDirectStateProvider();
137 if (WorkspaceService::isOldStyleWorkspaceUsed()) {
138 $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);
139 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
140 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
141 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
142 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
143 $defaultFlashMessageQueue->enqueue($flashMessage);
144 }
145 $this->pageRenderer->loadExtJS();
146 $this->pageRenderer->enableExtJSQuickTips();
147 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
148 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
149 // Load JavaScript:
150 $this->pageRenderer->addExtDirectCode(array(
151 'TYPO3.Workspaces'
152 ));
153 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.grid.RowExpander.js');
154 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.app.SearchField.js');
155 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.ux.FitToParent.js');
156 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
157
158 // @todo Integrate additional stylesheet resources
159 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/GridFilters.css');
160 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/RangeMenu.css');
161
162 $filters = array(
163 $resourcePath . 'gridfilters/menu/RangeMenu.js',
164 $resourcePath . 'gridfilters/menu/ListMenu.js',
165 $resourcePath . 'gridfilters/GridFilters.js',
166 $resourcePath . 'gridfilters/filter/Filter.js',
167 $resourcePath . 'gridfilters/filter/StringFilter.js',
168 $resourcePath . 'gridfilters/filter/DateFilter.js',
169 $resourcePath . 'gridfilters/filter/ListFilter.js',
170 $resourcePath . 'gridfilters/filter/NumericFilter.js',
171 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
172 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
173 );
174
175 $custom = $this->getAdditionalResourceService()->getJavaScriptResources();
176
177 $resources = array(
178 $resourcePath . 'Component/RowDetailTemplate.js',
179 $resourcePath . 'Component/RowExpander.js',
180 $resourcePath . 'Component/TabPanel.js',
181 $resourcePath . 'Store/mainstore.js',
182 $resourcePath . 'configuration.js',
183 $resourcePath . 'helpers.js',
184 $resourcePath . 'actions.js',
185 $resourcePath . 'component.js',
186 $resourcePath . 'toolbar.js',
187 $resourcePath . 'grid.js',
188 $resourcePath . 'workspaces.js'
189 );
190
191 $javaScriptFiles = array_merge($filters, $custom, $resources);
192
193 foreach ($javaScriptFiles as $javaScriptFile) {
194 $this->pageRenderer->addJsFile($javaScriptFile);
195 }
196 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
197 }
198
199 /**
200 * Prepares available workspace tabs.
201 *
202 * @param array $workspaceList
203 * @param int $activeWorkspace
204 * @return array
205 */
206 protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace) {
207 $tabs = array();
208
209 if ($activeWorkspace !== WorkspaceService::SELECT_ALL_WORKSPACES) {
210 $tabs[] = array(
211 'title' => $workspaceList[$activeWorkspace],
212 'itemId' => 'workspace-' . $activeWorkspace,
213 'workspaceId' => $activeWorkspace,
214 'triggerUrl' => $this->getModuleUri($activeWorkspace),
215 );
216 }
217
218 $tabs[] = array(
219 'title' => 'All workspaces',
220 'itemId' => 'workspace-' . WorkspaceService::SELECT_ALL_WORKSPACES,
221 'workspaceId' => WorkspaceService::SELECT_ALL_WORKSPACES,
222 'triggerUrl' => $this->getModuleUri(WorkspaceService::SELECT_ALL_WORKSPACES),
223 );
224
225 foreach ($workspaceList as $workspaceId => $workspaceTitle) {
226 if ($workspaceId === $activeWorkspace) {
227 continue;
228 }
229 $tabs[] = array(
230 'title' => $workspaceTitle,
231 'itemId' => 'workspace-' . $workspaceId,
232 'workspaceId' => $workspaceId,
233 'triggerUrl' => $this->getModuleUri($workspaceId),
234 );
235 }
236
237 return $tabs;
238 }
239
240 /**
241 * Gets the module URI.
242 *
243 * @param int $workspaceId
244 * @return string
245 */
246 protected function getModuleUri($workspaceId) {
247 $parameters = array(
248 'id' => (int)$this->pageId,
249 'workspace' => (int)$workspaceId,
250 );
251 // The "all workspaces" tab is handled in fullIndexAction
252 // which is required as additional GET parameter in the URI then
253 if ($workspaceId === WorkspaceService::SELECT_ALL_WORKSPACES) {
254 $this->uriBuilder->reset()->uriFor('fullIndex');
255 $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
256 }
257 return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
258 }
259
260 }