2 namespace TYPO3\CMS\Workspaces\ExtDirect
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
18 use TYPO3\CMS\Backend\Utility\BackendUtility
;
21 * ExtDirect action handler
23 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
25 class ActionHandler
extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler
{
28 * @var \TYPO3\CMS\Workspaces\Service\StagesService
30 protected $stageService;
33 * Creates this object.
35 public function __construct() {
36 $this->stageService
= GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
40 * Generates a workspace preview link.
42 * @param integer $uid The ID of the record to be linked
43 * @return string the full domain including the protocol http:// or https://, but without the trailing '/'
45 public function generateWorkspacePreviewLink($uid) {
46 return $this->getWorkspaceService()->generateWorkspacePreviewLink($uid);
50 * Swaps a single record.
52 * @param string $table
53 * @param integer $t3ver_oid
54 * @param integer $orig_uid
56 * @todo What about reporting errors back to the ExtJS interface? /olly/
58 public function swapSingleRecord($table, $t3ver_oid, $orig_uid) {
59 $versionRecord = BackendUtility
::getRecord($table, $orig_uid);
60 $currentWorkspace = $this->setTemporaryWorkspace($versionRecord['t3ver_wsid']);
62 $cmd[$table][$t3ver_oid]['version'] = array(
64 'swapWith' => $orig_uid,
67 $this->processTcaCmd($cmd);
69 $this->setTemporaryWorkspace($currentWorkspace);
73 * Deletes a single record.
75 * @param string $table
78 * @todo What about reporting errors back to the ExtJS interface? /olly/
80 public function deleteSingleRecord($table, $uid) {
81 $versionRecord = BackendUtility
::getRecord($table, $uid);
82 $currentWorkspace = $this->setTemporaryWorkspace($versionRecord['t3ver_wsid']);
84 $cmd[$table][$uid]['version'] = array(
85 'action' => 'clearWSID'
87 $this->processTcaCmd($cmd);
89 $this->setTemporaryWorkspace($currentWorkspace);
93 * Generates a view link for a page.
95 * @param string $table
99 public function viewSingleRecord($table, $uid) {
100 return \TYPO3\CMS\Workspaces\Service\WorkspaceService
::viewSingleRecord($table, $uid);
104 * Executes an action (publish, discard, swap) to a selection set.
106 * @param \stdClass $parameter
109 public function executeSelectionAction($parameter) {
112 if (empty($parameter->action
) ||
empty($parameter->selection
)) {
113 $result['error'] = 'No action or record selection given';
118 $swapIntoWorkspace = ($parameter->action
=== 'swap');
119 if ($parameter->action
=== 'publish' ||
$swapIntoWorkspace) {
120 $commands = $this->getPublishSwapCommands($parameter->selection
, $swapIntoWorkspace);
121 } elseif ($parameter->action
=== 'discard') {
122 $commands = $this->getFlushCommands($parameter->selection
);
125 $result = $this->processTcaCmd($commands);
126 $result['total'] = count($commands);
131 * Get publish swap commands
133 * @param array|\stdClass[] $selection
134 * @param boolean $swapIntoWorkspace
137 protected function getPublishSwapCommands(array $selection, $swapIntoWorkspace) {
139 foreach ($selection as $record) {
140 $commands[$record->table
][$record->liveId
]['version'] = array(
142 'swapWith' => $record->versionId
,
143 'swapIntoWS' => (bool
)$swapIntoWorkspace,
152 * @param array|\stdClass[] $selection
155 protected function getFlushCommands(array $selection) {
157 foreach ($selection as $record) {
158 $commands[$record->table
][$record->versionId
]['version'] = array(
159 'action' => 'clearWSID',
166 * Saves the selected columns to be shown to the preferences of the current backend user.
168 * @param object $model
171 public function saveColumnModel($model) {
173 foreach ($model as $column) {
174 $data[$column->column
] = array(
175 'position' => $column->position
,
176 'hidden' => $column->hidden
179 $GLOBALS['BE_USER']->uc
['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace
]['columns'] = $data;
180 $GLOBALS['BE_USER']->writeUC();
183 public function loadColumnModel() {
184 if (is_array($GLOBALS['BE_USER']->uc
['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace
]['columns'])) {
185 return $GLOBALS['BE_USER']->uc
['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace
]['columns'];
192 * Saves the selected language.
194 * @param integer|string $language
197 public function saveLanguageSelection($language) {
198 if (\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($language) === FALSE
&& $language !== 'all') {
201 $GLOBALS['BE_USER']->uc
['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace
]['language'] = $language;
202 $GLOBALS['BE_USER']->writeUC();
206 * Gets the dialog window to be displayed before a record can be sent to the next stage.
208 * @param integer $uid
209 * @param string $table
210 * @param integer $t3ver_oid
213 public function sendToNextStageWindow($uid, $table, $t3ver_oid) {
214 $elementRecord = BackendUtility
::getRecord($table, $uid);
215 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
217 if (is_array($elementRecord)) {
218 $stageId = $elementRecord['t3ver_stage'];
219 if ($this->getStageService()->isValid($stageId)) {
220 $nextStage = $this->getStageService()->getNextStage($stageId);
221 $result = $this->getSentToStageWindow($nextStage['uid']);
222 $result['affects'] = array(
224 'nextStage' => $nextStage['uid'],
225 't3ver_oid' => $t3ver_oid,
229 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
232 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264776);
235 $this->setTemporaryWorkspace($currentWorkspace);
240 * Gets the dialog window to be displayed before a record can be sent to the previous stage.
242 * @param integer $uid
243 * @param string $table
246 public function sendToPrevStageWindow($uid, $table) {
247 $elementRecord = BackendUtility
::getRecord($table, $uid);
248 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
250 if (is_array($elementRecord)) {
251 $stageId = $elementRecord['t3ver_stage'];
252 if ($this->getStageService()->isValid($stageId)) {
253 if ($stageId !== \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_EDIT_ID
) {
254 $prevStage = $this->getStageService()->getPrevStage($stageId);
255 $result = $this->getSentToStageWindow($prevStage['uid']);
256 $result['affects'] = array(
259 'nextStage' => $prevStage['uid']
262 // element is already in edit stage, there is no prev stage - return an error message
263 $result = $this->getErrorResponse('error.sendToPrevStage.noPreviousStage', 1287264746);
266 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
269 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264765);
272 $this->setTemporaryWorkspace($currentWorkspace);
277 * Gets the dialog window to be displayed before a record can be sent to a specific stage.
279 * @param integer $nextStageId
282 public function sendToSpecificStageWindow($nextStageId) {
283 $result = $this->getSentToStageWindow($nextStageId);
284 $result['affects'] = array(
285 'nextStage' => $nextStageId
291 * Gets a merged variant of recipient defined by uid and custom ones.
293 * @param array list of recipients
294 * @param string given user string of additional recipients
295 * @param integer stage id
298 public function getRecipientList(array $uidOfRecipients, $additionalRecipients, $stageId) {
299 $finalRecipients = array();
300 if (!$this->getStageService()->isValid($stageId)) {
301 throw new \
InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:error.stageId.integer'));
303 $stageId = (int)$stageId;
305 $recipients = array();
306 foreach ($uidOfRecipients as $userUid) {
307 $beUserRecord = BackendUtility
::getRecord('be_users', (int)$userUid);
308 if (is_array($beUserRecord) && $beUserRecord['email'] !== '') {
309 $uc = $beUserRecord['uc'] ?
unserialize($beUserRecord['uc']) : array();
310 $recipients[$beUserRecord['email']] = array(
311 'email' => $beUserRecord['email'],
312 'lang' => isset($uc['lang']) ?
$uc['lang'] : $beUserRecord['lang']
316 // the notification mode can be configured in the workspace stage record
317 $notification_mode = (int)$this->getStageService()->getNotificationMode($stageId);
318 if ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService
::MODE_NOTIFY_ALL ||
$notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService
::MODE_NOTIFY_ALL_STRICT
) {
319 // get the default recipients from the stage configuration
320 // the default recipients needs to be added in some cases of the notification_mode
321 $default_recipients = $this->getStageService()->getResponsibleBeUser($stageId, TRUE
);
322 foreach ($default_recipients as $default_recipient_uid => $default_recipient_record) {
323 if (!isset($recipients[$default_recipient_record['email']])) {
324 $uc = $default_recipient_record['uc'] ?
unserialize($default_recipient_record['uc']) : array();
325 $recipients[$default_recipient_record['email']] = array(
326 'email' => $default_recipient_record['email'],
327 'lang' => isset($uc['lang']) ?
$uc['lang'] : $default_recipient_record['lang']
332 if ($additionalRecipients !== '') {
333 $emails = GeneralUtility
::trimExplode(LF
, $additionalRecipients, TRUE
);
334 $additionalRecipients = array();
335 foreach ($emails as $email) {
336 $additionalRecipients[$email] = array('email' => $email);
339 $additionalRecipients = array();
341 // We merge $recipients on top of $additionalRecipients because $recipients
342 // possibly is more complete with a user language. Furthermore, the list of
343 // recipients is automatically unique since we indexed $additionalRecipients
344 // and $recipients with the email address
345 $allRecipients = array_merge($additionalRecipients, $recipients);
346 foreach ($allRecipients as $email => $recipientInformation) {
347 if (GeneralUtility
::validEmail($email)) {
348 $finalRecipients[] = $recipientInformation;
351 return $finalRecipients;
355 * Discard all items from given page id.
357 * @param integer $pageId
359 * @author Michael Klapper <development@morphodo.com>
361 public function discardStagesFromPage($pageId) {
362 $cmdMapArray = array();
363 /** @var $workspaceService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
364 $workspaceService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
365 /** @var $stageService \TYPO3\CMS\Workspaces\Service\StagesService */
366 $stageService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
367 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
368 foreach ($workspaceItemsArray as $tableName => $items) {
369 foreach ($items as $item) {
370 $cmdMapArray[$tableName][$item['uid']]['version']['action'] = 'clearWSID';
373 $this->processTcaCmd($cmdMapArray);
380 * Push the given element collection to the next workspace stage.
383 * $parameters->additional = your@mail.com
384 * $parameters->affects->__TABLENAME__
385 * $parameters->comments
386 * $parameters->receipients
387 * $parameters->stageId
390 * @param stdClass $parameters
392 * @author Michael Klapper <development@morphodo.com>
394 public function sentCollectionToStage(\stdClass
$parameters) {
395 $cmdMapArray = array();
396 $comment = $parameters->comments
;
397 $stageId = $parameters->stageId
;
398 if (\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($stageId) === FALSE
) {
399 throw new \
InvalidArgumentException('Missing "stageId" in $parameters array.', 1319488194);
401 if (!is_object($parameters->affects
) ||
count($parameters->affects
) == 0) {
402 throw new \
InvalidArgumentException('Missing "affected items" in $parameters array.', 1319488195);
404 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
, $stageId);
405 foreach ($parameters->affects
as $tableName => $items) {
406 foreach ($items as $item) {
407 // Publishing uses live id in command map
408 if ($stageId == \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_PUBLISH_EXECUTE_ID
) {
409 $cmdMapArray[$tableName][$item->t3ver_oid
]['version']['action'] = 'swap';
410 $cmdMapArray[$tableName][$item->t3ver_oid
]['version']['swapWith'] = $item->uid
;
411 $cmdMapArray[$tableName][$item->t3ver_oid
]['version']['comment'] = $comment;
412 $cmdMapArray[$tableName][$item->t3ver_oid
]['version']['notificationAlternativeRecipients'] = $recipients;
413 // Setting stage uses version id in command map
415 $cmdMapArray[$tableName][$item->uid
]['version']['action'] = 'setStage';
416 $cmdMapArray[$tableName][$item->uid
]['version']['stageId'] = $stageId;
417 $cmdMapArray[$tableName][$item->uid
]['version']['comment'] = $comment;
418 $cmdMapArray[$tableName][$item->uid
]['version']['notificationAlternativeRecipients'] = $recipients;
422 $this->processTcaCmd($cmdMapArray);
425 // force refresh after publishing changes
426 'refreshLivePanel' => $parameters->stageId
== -20 ? TRUE
: FALSE
431 * Process TCA command map array.
433 * @param array $cmdMapArray
435 * @author Michael Klapper <development@morphodo.com>
437 protected function processTcaCmd(array $cmdMapArray) {
440 if (empty($cmdMapArray)) {
441 $result['error'] = 'No commands given to be processed';
445 /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
446 $dataHandler = GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
447 $dataHandler->start(array(), $cmdMapArray);
448 $dataHandler->process_cmdmap();
450 if ($dataHandler->errorLog
) {
451 $result['error'] = implode('<br/>', $dataHandler->errorLog
);
458 * Gets an object with this structure:
465 * receipients: array with uids
469 * @param stdClass $parameters
472 public function sendToNextStageExecute(\stdClass
$parameters) {
474 $setStageId = $parameters->affects
->nextStage
;
475 $comments = $parameters->comments
;
476 $table = $parameters->affects
->table
;
477 $uid = $parameters->affects
->uid
;
478 $t3ver_oid = $parameters->affects
->t3ver_oid
;
480 $elementRecord = BackendUtility
::getRecord($table, $uid);
481 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
483 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
, $setStageId);
484 if ($setStageId == \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_PUBLISH_EXECUTE_ID
) {
485 $cmdArray[$table][$t3ver_oid]['version']['action'] = 'swap';
486 $cmdArray[$table][$t3ver_oid]['version']['swapWith'] = $uid;
487 $cmdArray[$table][$t3ver_oid]['version']['comment'] = $comments;
488 $cmdArray[$table][$t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
490 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
491 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
492 $cmdArray[$table][$uid]['version']['comment'] = $comments;
493 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
495 $this->processTcaCmd($cmdArray);
500 $this->setTemporaryWorkspace($currentWorkspace);
505 * Gets an object with this structure:
511 * receipients: array with uids
515 * @param stdClass $parameters
518 public function sendToPrevStageExecute(\stdClass
$parameters) {
520 $setStageId = $parameters->affects
->nextStage
;
521 $comments = $parameters->comments
;
522 $table = $parameters->affects
->table
;
523 $uid = $parameters->affects
->uid
;
525 $elementRecord = BackendUtility
::getRecord($table, $uid);
526 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
528 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
, $setStageId);
529 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
530 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
531 $cmdArray[$table][$uid]['version']['comment'] = $comments;
532 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
533 $this->processTcaCmd($cmdArray);
538 $this->setTemporaryWorkspace($currentWorkspace);
543 * Gets an object with this structure:
556 * receipients: array with uids
560 * @param stdClass $parameters
563 public function sendToSpecificStageExecute(\stdClass
$parameters) {
565 $setStageId = $parameters->affects
->nextStage
;
566 $comments = $parameters->comments
;
567 $elements = $parameters->affects
->elements
;
568 $recipients = $this->getRecipientList($parameters->receipients
, $parameters->additional
, $setStageId);
569 foreach ($elements as $key => $element) {
570 if ($setStageId == \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_PUBLISH_EXECUTE_ID
) {
571 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['action'] = 'swap';
572 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['swapWith'] = $element->uid
;
573 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['comment'] = $comments;
574 $cmdArray[$element->table
][$element->t3ver_oid
]['version']['notificationAlternativeRecipients'] = $recipients;
576 $cmdArray[$element->table
][$element->uid
]['version']['action'] = 'setStage';
577 $cmdArray[$element->table
][$element->uid
]['version']['stageId'] = $setStageId;
578 $cmdArray[$element->table
][$element->uid
]['version']['comment'] = $comments;
579 $cmdArray[$element->table
][$element->uid
]['version']['notificationAlternativeRecipients'] = $recipients;
582 $this->processTcaCmd($cmdArray);
590 * Gets the dialog window to be displayed before a record can be sent to a stage.
592 * @param $nextStageId
595 protected function getSentToStageWindow($nextStageId) {
596 $workspaceRec = BackendUtility
::getRecord('sys_workspace', $this->getStageService()->getWorkspaceId());
597 $showNotificationFields = FALSE
;
598 $stageTitle = $this->getStageService()->getStageTitle($nextStageId);
600 'title' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:actionSendToStage'),
604 'bodyStyle' => 'margin-bottom: 7px; border: none;',
605 'html' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.itemsWillBeSentTo') . ' ' . $stageTitle
609 switch ($nextStageId) {
610 case \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_PUBLISH_EXECUTE_ID
:
612 case \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_PUBLISH_ID
:
613 if (!empty($workspaceRec['publish_allow_notificaton_settings'])) {
614 $showNotificationFields = TRUE
;
617 case \TYPO3\CMS\Workspaces\Service\StagesService
::STAGE_EDIT_ID
:
618 if (!empty($workspaceRec['edit_allow_notificaton_settings'])) {
619 $showNotificationFields = TRUE
;
623 $allow_notificaton_settings = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($nextStageId, 'allow_notificaton_settings');
624 if (!empty($allow_notificaton_settings)) {
625 $showNotificationFields = TRUE
;
628 if ($showNotificationFields == TRUE
) {
629 $result['items'][] = array(
630 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.sendMailTo'),
631 'xtype' => 'checkboxgroup',
632 'itemCls' => 'x-check-group-alt',
634 'style' => 'max-height: 200px',
635 'autoScroll' => TRUE
,
637 $this->getReceipientsOfStage($nextStageId)
640 $result['items'][] = array(
641 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.additionalRecipients'),
642 'name' => 'additional',
643 'xtype' => 'textarea',
647 $result['items'][] = array(
648 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.comments'),
649 'name' => 'comments',
650 'xtype' => 'textarea',
652 'value' => $this->getDefaultCommentOfStage($nextStageId)
658 * Gets all assigned recipients of a particular stage.
660 * @param integer $stage
663 protected function getReceipientsOfStage($stage) {
665 $recipients = $this->getStageService()->getResponsibleBeUser($stage);
666 $default_recipients = $this->getStageService()->getResponsibleBeUser($stage, TRUE
);
667 foreach ($recipients as $id => $user) {
668 if (GeneralUtility
::validEmail($user['email'])) {
671 $name = $user['realName'] ?
$user['realName'] : $user['username'];
672 // the notification mode can be configured in the workspace stage record
673 $notification_mode = (int)$this->getStageService()->getNotificationMode($stage);
674 if ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService
::MODE_NOTIFY_SOMEONE
) {
675 // all responsible users are checked per default, as in versions before
677 } elseif ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService
::MODE_NOTIFY_ALL
) {
678 // the default users are checked only
679 if (!empty($default_recipients[$id])) {
685 } elseif ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService
::MODE_NOTIFY_ALL_STRICT
) {
686 // all responsible users are checked
691 'boxLabel' => sprintf('%s (%s)', $name, $user['email']),
692 'name' => 'receipients-' . $id,
693 'checked' => $checked,
694 'disabled' => $disabled
702 * Gets the default comment of a particular stage.
704 * @param integer $stage
707 protected function getDefaultCommentOfStage($stage) {
708 $result = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
713 * Gets an instance of the Stage service.
715 * @return \TYPO3\CMS\Workspaces\Service\StagesService
717 protected function getStageService() {
718 if (!isset($this->stageService
)) {
719 $this->stageService
= GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
721 return $this->stageService
;
725 * Send all available workspace records to the previous stage.
727 * @param integer $id Current page id to process items to previous stage.
729 * @author Michael Klapper <development@morphodo.com>
731 public function sendPageToPreviousStage($id) {
732 $workspaceService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
733 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService
->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
734 list($currentStage, $previousStage) = $this->getStageService()->getPreviousStageForElementCollection($workspaceItemsArray);
735 // get only the relevant items for processing
736 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService
->getWorkspaceId(), ($filter = 1), $currentStage['uid'], $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
738 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $previousStage['title'],
739 'items' => $this->getSentToStageWindow($previousStage['uid']),
740 'affects' => $workspaceItemsArray,
741 'stageId' => $previousStage['uid']
746 * @param integer $id Current Page id to select Workspace items from.
748 * @author Michael Klapper <development@morphodo.com>
750 public function sendPageToNextStage($id) {
751 $workspaceService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
752 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService
->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
753 list($currentStage, $nextStage) = $this->getStageService()->getNextStageForElementCollection($workspaceItemsArray);
754 // get only the relevant items for processing
755 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService
->getWorkspaceId(), ($filter = 1), $currentStage['uid'], $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
757 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $nextStage['title'],
758 'items' => $this->getSentToStageWindow($nextStage['uid']),
759 'affects' => $workspaceItemsArray,
760 'stageId' => $nextStage['uid']
765 * Fetch the current label and visible state of the buttons.
768 * @return array Contains the visibility state and label of the stage change buttons.
769 * @author Michael Klapper <development@morphodo.com>
771 public function updateStageChangeButtons($id) {
772 $stageService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
773 $workspaceService = GeneralUtility
::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
774 // fetch the next and previous stage
775 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
776 list(, $nextStage) = $stageService->getNextStageForElementCollection($workspaceItemsArray);
777 list(, $previousStage) = $stageService->getPreviousStageForElementCollection($workspaceItemsArray);
778 $toolbarButtons = array(
779 'feToolbarButtonNextStage' => array(
780 'visible' => is_array($nextStage) && count($nextStage) > 0,
781 'text' => $nextStage['title']
783 'feToolbarButtonPreviousStage' => array(
784 'visible' => is_array($previousStage) && count($previousStage),
785 'text' => $previousStage['title']
787 'feToolbarButtonDiscardStage' => array(
788 'visible' => is_array($nextStage) && count($nextStage) > 0 ||
is_array($previousStage) && count($previousStage) > 0,
789 'text' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', TRUE
)
792 return $toolbarButtons;
796 * @param integer $workspaceId
797 * @return integer Id of the original workspace
798 * @throws \TYPO3\CMS\Core\Exception
800 protected function setTemporaryWorkspace($workspaceId) {
801 $workspaceId = (int)$workspaceId;
802 $currentWorkspace = (int)$this->getBackendUser()->workspace
;
804 if ($currentWorkspace !== $workspaceId) {
805 if (!$this->getBackendUser()->setTemporaryWorkspace($workspaceId)) {
806 throw new \TYPO3\CMS\Core\
Exception(
807 'Cannot set temporary workspace to "' . $workspaceId . '"',
813 return $currentWorkspace;
817 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
819 protected function getBackendUser() {
820 return $GLOBALS['BE_USER'];