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