2 /***************************************************************
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
31 * @subpackage ExtDirect
33 class tx_Workspaces_ExtDirect_Server
extends tx_Workspaces_ExtDirect_AbstractHandler
{
35 * Get List of workspace changes
37 * @param object $parameter
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;
44 $wslibObj = t3lib_div
::makeInstance('tx_Workspaces_Service_Workspaces');
45 $versions = $wslibObj->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, $pageId, $parameter->depth
);
47 $workspacesService = t3lib_div
::makeInstance('tx_Workspaces_Service_GridData');
48 $data = $workspacesService->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace());
53 * Get List of available workspace actions
55 * @param object $parameter
58 public function getStageActions($parameter) {
59 $currentWorkspace = $this->getCurrentWorkspace();
61 if ($currentWorkspace != tx_Workspaces_Service_Workspaces
::SELECT_ALL_WORKSPACES
) {
62 $stagesService = t3lib_div
::makeInstance('Tx_Workspaces_Service_Stages');
63 $stages = $stagesService->getStagesForWSUser();
67 'total' => count($stages),
74 * Fetch futher information to current selected worspace record.
76 * @param object $parameter
79 public function getRowDetails($parameter) {
81 $diffReturnArray = array();
82 $liveReturnArray = array();
84 $t3lib_diff = t3lib_div
::makeInstance('t3lib_diff');
85 $stagesService = t3lib_div
::makeInstance('Tx_Workspaces_Service_Stages');
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
);
93 $fieldsOfRecords = array_keys($liveRecord);
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);
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);
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;
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, '');
122 $diffReturnArray[] = array(
123 'label' => $fieldTitle,
124 'content' => $versionThumb
126 $liveReturnArray[] = array(
127 'label' => $fieldTitle,
128 'content' => $liveThumb
131 $diffReturnArray[] = array(
132 'label' => $fieldTitle,
133 'content' => $t3lib_diff->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName]) // call diff class to get diff
135 $liveReturnArray[] = array(
136 'label' => $fieldTitle,
137 'content' => $liveRecord[$fieldName]
144 $commentsForRecord = $this->getCommentsForRecord($parameter->uid
, $parameter->table
);
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
165 * Gets an array with all sys_log entries and their comments for the given record uid and table
167 * @param integer $uid uid of changed element to search for in log
168 * @return string $table table name
170 public function getCommentsForRecord($uid, $table) {
171 $stagesService = t3lib_div
::makeInstance('Tx_Workspaces_Service_Stages');
172 $sysLogReturnArray = array();
174 $sysLogRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
175 'log_data,tstamp,userid',
177 'action=6 and details_nr=30
178 AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_log').'
179 AND recuid='.intval($uid),
184 foreach($sysLogRows as $sysLogRow) {
185 $sysLogEntry = array();
186 $data = unserialize($sysLogRow['log_data']);
187 $beUserRecord = t3lib_BEfunc
::getRecord('be_users', $sysLogRow['userid']);
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'];
195 $sysLogReturnArray[] = $sysLogEntry;
198 return $sysLogReturnArray;
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']);