c7a69bf55510f864c88270b01537635393ab70c7
[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 global $TCA,$BE_USER;
81 $diffReturnArray = array();
82 $liveReturnArray = array();
83
84 $t3lib_diff = t3lib_div::makeInstance('t3lib_diff');
85 $stagesService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
86
87 $liveRecord = t3lib_BEfunc::getRecord($parameter->table, $parameter->t3ver_oid);
88 $versionRecord = t3lib_BEfunc::getRecord($parameter->table, $parameter->uid);
89 $icon_Live = t3lib_iconWorks::mapRecordTypeToSpriteIconClass($parameter->table, $liveRecord);
90 $icon_Workspace = t3lib_iconWorks::mapRecordTypeToSpriteIconClass($parameter->table, $versionRecord);
91 $stagePosition = $stagesService->getPositionOfCurrentStage($parameter->stage);
92
93 $fieldsOfRecords = array_keys($liveRecord);
94
95 // get field list from TCA configuration, if available
96 if ($TCA[$parameter->table]) {
97 if ($TCA[$parameter->table]['interface']['showRecordFieldList']) {
98 $fieldsOfRecords = $TCA[$parameter->table]['interface']['showRecordFieldList'];
99 $fieldsOfRecords = t3lib_div::trimExplode(',',$fieldsOfRecords,1);
100 }
101 }
102
103 foreach ($fieldsOfRecords as $fieldName) {
104 // check for exclude fields
105 if ($GLOBALS['BE_USER']->isAdmin() || ($TCA[$parameter->table]['columns'][$fieldName]['exclude'] == 0) || t3lib_div::inList($BE_USER->groupData['non_exclude_fields'],$parameter->table.':'.$fieldName)) {
106 // call diff class only if there is a difference
107 if (strcmp($liveRecord[$fieldName],$versionRecord[$fieldName]) !== 0) {
108 // Select the human readable values before diff
109 $liveRecord[$fieldName] = t3lib_BEfunc::getProcessedValue($parameter->table,$fieldName,$liveRecord[$fieldName],0,1);
110 $versionRecord[$fieldName] = t3lib_BEfunc::getProcessedValue($parameter->table,$fieldName,$versionRecord[$fieldName],0,1);
111
112 // Get the field's label. If not available, use the field name
113 $fieldTitle = $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($parameter->table, $fieldName));
114 if (empty($fieldTitle)) {
115 $fieldTitle = $fieldName;
116 }
117
118 if ($TCA[$parameter->table]['columns'][$fieldName]['config']['type'] == 'group' && $TCA[$parameter->table]['columns'][$fieldName]['config']['internal_type'] == 'file') {
119 $versionThumb = t3lib_BEfunc::thumbCode($versionRecord, $parameter->table, $fieldName, '');
120 $liveThumb = t3lib_BEfunc::thumbCode($liveRecord, $parameter->table, $fieldName, '');
121
122 $diffReturnArray[] = array(
123 'label' => $fieldTitle,
124 'content' => $versionThumb
125 );
126 $liveReturnArray[] = array(
127 'label' => $fieldTitle,
128 'content' => $liveThumb
129 );
130 } else {
131 $diffReturnArray[] = array(
132 'label' => $fieldTitle,
133 'content' => $t3lib_diff->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName]) // call diff class to get diff
134 );
135 $liveReturnArray[] = array(
136 'label' => $fieldTitle,
137 'content' => $liveRecord[$fieldName]
138 );
139 }
140 }
141 }
142 }
143
144 $commentsForRecord = $this->getCommentsForRecord($parameter->uid, $parameter->table);
145
146 return array(
147 'total' => 1,
148 'data' => array(
149 array(
150 'diff' => $diffReturnArray,
151 'live_record' => $liveReturnArray,
152 'path_Live' => $parameter->path_Live,
153 'label_Stage' => $parameter->label_Stage,
154 'stage_position' => $stagePosition['position'],
155 'stage_count' => $stagePosition['count'],
156 'comments' => $commentsForRecord,
157 'icon_Live' => $icon_Live,
158 'icon_Workspace' => $icon_Workspace
159 )
160 )
161 );
162 }
163
164 /**
165 * Gets an array with all sys_log entries and their comments for the given record uid and table
166 *
167 * @param integer $uid uid of changed element to search for in log
168 * @return string $table table name
169 */
170 public function getCommentsForRecord($uid, $table) {
171 $stagesService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
172 $sysLogReturnArray = array();
173
174 $sysLogRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
175 'log_data,tstamp,userid',
176 'sys_log',
177 'action=6 and details_nr=30
178 AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_log').'
179 AND recuid='.intval($uid),
180 '',
181 'tstamp DESC'
182 );
183
184 foreach($sysLogRows as $sysLogRow) {
185 $sysLogEntry = array();
186 $data = unserialize($sysLogRow['log_data']);
187 $beUserRecord = t3lib_BEfunc::getRecord('be_users', $sysLogRow['userid']);
188
189 $sysLogEntry['stage_title'] = $stagesService->getStageTitle($data['stage']);
190 $sysLogEntry['user_uid'] = $sysLogRow['userid'];
191 $sysLogEntry['user_username'] = is_array($beUserRecord) ? $beUserRecord['username'] : '';
192 $sysLogEntry['tstamp'] = t3lib_BEfunc::datetime($sysLogRow['tstamp']);
193 $sysLogEntry['user_comment'] = $data['comment'];
194
195 $sysLogReturnArray[] = $sysLogEntry;
196 }
197
198 return $sysLogReturnArray;
199 }
200 }
201
202
203 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/Server.php'])) {
204 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/Server.php']);
205 }
206 ?>