[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / ActionHandler.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\ExtDirect;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19
20 /**
21 * ExtDirect action handler
22 *
23 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
24 */
25 class ActionHandler extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler {
26
27 /**
28 * @var \TYPO3\CMS\Workspaces\Service\StagesService
29 */
30 protected $stageService;
31
32 /**
33 * Creates this object.
34 */
35 public function __construct() {
36 $this->stageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
37 }
38
39 /**
40 * Generates a workspace preview link.
41 *
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 '/'
44 */
45 public function generateWorkspacePreviewLink($uid) {
46 return $this->getWorkspaceService()->generateWorkspacePreviewLink($uid);
47 }
48
49 /**
50 * Swaps a single record.
51 *
52 * @param string $table
53 * @param integer $t3ver_oid
54 * @param integer $orig_uid
55 * @return void
56 * @todo What about reporting errors back to the ExtJS interface? /olly/
57 */
58 public function swapSingleRecord($table, $t3ver_oid, $orig_uid) {
59 $versionRecord = BackendUtility::getRecord($table, $orig_uid);
60 $currentWorkspace = $this->setTemporaryWorkspace($versionRecord['t3ver_wsid']);
61
62 $cmd[$table][$t3ver_oid]['version'] = array(
63 'action' => 'swap',
64 'swapWith' => $orig_uid,
65 'swapIntoWS' => 1
66 );
67 $this->processTcaCmd($cmd);
68
69 $this->setTemporaryWorkspace($currentWorkspace);
70 }
71
72 /**
73 * Deletes a single record.
74 *
75 * @param string $table
76 * @param integer $uid
77 * @return void
78 * @todo What about reporting errors back to the ExtJS interface? /olly/
79 */
80 public function deleteSingleRecord($table, $uid) {
81 $versionRecord = BackendUtility::getRecord($table, $uid);
82 $currentWorkspace = $this->setTemporaryWorkspace($versionRecord['t3ver_wsid']);
83
84 $cmd[$table][$uid]['version'] = array(
85 'action' => 'clearWSID'
86 );
87 $this->processTcaCmd($cmd);
88
89 $this->setTemporaryWorkspace($currentWorkspace);
90 }
91
92 /**
93 * Generates a view link for a page.
94 *
95 * @param string $table
96 * @param string $uid
97 * @return string
98 */
99 public function viewSingleRecord($table, $uid) {
100 return \TYPO3\CMS\Workspaces\Service\WorkspaceService::viewSingleRecord($table, $uid);
101 }
102
103 /**
104 * Saves the selected columns to be shown to the preferences of the current backend user.
105 *
106 * @param object $model
107 * @return void
108 */
109 public function saveColumnModel($model) {
110 $data = array();
111 foreach ($model as $column) {
112 $data[$column->column] = array(
113 'position' => $column->position,
114 'hidden' => $column->hidden
115 );
116 }
117 $GLOBALS['BE_USER']->uc['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace]['columns'] = $data;
118 $GLOBALS['BE_USER']->writeUC();
119 }
120
121 public function loadColumnModel() {
122 if (is_array($GLOBALS['BE_USER']->uc['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace]['columns'])) {
123 return $GLOBALS['BE_USER']->uc['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace]['columns'];
124 } else {
125 return array();
126 }
127 }
128
129 /**
130 * Saves the selected language.
131 *
132 * @param integer|string $language
133 * @return void
134 */
135 public function saveLanguageSelection($language) {
136 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($language) === FALSE && $language !== 'all') {
137 $language = 'all';
138 }
139 $GLOBALS['BE_USER']->uc['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace]['language'] = $language;
140 $GLOBALS['BE_USER']->writeUC();
141 }
142
143 /**
144 * Gets the dialog window to be displayed before a record can be sent to the next stage.
145 *
146 * @param integer $uid
147 * @param string $table
148 * @param integer $t3ver_oid
149 * @return array
150 */
151 public function sendToNextStageWindow($uid, $table, $t3ver_oid) {
152 $elementRecord = BackendUtility::getRecord($table, $uid);
153 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
154
155 if (is_array($elementRecord)) {
156 $stageId = $elementRecord['t3ver_stage'];
157 if ($this->getStageService()->isValid($stageId)) {
158 $nextStage = $this->getStageService()->getNextStage($stageId);
159 $result = $this->getSentToStageWindow($nextStage['uid']);
160 $result['affects'] = array(
161 'table' => $table,
162 'nextStage' => $nextStage['uid'],
163 't3ver_oid' => $t3ver_oid,
164 'uid' => $uid
165 );
166 } else {
167 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
168 }
169 } else {
170 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264776);
171 }
172
173 $this->setTemporaryWorkspace($currentWorkspace);
174 return $result;
175 }
176
177 /**
178 * Gets the dialog window to be displayed before a record can be sent to the previous stage.
179 *
180 * @param integer $uid
181 * @param string $table
182 * @return array
183 */
184 public function sendToPrevStageWindow($uid, $table) {
185 $elementRecord = BackendUtility::getRecord($table, $uid);
186 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
187
188 if (is_array($elementRecord)) {
189 $stageId = $elementRecord['t3ver_stage'];
190 if ($this->getStageService()->isValid($stageId)) {
191 if ($stageId !== \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID) {
192 $prevStage = $this->getStageService()->getPrevStage($stageId);
193 $result = $this->getSentToStageWindow($prevStage['uid']);
194 $result['affects'] = array(
195 'table' => $table,
196 'uid' => $uid,
197 'nextStage' => $prevStage['uid']
198 );
199 } else {
200 // element is already in edit stage, there is no prev stage - return an error message
201 $result = $this->getErrorResponse('error.sendToPrevStage.noPreviousStage', 1287264746);
202 }
203 } else {
204 $result = $this->getErrorResponse('error.stageId.invalid', 1291111644);
205 }
206 } else {
207 $result = $this->getErrorResponse('error.sendToNextStage.noRecordFound', 1287264765);
208 }
209
210 $this->setTemporaryWorkspace($currentWorkspace);
211 return $result;
212 }
213
214 /**
215 * Gets the dialog window to be displayed before a record can be sent to a specific stage.
216 *
217 * @param integer $nextStageId
218 * @return array
219 */
220 public function sendToSpecificStageWindow($nextStageId) {
221 $result = $this->getSentToStageWindow($nextStageId);
222 $result['affects'] = array(
223 'nextStage' => $nextStageId
224 );
225 return $result;
226 }
227
228 /**
229 * Gets a merged variant of recipient defined by uid and custom ones.
230 *
231 * @param array list of recipients
232 * @param string given user string of additional recipients
233 * @param integer stage id
234 * @return array
235 */
236 public function getRecipientList(array $uidOfRecipients, $additionalRecipients, $stageId) {
237 $finalRecipients = array();
238 if (!$this->getStageService()->isValid($stageId)) {
239 throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:error.stageId.integer'));
240 } else {
241 $stageId = (int)$stageId;
242 }
243 $recipients = array();
244 foreach ($uidOfRecipients as $userUid) {
245 $beUserRecord = BackendUtility::getRecord('be_users', (int)$userUid);
246 if (is_array($beUserRecord) && $beUserRecord['email'] !== '') {
247 $uc = $beUserRecord['uc'] ? unserialize($beUserRecord['uc']) : array();
248 $recipients[$beUserRecord['email']] = array(
249 'email' => $beUserRecord['email'],
250 'lang' => isset($uc['lang']) ? $uc['lang'] : $beUserRecord['lang']
251 );
252 }
253 }
254 // the notification mode can be configured in the workspace stage record
255 $notification_mode = (int)$this->getStageService()->getNotificationMode($stageId);
256 if ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService::MODE_NOTIFY_ALL || $notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService::MODE_NOTIFY_ALL_STRICT) {
257 // get the default recipients from the stage configuration
258 // the default recipients needs to be added in some cases of the notification_mode
259 $default_recipients = $this->getStageService()->getResponsibleBeUser($stageId, TRUE);
260 foreach ($default_recipients as $default_recipient_uid => $default_recipient_record) {
261 if (!isset($recipients[$default_recipient_record['email']])) {
262 $uc = $default_recipient_record['uc'] ? unserialize($default_recipient_record['uc']) : array();
263 $recipients[$default_recipient_record['email']] = array(
264 'email' => $default_recipient_record['email'],
265 'lang' => isset($uc['lang']) ? $uc['lang'] : $default_recipient_record['lang']
266 );
267 }
268 }
269 }
270 if ($additionalRecipients !== '') {
271 $emails = GeneralUtility::trimExplode(LF, $additionalRecipients, TRUE);
272 $additionalRecipients = array();
273 foreach ($emails as $email) {
274 $additionalRecipients[$email] = array('email' => $email);
275 }
276 } else {
277 $additionalRecipients = array();
278 }
279 // We merge $recipients on top of $additionalRecipients because $recipients
280 // possibly is more complete with a user language. Furthermore, the list of
281 // recipients is automatically unique since we indexed $additionalRecipients
282 // and $recipients with the email address
283 $allRecipients = array_merge($additionalRecipients, $recipients);
284 foreach ($allRecipients as $email => $recipientInformation) {
285 if (GeneralUtility::validEmail($email)) {
286 $finalRecipients[] = $recipientInformation;
287 }
288 }
289 return $finalRecipients;
290 }
291
292 /**
293 * Discard all items from given page id.
294 *
295 * @param integer $pageId
296 * @return array
297 * @author Michael Klapper <development@morphodo.com>
298 */
299 public function discardStagesFromPage($pageId) {
300 $cmdMapArray = array();
301 /** @var $workspaceService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
302 $workspaceService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
303 /** @var $stageService \TYPO3\CMS\Workspaces\Service\StagesService */
304 $stageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
305 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
306 foreach ($workspaceItemsArray as $tableName => $items) {
307 foreach ($items as $item) {
308 $cmdMapArray[$tableName][$item['uid']]['version']['action'] = 'clearWSID';
309 }
310 }
311 $this->processTcaCmd($cmdMapArray);
312 return array(
313 'success' => TRUE
314 );
315 }
316
317 /**
318 * Push the given element collection to the next workspace stage.
319 *
320 * <code>
321 * $parameters->additional = your@mail.com
322 * $parameters->affects->__TABLENAME__
323 * $parameters->comments
324 * $parameters->receipients
325 * $parameters->stageId
326 * </code>
327 *
328 * @param stdClass $parameters
329 * @return array
330 * @author Michael Klapper <development@morphodo.com>
331 */
332 public function sentCollectionToStage(\stdClass $parameters) {
333 $cmdMapArray = array();
334 $comment = $parameters->comments;
335 $stageId = $parameters->stageId;
336 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($stageId) === FALSE) {
337 throw new \InvalidArgumentException('Missing "stageId" in $parameters array.', 1319488194);
338 }
339 if (!is_object($parameters->affects) || count($parameters->affects) == 0) {
340 throw new \InvalidArgumentException('Missing "affected items" in $parameters array.', 1319488195);
341 }
342 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $stageId);
343 foreach ($parameters->affects as $tableName => $items) {
344 foreach ($items as $item) {
345 // Publishing uses live id in command map
346 if ($stageId == \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_EXECUTE_ID) {
347 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['action'] = 'swap';
348 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['swapWith'] = $item->uid;
349 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['comment'] = $comment;
350 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
351 // Setting stage uses version id in command map
352 } else {
353 $cmdMapArray[$tableName][$item->uid]['version']['action'] = 'setStage';
354 $cmdMapArray[$tableName][$item->uid]['version']['stageId'] = $stageId;
355 $cmdMapArray[$tableName][$item->uid]['version']['comment'] = $comment;
356 $cmdMapArray[$tableName][$item->uid]['version']['notificationAlternativeRecipients'] = $recipients;
357 }
358 }
359 }
360 $this->processTcaCmd($cmdMapArray);
361 return array(
362 'success' => TRUE,
363 // force refresh after publishing changes
364 'refreshLivePanel' => $parameters->stageId == -20 ? TRUE : FALSE
365 );
366 }
367
368 /**
369 * Process TCA command map array.
370 *
371 * @param array $cmdMapArray
372 * @return void
373 * @author Michael Klapper <development@morphodo.com>
374 */
375 protected function processTcaCmd(array $cmdMapArray) {
376 $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
377 $tce->start(array(), $cmdMapArray);
378 $tce->process_cmdmap();
379 }
380
381 /**
382 * Gets an object with this structure:
383 *
384 * affects: object
385 * table
386 * t3ver_oid
387 * nextStage
388 * uid
389 * receipients: array with uids
390 * additional: string
391 * comments: string
392 *
393 * @param stdClass $parameters
394 * @return array
395 */
396 public function sendToNextStageExecute(\stdClass $parameters) {
397 $cmdArray = array();
398 $setStageId = $parameters->affects->nextStage;
399 $comments = $parameters->comments;
400 $table = $parameters->affects->table;
401 $uid = $parameters->affects->uid;
402 $t3ver_oid = $parameters->affects->t3ver_oid;
403
404 $elementRecord = BackendUtility::getRecord($table, $uid);
405 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
406
407 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
408 if ($setStageId == \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_EXECUTE_ID) {
409 $cmdArray[$table][$t3ver_oid]['version']['action'] = 'swap';
410 $cmdArray[$table][$t3ver_oid]['version']['swapWith'] = $uid;
411 $cmdArray[$table][$t3ver_oid]['version']['comment'] = $comments;
412 $cmdArray[$table][$t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
413 } else {
414 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
415 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
416 $cmdArray[$table][$uid]['version']['comment'] = $comments;
417 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
418 }
419 $this->processTcaCmd($cmdArray);
420 $result = array(
421 'success' => TRUE
422 );
423
424 $this->setTemporaryWorkspace($currentWorkspace);
425 return $result;
426 }
427
428 /**
429 * Gets an object with this structure:
430 *
431 * affects: object
432 * table
433 * t3ver_oid
434 * nextStage
435 * receipients: array with uids
436 * additional: string
437 * comments: string
438 *
439 * @param stdClass $parameters
440 * @return array
441 */
442 public function sendToPrevStageExecute(\stdClass $parameters) {
443 $cmdArray = array();
444 $setStageId = $parameters->affects->nextStage;
445 $comments = $parameters->comments;
446 $table = $parameters->affects->table;
447 $uid = $parameters->affects->uid;
448
449 $elementRecord = BackendUtility::getRecord($table, $uid);
450 $currentWorkspace = $this->setTemporaryWorkspace($elementRecord['t3ver_wsid']);
451
452 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
453 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
454 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
455 $cmdArray[$table][$uid]['version']['comment'] = $comments;
456 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
457 $this->processTcaCmd($cmdArray);
458 $result = array(
459 'success' => TRUE
460 );
461
462 $this->setTemporaryWorkspace($currentWorkspace);
463 return $result;
464 }
465
466 /**
467 * Gets an object with this structure:
468 *
469 * affects: object
470 * elements: array
471 * 0: object
472 * table
473 * t3ver_oid
474 * uid
475 * 1: object
476 * table
477 * t3ver_oid
478 * uid
479 * nextStage
480 * receipients: array with uids
481 * additional: string
482 * comments: string
483 *
484 * @param stdClass $parameters
485 * @return array
486 */
487 public function sendToSpecificStageExecute(\stdClass $parameters) {
488 $cmdArray = array();
489 $setStageId = $parameters->affects->nextStage;
490 $comments = $parameters->comments;
491 $elements = $parameters->affects->elements;
492 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
493 foreach ($elements as $key => $element) {
494 if ($setStageId == \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_EXECUTE_ID) {
495 $cmdArray[$element->table][$element->t3ver_oid]['version']['action'] = 'swap';
496 $cmdArray[$element->table][$element->t3ver_oid]['version']['swapWith'] = $element->uid;
497 $cmdArray[$element->table][$element->t3ver_oid]['version']['comment'] = $comments;
498 $cmdArray[$element->table][$element->t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
499 } else {
500 $cmdArray[$element->table][$element->uid]['version']['action'] = 'setStage';
501 $cmdArray[$element->table][$element->uid]['version']['stageId'] = $setStageId;
502 $cmdArray[$element->table][$element->uid]['version']['comment'] = $comments;
503 $cmdArray[$element->table][$element->uid]['version']['notificationAlternativeRecipients'] = $recipients;
504 }
505 }
506 $this->processTcaCmd($cmdArray);
507 $result = array(
508 'success' => TRUE
509 );
510 return $result;
511 }
512
513 /**
514 * Gets the dialog window to be displayed before a record can be sent to a stage.
515 *
516 * @param $nextStageId
517 * @return array
518 */
519 protected function getSentToStageWindow($nextStageId) {
520 $workspaceRec = BackendUtility::getRecord('sys_workspace', $this->getStageService()->getWorkspaceId());
521 $showNotificationFields = FALSE;
522 $stageTitle = $this->getStageService()->getStageTitle($nextStageId);
523 $result = array(
524 'title' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:actionSendToStage'),
525 'items' => array(
526 array(
527 'xtype' => 'panel',
528 'bodyStyle' => 'margin-bottom: 7px; border: none;',
529 'html' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.itemsWillBeSentTo') . ' ' . $stageTitle
530 )
531 )
532 );
533 switch ($nextStageId) {
534 case \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_EXECUTE_ID:
535
536 case \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_ID:
537 if (!empty($workspaceRec['publish_allow_notificaton_settings'])) {
538 $showNotificationFields = TRUE;
539 }
540 break;
541 case \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID:
542 if (!empty($workspaceRec['edit_allow_notificaton_settings'])) {
543 $showNotificationFields = TRUE;
544 }
545 break;
546 default:
547 $allow_notificaton_settings = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($nextStageId, 'allow_notificaton_settings');
548 if (!empty($allow_notificaton_settings)) {
549 $showNotificationFields = TRUE;
550 }
551 }
552 if ($showNotificationFields == TRUE) {
553 $result['items'][] = array(
554 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.sendMailTo'),
555 'xtype' => 'checkboxgroup',
556 'itemCls' => 'x-check-group-alt',
557 'columns' => 1,
558 'style' => 'max-height: 200px',
559 'autoScroll' => TRUE,
560 'items' => array(
561 $this->getReceipientsOfStage($nextStageId)
562 )
563 );
564 $result['items'][] = array(
565 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.additionalRecipients'),
566 'name' => 'additional',
567 'xtype' => 'textarea',
568 'width' => 250
569 );
570 }
571 $result['items'][] = array(
572 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.comments'),
573 'name' => 'comments',
574 'xtype' => 'textarea',
575 'width' => 250,
576 'value' => $this->getDefaultCommentOfStage($nextStageId)
577 );
578 return $result;
579 }
580
581 /**
582 * Gets all assigned recipients of a particular stage.
583 *
584 * @param integer $stage
585 * @return array
586 */
587 protected function getReceipientsOfStage($stage) {
588 $result = array();
589 $recipients = $this->getStageService()->getResponsibleBeUser($stage);
590 $default_recipients = $this->getStageService()->getResponsibleBeUser($stage, TRUE);
591 foreach ($recipients as $id => $user) {
592 if (GeneralUtility::validEmail($user['email'])) {
593 $checked = FALSE;
594 $disabled = FALSE;
595 $name = $user['realName'] ? $user['realName'] : $user['username'];
596 // the notification mode can be configured in the workspace stage record
597 $notification_mode = (int)$this->getStageService()->getNotificationMode($stage);
598 if ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService::MODE_NOTIFY_SOMEONE) {
599 // all responsible users are checked per default, as in versions before
600 $checked = TRUE;
601 } elseif ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService::MODE_NOTIFY_ALL) {
602 // the default users are checked only
603 if (!empty($default_recipients[$id])) {
604 $checked = TRUE;
605 $disabled = TRUE;
606 } else {
607 $checked = FALSE;
608 }
609 } elseif ($notification_mode === \TYPO3\CMS\Workspaces\Service\StagesService::MODE_NOTIFY_ALL_STRICT) {
610 // all responsible users are checked
611 $checked = TRUE;
612 $disabled = TRUE;
613 }
614 $result[] = array(
615 'boxLabel' => sprintf('%s (%s)', $name, $user['email']),
616 'name' => 'receipients-' . $id,
617 'checked' => $checked,
618 'disabled' => $disabled
619 );
620 }
621 }
622 return $result;
623 }
624
625 /**
626 * Gets the default comment of a particular stage.
627 *
628 * @param integer $stage
629 * @return string
630 */
631 protected function getDefaultCommentOfStage($stage) {
632 $result = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
633 return $result;
634 }
635
636 /**
637 * Gets an instance of the Stage service.
638 *
639 * @return \TYPO3\CMS\Workspaces\Service\StagesService
640 */
641 protected function getStageService() {
642 if (!isset($this->stageService)) {
643 $this->stageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
644 }
645 return $this->stageService;
646 }
647
648 /**
649 * Send all available workspace records to the previous stage.
650 *
651 * @param integer $id Current page id to process items to previous stage.
652 * @return array
653 * @author Michael Klapper <development@morphodo.com>
654 */
655 public function sendPageToPreviousStage($id) {
656 $workspaceService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
657 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
658 list($currentStage, $previousStage) = $this->getStageService()->getPreviousStageForElementCollection($workspaceItemsArray);
659 // get only the relevant items for processing
660 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), $currentStage['uid'], $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
661 return array(
662 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $previousStage['title'],
663 'items' => $this->getSentToStageWindow($previousStage['uid']),
664 'affects' => $workspaceItemsArray,
665 'stageId' => $previousStage['uid']
666 );
667 }
668
669 /**
670 * @param integer $id Current Page id to select Workspace items from.
671 * @return array
672 * @author Michael Klapper <development@morphodo.com>
673 */
674 public function sendPageToNextStage($id) {
675 $workspaceService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
676 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
677 list($currentStage, $nextStage) = $this->getStageService()->getNextStageForElementCollection($workspaceItemsArray);
678 // get only the relevant items for processing
679 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), $currentStage['uid'], $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
680 return array(
681 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $nextStage['title'],
682 'items' => $this->getSentToStageWindow($nextStage['uid']),
683 'affects' => $workspaceItemsArray,
684 'stageId' => $nextStage['uid']
685 );
686 }
687
688 /**
689 * Fetch the current label and visible state of the buttons.
690 *
691 * @param integer $id
692 * @return array Contains the visibility state and label of the stage change buttons.
693 * @author Michael Klapper <development@morphodo.com>
694 */
695 public function updateStageChangeButtons($id) {
696 $stageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
697 $workspaceService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
698 // fetch the next and previous stage
699 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $id, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
700 list(, $nextStage) = $stageService->getNextStageForElementCollection($workspaceItemsArray);
701 list(, $previousStage) = $stageService->getPreviousStageForElementCollection($workspaceItemsArray);
702 $toolbarButtons = array(
703 'feToolbarButtonNextStage' => array(
704 'visible' => is_array($nextStage) && count($nextStage) > 0,
705 'text' => $nextStage['title']
706 ),
707 'feToolbarButtonPreviousStage' => array(
708 'visible' => is_array($previousStage) && count($previousStage),
709 'text' => $previousStage['title']
710 ),
711 'feToolbarButtonDiscardStage' => array(
712 'visible' => is_array($nextStage) && count($nextStage) > 0 || is_array($previousStage) && count($previousStage) > 0,
713 'text' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', TRUE)
714 )
715 );
716 return $toolbarButtons;
717 }
718
719 /**
720 * @param integer $workspaceId
721 * @return integer Id of the original workspace
722 * @throws \TYPO3\CMS\Core\Exception
723 */
724 protected function setTemporaryWorkspace($workspaceId) {
725 $workspaceId = (int)$workspaceId;
726 $currentWorkspace = (int)$this->getBackendUser()->workspace;
727
728 if ($currentWorkspace !== $workspaceId) {
729 if (!$this->getBackendUser()->setTemporaryWorkspace($workspaceId)) {
730 throw new \TYPO3\CMS\Core\Exception(
731 'Cannot set temporary workspace to "' . $workspaceId . '"',
732 1371484524
733 );
734 }
735 }
736
737 return $currentWorkspace;
738 }
739
740 /**
741 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
742 */
743 protected function getBackendUser() {
744 return $GLOBALS['BE_USER'];
745 }
746
747 }