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