83e58964565a2521c89fd89e8c91cc039b1e88a0
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / Server.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
30 * @package Workspaces
31 * @subpackage ExtDirect
32 */
33 class tx_Workspaces_ExtDirect_Server extends tx_Workspaces_ExtDirect_AbstractHandler {
34 /**
35 * Get List of workspace changes
36 *
37 * @param object $parameter
38 * @return array $data
39 */
40 public function getWorkspaceInfos($parameter) {
41 // To avoid too much work we use -1 to indicate that every page is relevant
42 $pageId = $parameter->id > 0 ? $parameter->id : -1;
43
44 $wslibObj = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
45 $versions = $wslibObj->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, $pageId, $parameter->depth);
46
47 $workspacesService = t3lib_div::makeInstance('tx_Workspaces_Service_GridData');
48 $data = $workspacesService->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace());
49 return $data;
50 }
51
52 /**
53 * Get List of available workspace actions
54 *
55 * @param object $parameter
56 * @return array $data
57 */
58 public function getStageActions($parameter) {
59 $currentWorkspace = $this->getCurrentWorkspace();
60 $stages = array();
61 if ($currentWorkspace != tx_Workspaces_Service_Workspaces::SELECT_ALL_WORKSPACES) {
62 $stagesService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
63 $stages = $stagesService->getStagesForWSUser();
64 }
65
66 $data = array(
67 'total' => count($stages),
68 'data' => $stages
69 );
70 return $data;
71 }
72
73 /**
74 * Fetch futher information to current selected worspace record.
75 *
76 * @param object $parameter
77 * @return array $data
78 */
79 public function getRowDetails($parameter) {
80 $diffReturnArray = array();
81 $liveReturnArray = array();
82
83 /** @var $t3lib_diff t3lib_diff */
84 $t3lib_diff = t3lib_div::makeInstance('t3lib_diff');
85 /** @var $stagesService Tx_Workspaces_Service_Stages */
86 $stagesService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
87
88 $liveRecord = t3lib_BEfunc::getRecord($parameter->table, $parameter->t3ver_oid);
89 $versionRecord = t3lib_BEfunc::getRecord($parameter->table, $parameter->uid);
90 $icon_Live = t3lib_iconWorks::mapRecordTypeToSpriteIconClass($parameter->table, $liveRecord);
91 $icon_Workspace = t3lib_iconWorks::mapRecordTypeToSpriteIconClass($parameter->table, $versionRecord);
92 $stagePosition = $stagesService->getPositionOfCurrentStage($parameter->stage);
93
94 $fieldsOfRecords = array_keys($liveRecord);
95
96 // get field list from TCA configuration, if available
97 t3lib_div::loadTCA($parameter->table);
98 if ($GLOBALS['TCA'][$parameter->table]) {
99 if ($GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList']) {
100 $fieldsOfRecords = $GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList'];
101 $fieldsOfRecords = t3lib_div::trimExplode(',',$fieldsOfRecords,1);
102 }
103 }
104
105 foreach ($fieldsOfRecords as $fieldName) {
106 // check for exclude fields
107 if ($GLOBALS['BE_USER']->isAdmin() || ($GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['exclude'] == 0) || t3lib_div::inList($GLOBALS['BE_USER']->groupData['non_exclude_fields'],$parameter->table.':'.$fieldName)) {
108 // call diff class only if there is a difference
109 if (strcmp($liveRecord[$fieldName],$versionRecord[$fieldName]) !== 0) {
110 // Select the human readable values before diff
111 $liveRecord[$fieldName] = t3lib_BEfunc::getProcessedValue($parameter->table,$fieldName,$liveRecord[$fieldName],0,1);
112 $versionRecord[$fieldName] = t3lib_BEfunc::getProcessedValue($parameter->table,$fieldName,$versionRecord[$fieldName],0,1);
113
114 // Get the field's label. If not available, use the field name
115 $fieldTitle = $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($parameter->table, $fieldName));
116 if (empty($fieldTitle)) {
117 $fieldTitle = $fieldName;
118 }
119
120 if ($GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['type'] == 'group' && $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['internal_type'] == 'file') {
121 $versionThumb = t3lib_BEfunc::thumbCode($versionRecord, $parameter->table, $fieldName, '');
122 $liveThumb = t3lib_BEfunc::thumbCode($liveRecord, $parameter->table, $fieldName, '');
123
124 $diffReturnArray[] = array(
125 'field' => $fieldName,
126 'label' => $fieldTitle,
127 'content' => $versionThumb
128 );
129 $liveReturnArray[] = array(
130 'field' => $fieldName,
131 'label' => $fieldTitle,
132 'content' => $liveThumb
133 );
134 } else {
135 $diffReturnArray[] = array(
136 'field' => $fieldName,
137 'label' => $fieldTitle,
138 'content' => $t3lib_diff->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName]) // call diff class to get diff
139 );
140 $liveReturnArray[] = array(
141 'field' => $fieldName,
142 'label' => $fieldTitle,
143 'content' => $liveRecord[$fieldName]
144 );
145 }
146 }
147 }
148 }
149 // Hook for modifying the difference and live arrays
150 // (this may be used by custom or dynamically-defined fields)
151 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'])) {
152 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] as $className) {
153 $hookObject = &t3lib_div::getUserObj($className);
154 $hookObject->modifyDifferenceArray($parameter, $diffReturnArray, $liveReturnArray, $t3lib_diff);
155 }
156 }
157
158 $commentsForRecord = $this->getCommentsForRecord($parameter->uid, $parameter->table);
159
160 return array(
161 'total' => 1,
162 'data' => array(
163 array(
164 'diff' => $diffReturnArray,
165 'live_record' => $liveReturnArray,
166 'path_Live' => $parameter->path_Live,
167 'label_Stage' => $parameter->label_Stage,
168 'stage_position' => $stagePosition['position'],
169 'stage_count' => $stagePosition['count'],
170 'comments' => $commentsForRecord,
171 'icon_Live' => $icon_Live,
172 'icon_Workspace' => $icon_Workspace
173 )
174 )
175 );
176 }
177
178 /**
179 * Gets an array with all sys_log entries and their comments for the given record uid and table
180 *
181 * @param integer $uid uid of changed element to search for in log
182 * @return string $table table name
183 */
184 public function getCommentsForRecord($uid, $table) {
185 $stagesService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
186 $sysLogReturnArray = array();
187
188 $sysLogRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
189 'log_data,tstamp,userid',
190 'sys_log',
191 'action=6 and details_nr=30
192 AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_log').'
193 AND recuid='.intval($uid),
194 '',
195 'tstamp DESC'
196 );
197
198 foreach($sysLogRows as $sysLogRow) {
199 $sysLogEntry = array();
200 $data = unserialize($sysLogRow['log_data']);
201 $beUserRecord = t3lib_BEfunc::getRecord('be_users', $sysLogRow['userid']);
202
203 $sysLogEntry['stage_title'] = $stagesService->getStageTitle($data['stage']);
204 $sysLogEntry['user_uid'] = $sysLogRow['userid'];
205 $sysLogEntry['user_username'] = is_array($beUserRecord) ? $beUserRecord['username'] : '';
206 $sysLogEntry['tstamp'] = t3lib_BEfunc::datetime($sysLogRow['tstamp']);
207 $sysLogEntry['user_comment'] = $data['comment'];
208
209 $sysLogReturnArray[] = $sysLogEntry;
210 }
211
212 return $sysLogReturnArray;
213 }
214 }
215
216
217 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/Server.php'])) {
218 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/Server.php']);
219 }
220 ?>