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