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_ActionHandler
extends tx_Workspaces_ExtDirect_AbstractHandler
{
35 * @var Tx_Workspaces_Service_Stages
37 protected $stageService;
40 * Creates this object.
42 public function __construct() {
43 $this->stageService
= t3lib_div
::makeInstance('Tx_Workspaces_Service_Stages');
47 * Generates a workspace preview link.
49 * @param integer $uid The ID of the record to be linked
50 * @return string the full domain including the protocol http:// or https://, but without the trailing '/'
52 public function generateWorkspacePreviewLink($uid) {
53 $ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
54 $ttlHours = ($ttlHours ?
$ttlHours : 24*2) * 3600;
56 'ADMCMD_prev' => t3lib_BEfunc
::compilePreviewKeyword('', $GLOBALS['BE_USER']->user
['uid'], $ttlHours, $this->getCurrentWorkspace()),
59 return t3lib_BEfunc
::getViewDomain($uid) . '/index.php?' . t3lib_div
::implodeArrayForUrl('', $linkParams);
63 * Swaps a sisngle record.
65 * @param string $table
66 * @param integer $t3ver_oid
67 * @param integer $orig_uid
70 * @todo What about reporting errors back to the ExtJS interface? /olly/
72 public function swapSingleRecord($table, $t3ver_oid, $orig_uid) {
73 $cmd[$table][$t3ver_oid]['version'] = array(
75 'swapWith' => $orig_uid,
79 $tce = t3lib_div
::makeInstance ('t3lib_TCEmain');
80 $tce->start(array(), $cmd);
81 $tce->process_cmdmap();
85 * Deletes a single record.
87 * @param string $table
91 * @todo What about reporting errors back to the ExtJS interface? /olly/
93 public function deleteSingleRecord($table, $uid) {
94 $cmd[$table][$uid]['version'] = array(
95 'action' => 'clearWSID'
98 $tce = t3lib_div
::makeInstance ('t3lib_TCEmain');
99 $tce->start(array(), $cmd);
100 $tce->process_cmdmap();
104 * Generates a view link for a page.
106 * @param string $table
110 public function viewSingleRecord($table, $uid) {
111 return tx_Workspaces_Service_Workspaces
::viewSingleRecord($table, $uid);
116 * Saves the selected columns to be shown to the preferences of the current backend user.
118 * @param object $model
121 public function saveColumnModel($model) {
123 foreach ($model as $column) {
124 $data[$column->column
] = array(
125 'position' => $column->position
,
126 'hidden' => $column->hidden
129 $GLOBALS['BE_USER']->uc
['moduleData']['Workspaces']['columns'] = $data;
130 $GLOBALS['BE_USER']->writeUC();
133 public function loadColumnModel() {
134 if(is_array($GLOBALS['BE_USER']->uc
['moduleData']['Workspaces']['columns'])) {
135 return $GLOBALS['BE_USER']->uc
['moduleData']['Workspaces']['columns'];
142 * Gets the dialog window to be displayed before a record can be sent to the next stage.
144 * @param integer $uid
145 * @param string $table
146 * @param integer $t3ver_oid
149 public function sendToNextStageWindow($uid, $table, $t3ver_oid) {
150 $elementRecord = t3lib_BEfunc
::getRecord($table, $uid);
152 if(is_array($elementRecord)) {
153 $stageId = $elementRecord['t3ver_stage'];
155 if ($this->getStageService()->isValid($stageId)) {
156 $nextStage = $this->getStageService()->getNextStage($stageId);
157 $result = $this->getSentToStageWindow($nextStage['uid']);
158 $result['affects'] = array(
160 'nextStage' => $nextStage['uid'],
161 't3ver_oid' => $t3ver_oid,
165 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
168 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264776);
175 * Gets the dialog window to be displayed before a record can be sent to the previous stage.
177 * @param integer $uid
178 * @param string $table
181 public function sendToPrevStageWindow($uid, $table) {
182 $elementRecord = t3lib_BEfunc
::getRecord($table, $uid);
184 if(is_array($elementRecord)) {
185 $stageId = $elementRecord['t3ver_stage'];
187 if ($this->getStageService()->isValid($stageId)) {
188 if ($stageId !== Tx_Workspaces_Service_Stages
::STAGE_EDIT_ID
) {
189 $prevStage = $this->getStageService()->getPrevStage($stageId);
191 $result = $this->getSentToStageWindow($prevStage['uid']);
192 $result['affects'] = array(
195 'nextStage' => $prevStage['uid'],
198 // element is already in edit stage, there is no prev stage - return an error message
199 $result = $this->getErrorResponse('error.sendToPrevStage.noPreviousStage', 1287264746);
202 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
205 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264765);
212 * Gets the dialog window to be displayed before a record can be sent to a specific stage.
214 * @param integer $nextStageId
217 public function sendToSpecificStageWindow($nextStageId) {
218 $result = $this->getSentToStageWindow($nextStageId);
219 $result['affects'] = array(
220 'nextStage' => $nextStageId,
227 * Gets a merged variant of recipient defined by uid and custom ones.
229 * @param array list of recipients
230 * @param string given user string of additional recipients
233 public function getRecipientList(array $uidOfRecipients, $additionalRecipients) {
234 $finalRecipients = array();
236 $recipients = array();
237 foreach ($uidOfRecipients as $userUid) {
238 $beUserRecord = t3lib_befunc
::getRecord('be_users',intval($userUid));
239 if(is_array($beUserRecord) && $beUserRecord['email'] != '') {
240 $recipients[] = $beUserRecord['email'];
244 if ($additionalRecipients != '') {
245 $additionalRecipients = t3lib_div
::trimExplode("\n", $additionalRecipients, TRUE);
247 $additionalRecipients = array();
250 $allRecipients = array_unique(
251 array_merge($recipients, $additionalRecipients)
254 foreach ($allRecipients as $recipient) {
255 if (t3lib_div
::validEmail($recipient)) {
256 $finalRecipients[] = $recipient;
260 return $finalRecipients;
264 * Gets an object with this structure:
271 * receipients: array with uids
275 * @param stdObject $parameters
278 public function sendToNextStageExecute(stdClass
$parameters) {
280 $recipients = array();
282 $setStageId = $parameters->affects
->nextStage
;
283 $comments = $parameters->comments
;
284 $table = $parameters->affects
->table
;
285 $uid = $parameters->affects
->uid
;
286 $t3ver_oid = $parameters->affects
->t3ver_oid
;
287 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
);
289 if ($setStageId == Tx_Workspaces_Service_Stages
::STAGE_PUBLISH_EXECUTE_ID
) {
290 $cmdArray[$table][$t3ver_oid]['version']['action'] = 'swap';
291 $cmdArray[$table][$t3ver_oid]['version']['swapWith'] = $uid;
292 $cmdArray[$table][$t3ver_oid]['version']['comment'] = $comments;
293 $cmdArray[$table][$t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
295 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
296 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
297 $cmdArray[$table][$uid]['version']['comment'] = $comments;
298 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
301 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
302 $tce->start(array(), $cmdArray);
303 $tce->process_cmdmap();
313 * Gets an object with this structure:
319 * receipients: array with uids
323 * @param stdObject $parameters
326 public function sendToPrevStageExecute(stdClass
$parameters) {
328 $recipients = array();
330 $setStageId = $parameters->affects
->nextStage
;
331 $comments = $parameters->comments
;
332 $table = $parameters->affects
->table
;
333 $uid = $parameters->affects
->uid
;
334 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
);
336 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
337 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
338 $cmdArray[$table][$uid]['version']['comment'] = $comments;
339 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
341 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
342 $tce->start(array(), $cmdArray);
343 $tce->process_cmdmap();
353 * Gets an object with this structure:
366 * receipients: array with uids
370 * @param stdObject $parameters
373 public function sendToSpecificStageExecute(stdClass
$parameters) {
376 $setStageId = $parameters->affects
->nextStage
;
377 $comments = $parameters->comments
;
378 $elements = $parameters->affects
->elements
;
379 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
);
381 foreach($elements as $key=>$element) {
382 if ($setStageId == Tx_Workspaces_Service_Stages
::STAGE_PUBLISH_EXECUTE_ID
) {
383 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['action'] = 'swap';
384 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['swapWith'] = $element->uid
;
385 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['comment'] = $comments;
386 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['notificationAlternativeRecipients'] = $recipients;
388 $cmdArray[$element->table
][$element->uid
]['version']['action'] = 'setStage';
389 $cmdArray[$element->table
][$element->uid
]['version']['stageId'] = $setStageId;
390 $cmdArray[$element->table
][$element->uid
]['version']['comment'] = $comments;
391 $cmdArray[$element->table
][$element->uid
]['version']['notificationAlternativeRecipients'] = $recipients;
395 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
396 $tce->start(array(), $cmdArray);
397 $tce->process_cmdmap();
407 * Gets the dialog window to be displayed before a record can be sent to a stage.
409 * @param $nextStageId
412 protected function getSentToStageWindow($nextStageId) {
413 $stageTitle = $this->getStageService()->getStageTitle($nextStageId);
415 'title' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:actionSendToStage'),
419 'bodyStyle' => 'margin-bottom: 7px; border: none;',
420 'html' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:window.sendToNextStageWindow.itemsWillBeSentTo') . $stageTitle,
423 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:window.sendToNextStageWindow.sendMailTo'),
424 'xtype' => 'checkboxgroup',
425 'itemCls' => 'x-check-group-alt',
427 'style' => 'max-height: 200px',
428 'autoScroll' => true,
430 $this->getReceipientsOfStage($nextStageId)
434 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:window.sendToNextStageWindow.additionalRecipients'),
435 'name' => 'additional',
436 'xtype' => 'textarea',
440 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:window.sendToNextStageWindow.comments'),
441 'name' => 'comments',
442 'xtype' => 'textarea',
444 'value' => $this->getDefaultCommentOfStage($nextStageId),
453 * Gets all assigned recipients of a particular stage.
455 * @param integer $stage
458 protected function getReceipientsOfStage($stage) {
461 $recipients = $this->getStageService()->getResponsibleBeUser($stage);
463 foreach ($recipients as $id => $user) {
464 if (t3lib_div
::validEmail($user['email'])) {
465 $name = $user['realName'] ?
$user['realName'] : $user['username'];
467 'boxLabel' => sprintf('%s (%s)', $name, $user['email']),
468 'name' => 'receipients-' . $id,
478 * Gets the default comment of a particular stage.
480 * @param integer $stage
483 protected function getDefaultCommentOfStage($stage) {
484 $result = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
490 * Gets an instance of the Stage service.
492 * @return Tx_Workspaces_Service_Stages
494 protected function getStageService() {
495 if (!isset($this->stageService
)) {
496 $this->stageService
= t3lib_div
::makeInstance('Tx_Workspaces_Service_Stages');
498 return $this->stageService
;
503 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/ExtDirect/ActionHandler.php'])) {
504 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/ExtDirect/ActionHandler.php']);