[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / ExtDirectServer.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\ExtDirect;
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\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * ExtDirect server
22 *
23 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
24 */
25 class ExtDirectServer extends AbstractHandler {
26
27 /**
28 * @var \TYPO3\CMS\Workspaces\Service\GridDataService
29 */
30 protected $gridDataService;
31
32 /**
33 * @var \TYPO3\CMS\Workspaces\Service\StagesService
34 */
35 protected $stagesService;
36
37 /**
38 * Checks integrity of elements before peforming actions on them.
39 *
40 * @param stdClass $parameters
41 * @return array
42 */
43 public function checkIntegrity(\stdClass $parameters) {
44 $integrity = $this->createIntegrityService($this->getAffectedElements($parameters));
45 $integrity->check();
46 $response = array(
47 'result' => $integrity->getStatusRepresentation()
48 );
49 return $response;
50 }
51
52 /**
53 * Get List of workspace changes
54 *
55 * @param \stdClass $parameter
56 * @return array $data
57 */
58 public function getWorkspaceInfos($parameter) {
59 // To avoid too much work we use -1 to indicate that every page is relevant
60 $pageId = $parameter->id > 0 ? $parameter->id : -1;
61 if (!isset($parameter->language) || !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($parameter->language)) {
62 $parameter->language = NULL;
63 }
64 $versions = $this->getWorkspaceService()->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, $pageId, $parameter->depth, 'tables_select', $parameter->language);
65 $data = $this->getGridDataService()->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace());
66 return $data;
67 }
68
69 /**
70 * Gets the editing history of a record.
71 *
72 * @param stdClass $parameters
73 * @return array
74 */
75 public function getHistory($parameters) {
76 /** @var $historyService \TYPO3\CMS\Workspaces\Service\HistoryService */
77 $historyService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\HistoryService::class);
78 $history = $historyService->getHistory($parameters->table, $parameters->liveId);
79 return array(
80 'data' => $history,
81 'total' => count($history)
82 );
83 }
84
85 /**
86 * Get List of available workspace actions
87 *
88 * @param \stdClass $parameter
89 * @return array $data
90 */
91 public function getStageActions(\stdClass $parameter) {
92 $currentWorkspace = $this->getCurrentWorkspace();
93 $stages = array();
94 if ($currentWorkspace != \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES) {
95 $stages = $this->getStagesService()->getStagesForWSUser();
96 }
97 $data = array(
98 'total' => count($stages),
99 'data' => $stages
100 );
101 return $data;
102 }
103
104 /**
105 * Fetch further information to current selected workspace record.
106 *
107 * @param \stdClass $parameter
108 * @return array $data
109 */
110 public function getRowDetails($parameter) {
111 $diffReturnArray = array();
112 $liveReturnArray = array();
113 /** @var $t3lib_diff \TYPO3\CMS\Core\Utility\DiffUtility */
114 $t3lib_diff = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\DiffUtility::class);
115 /** @var $parseObj \TYPO3\CMS\Core\Html\RteHtmlParser */
116 $parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Html\RteHtmlParser::class);
117 $liveRecord = BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid);
118 $versionRecord = BackendUtility::getRecord($parameter->table, $parameter->uid);
119 $icon_Live = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($parameter->table, $liveRecord);
120 $icon_Workspace = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($parameter->table, $versionRecord);
121 $stagePosition = $this->getStagesService()->getPositionOfCurrentStage($parameter->stage);
122 $fieldsOfRecords = array_keys($liveRecord);
123 if ($GLOBALS['TCA'][$parameter->table]) {
124 if ($GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList']) {
125 $fieldsOfRecords = $GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList'];
126 $fieldsOfRecords = GeneralUtility::trimExplode(',', $fieldsOfRecords, TRUE);
127 }
128 }
129 foreach ($fieldsOfRecords as $fieldName) {
130 // check for exclude fields
131 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['exclude'] == 0 || GeneralUtility::inList($GLOBALS['BE_USER']->groupData['non_exclude_fields'], $parameter->table . ':' . $fieldName)) {
132 // call diff class only if there is a difference
133 if ((string)$liveRecord[$fieldName] !== (string)$versionRecord[$fieldName]) {
134 // Select the human readable values before diff
135 $liveRecord[$fieldName] = BackendUtility::getProcessedValue(
136 $parameter->table,
137 $fieldName,
138 $liveRecord[$fieldName],
139 0,
140 1,
141 FALSE,
142 $liveRecord['uid']
143 );
144 $versionRecord[$fieldName] = BackendUtility::getProcessedValue(
145 $parameter->table,
146 $fieldName,
147 $versionRecord[$fieldName],
148 0,
149 1,
150 FALSE,
151 $versionRecord['uid']
152 );
153 // Get the field's label. If not available, use the field name
154 $fieldTitle = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($parameter->table, $fieldName));
155 if (empty($fieldTitle)) {
156 $fieldTitle = $fieldName;
157 }
158 if ($GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['type'] == 'group' && $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['internal_type'] == 'file') {
159 $versionThumb = BackendUtility::thumbCode($versionRecord, $parameter->table, $fieldName, '');
160 $liveThumb = BackendUtility::thumbCode($liveRecord, $parameter->table, $fieldName, '');
161 $diffReturnArray[] = array(
162 'field' => $fieldName,
163 'label' => $fieldTitle,
164 'content' => $versionThumb
165 );
166 $liveReturnArray[] = array(
167 'field' => $fieldName,
168 'label' => $fieldTitle,
169 'content' => $liveThumb
170 );
171 } else {
172 $diffReturnArray[] = array(
173 'field' => $fieldName,
174 'label' => $fieldTitle,
175 'content' => $t3lib_diff->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName])
176 );
177 $liveReturnArray[] = array(
178 'field' => $fieldName,
179 'label' => $fieldTitle,
180 'content' => $parseObj->TS_images_rte($liveRecord[$fieldName])
181 );
182 }
183 }
184 }
185 }
186 // Hook for modifying the difference and live arrays
187 // (this may be used by custom or dynamically-defined fields)
188 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'])) {
189 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] as $className) {
190 $hookObject =& GeneralUtility::getUserObj($className);
191 $hookObject->modifyDifferenceArray($parameter, $diffReturnArray, $liveReturnArray, $t3lib_diff);
192 }
193 }
194 $commentsForRecord = $this->getCommentsForRecord($parameter->uid, $parameter->table);
195 return array(
196 'total' => 1,
197 'data' => array(
198 array(
199 'diff' => $diffReturnArray,
200 'live_record' => $liveReturnArray,
201 'path_Live' => $parameter->path_Live,
202 'label_Stage' => $parameter->label_Stage,
203 'stage_position' => $stagePosition['position'],
204 'stage_count' => $stagePosition['count'],
205 'comments' => $commentsForRecord,
206 'icon_Live' => $icon_Live,
207 'icon_Workspace' => $icon_Workspace
208 )
209 )
210 );
211 }
212
213 /**
214 * Gets an array with all sys_log entries and their comments for the given record uid and table
215 *
216 * @param int $uid uid of changed element to search for in log
217 * @param string $table Name of the record's table
218 * @return array
219 */
220 public function getCommentsForRecord($uid, $table) {
221 $sysLogReturnArray = array();
222 $sysLogRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
223 'log_data,tstamp,userid',
224 'sys_log',
225 'action=6 and details_nr=30 AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_log')
226 . ' AND recuid=' . (int)$uid,
227 '',
228 'tstamp DESC'
229 );
230 foreach ($sysLogRows as $sysLogRow) {
231 $sysLogEntry = array();
232 $data = unserialize($sysLogRow['log_data']);
233 $beUserRecord = BackendUtility::getRecord('be_users', $sysLogRow['userid']);
234 $sysLogEntry['stage_title'] = $this->getStagesService()->getStageTitle($data['stage']);
235 $sysLogEntry['user_uid'] = $sysLogRow['userid'];
236 $sysLogEntry['user_username'] = is_array($beUserRecord) ? $beUserRecord['username'] : '';
237 $sysLogEntry['tstamp'] = BackendUtility::datetime($sysLogRow['tstamp']);
238 $sysLogEntry['user_comment'] = $data['comment'];
239 $sysLogReturnArray[] = $sysLogEntry;
240 }
241 return $sysLogReturnArray;
242 }
243
244 /**
245 * Gets all available system languages.
246 *
247 * @return array
248 */
249 public function getSystemLanguages() {
250 $systemLanguages = array(
251 array(
252 'uid' => 'all',
253 'title' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('language.allLanguages', 'workspaces'),
254 'cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('empty-empty')
255 )
256 );
257 foreach ($this->getGridDataService()->getSystemLanguages() as $id => $systemLanguage) {
258 if ($id < 0) {
259 continue;
260 }
261 $systemLanguages[] = array(
262 'uid' => $id,
263 'title' => htmlspecialchars($systemLanguage['title']),
264 'cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses($systemLanguage['flagIcon'])
265 );
266 }
267 $result = array(
268 'total' => count($systemLanguages),
269 'data' => $systemLanguages
270 );
271 return $result;
272 }
273
274 /**
275 * Gets the Grid Data Service.
276 *
277 * @return \TYPO3\CMS\Workspaces\Service\GridDataService
278 */
279 protected function getGridDataService() {
280 if (!isset($this->gridDataService)) {
281 $this->gridDataService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\GridDataService::class);
282 }
283 return $this->gridDataService;
284 }
285
286 /**
287 * Gets the Stages Service.
288 *
289 * @return \TYPO3\CMS\Workspaces\Service\StagesService
290 */
291 protected function getStagesService() {
292 if (!isset($this->stagesService)) {
293 $this->stagesService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\StagesService::class);
294 }
295 return $this->stagesService;
296 }
297
298 }