d2e3c25bba4e3bfa05abc974c916b52163c1dbef
[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 void
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 $recipients[] = $beUserRecord['email'];
236 }
237 }
238
239 // the notification mode can be configured in the workspace stage record
240 $notification_mode = $this->getStageService()->getNotificationMode($stageId);
241 if (intval($notification_mode) === Tx_Workspaces_Service_Stages::MODE_NOTIFY_ALL || intval($notification_mode) === Tx_Workspaces_Service_Stages::MODE_NOTIFY_ALL_STRICT) {
242 // get the default recipients from the stage configuration
243 // the default recipients needs to be added in some cases of the notification_mode
244 $default_recipients = $this->getStageService()->getResponsibleBeUser($stageId, TRUE);
245 foreach ($default_recipients as $default_recipient_uid => $default_recipient_record) {
246 if (!in_array($default_recipient_record['email'],$recipients)) {
247 $recipients[] = $default_recipient_record['email'];
248 }
249 }
250 }
251
252 if ($additionalRecipients != '') {
253 $additionalRecipients = t3lib_div::trimExplode("\n", $additionalRecipients, TRUE);
254 } else {
255 $additionalRecipients = array();
256 }
257
258 $allRecipients = array_unique(
259 array_merge($recipients, $additionalRecipients)
260 );
261
262 foreach ($allRecipients as $recipient) {
263 if (t3lib_div::validEmail($recipient)) {
264 $finalRecipients[] = $recipient;
265 }
266 }
267
268 return $finalRecipients;
269 }
270
271 /**
272 * Discard all items from given page id.
273 *
274 * @param integer $pageId
275 * @return array
276 *
277 * @author Michael Klapper <development@morphodo.com>
278 */
279 public function discardStagesFromPage($pageId) {
280 $cmdMapArray = array();
281 /** @var $workspaceService tx_Workspaces_Service_Workspaces */
282 $workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
283 /** @var $stageService Tx_Workspaces_Service_Stages */
284 $stageService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
285 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), $filter = 1, $stage = -99, $pageId, $recursionLevel = 0, $selectionType = 'tables_modify');
286
287 foreach ($workspaceItemsArray as $tableName => $items) {
288 foreach ($items as $item) {
289 $cmdMapArray[$tableName][$item['uid']]['version']['action'] = 'clearWSID';
290 }
291 }
292
293 $this->processTcaCmd($cmdMapArray);
294
295 return array (
296 'success' => TRUE,
297 );
298 }
299
300 /**
301 * Push the given element collection to the next workspace stage.
302 *
303 * <code>
304 * $parameters->additional = your@mail.com
305 * $parameters->affects->__TABLENAME__
306 * $parameters->comments
307 * $parameters->receipients
308 * $parameters->stageId
309 * </code>
310 *
311 * @param stdClass $parameters
312 * @return array
313 *
314 * @author Michael Klapper <development@morphodo.com>
315 */
316 public function sentCollectionToStage(stdClass $parameters) {
317 $cmdMapArray = array();
318 $comment = $parameters->comments;
319 $stageId = $parameters->stageId;
320 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional);
321
322 if (t3lib_div::testInt($stageId) === FALSE) {
323 throw new InvalidArgumentException('Missing "stageId" in $parameters array.');
324 }
325
326 if (! is_array($parameters->affects) && count($parameters->affects) == 0) {
327 throw new InvalidArgumentException('Missing "affected items" in $parameters array.');
328 }
329 foreach ($parameters->affects as $tableName => $items) {
330 foreach ($items as $item) {
331 if ($stageId == Tx_Workspaces_Service_Stages::STAGE_PUBLISH_EXECUTE_ID) {
332 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['action'] = 'swap';
333 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['swapWith'] = $item->uid;
334 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['comment'] = $comment;
335 $cmdMapArray[$tableName][$item->t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
336 } else {
337 $cmdMapArray[$tableName][$item->uid]['version']['action'] = 'setStage';
338 $cmdMapArray[$tableName][$item->uid]['version']['stageId'] = $stageId;
339 $cmdMapArray[$tableName][$item->uid]['version']['comment'] = $comment;
340 $cmdMapArray[$tableName][$item->uid]['version']['notificationAlternativeRecipients'] = $recipients;
341 }
342 }
343 }
344
345 $this->processTcaCmd($cmdMapArray);
346
347 return array (
348 'success' => TRUE,
349 // force refresh after publishing changes
350 'refreshLivePanel' => ($parameters->stageId == -20) ? TRUE : FALSE
351 );
352 }
353
354 /**
355 * Process TCA command map array.
356 *
357 * @param array $cmdMapArray
358 * @return void
359 *
360 * @author Michael Klapper <development@morphodo.com>
361 */
362 protected function processTcaCmd(array $cmdMapArray) {
363 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
364 $tce->start(array(), $cmdMapArray);
365 $tce->process_cmdmap();
366 }
367
368 /**
369 * Gets an object with this structure:
370 *
371 * affects: object
372 * table
373 * t3ver_oid
374 * nextStage
375 * uid
376 * receipients: array with uids
377 * additional: string
378 * comments: string
379 *
380 * @param stdObject $parameters
381 * @return array
382 */
383 public function sendToNextStageExecute(stdClass $parameters) {
384 $cmdArray = array();
385 $recipients = array();
386
387 $setStageId = $parameters->affects->nextStage;
388 $comments = $parameters->comments;
389 $table = $parameters->affects->table;
390 $uid = $parameters->affects->uid;
391 $t3ver_oid = $parameters->affects->t3ver_oid;
392 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
393
394 if ($setStageId == Tx_Workspaces_Service_Stages::STAGE_PUBLISH_EXECUTE_ID) {
395 $cmdArray[$table][$t3ver_oid]['version']['action'] = 'swap';
396 $cmdArray[$table][$t3ver_oid]['version']['swapWith'] = $uid;
397 $cmdArray[$table][$t3ver_oid]['version']['comment'] = $comments;
398 $cmdArray[$table][$t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
399 } else {
400 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
401 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
402 $cmdArray[$table][$uid]['version']['comment'] = $comments;
403 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
404 }
405
406 $this->processTcaCmd($cmdArray);
407
408 $result = array(
409 'success' => TRUE,
410 );
411
412 return $result;
413 }
414
415 /**
416 * Gets an object with this structure:
417 *
418 * affects: object
419 * table
420 * t3ver_oid
421 * nextStage
422 * receipients: array with uids
423 * additional: string
424 * comments: string
425 *
426 * @param stdObject $parameters
427 * @return array
428 */
429 public function sendToPrevStageExecute(stdClass $parameters) {
430 $cmdArray = array();
431 $recipients = array();
432
433 $setStageId = $parameters->affects->nextStage;
434 $comments = $parameters->comments;
435 $table = $parameters->affects->table;
436 $uid = $parameters->affects->uid;
437 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
438
439 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
440 $cmdArray[$table][$uid]['version']['stageId'] = $setStageId;
441 $cmdArray[$table][$uid]['version']['comment'] = $comments;
442 $cmdArray[$table][$uid]['version']['notificationAlternativeRecipients'] = $recipients;
443
444 $this->processTcaCmd($cmdArray);
445
446 $result = array(
447 'success' => TRUE,
448 );
449
450 return $result;
451 }
452
453 /**
454 * Gets an object with this structure:
455 *
456 * affects: object
457 * elements: array
458 * 0: object
459 * table
460 * t3ver_oid
461 * uid
462 * 1: object
463 * table
464 * t3ver_oid
465 * uid
466 * nextStage
467 * receipients: array with uids
468 * additional: string
469 * comments: string
470 *
471 * @param stdObject $parameters
472 * @return array
473 */
474 public function sendToSpecificStageExecute(stdClass $parameters) {
475 $cmdArray = array();
476
477 $setStageId = $parameters->affects->nextStage;
478 $comments = $parameters->comments;
479 $elements = $parameters->affects->elements;
480 $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $setStageId);
481
482 foreach($elements as $key=>$element) {
483 if ($setStageId == Tx_Workspaces_Service_Stages::STAGE_PUBLISH_EXECUTE_ID) {
484 $cmdArray[$element->table][$element->t3ver_oid]['version']['action'] = 'swap';
485 $cmdArray[$element->table][$element->t3ver_oid]['version']['swapWith'] = $element->uid;
486 $cmdArray[$element->table][$element->t3ver_oid]['version']['comment'] = $comments;
487 $cmdArray[$element->table][$element->t3ver_oid]['version']['notificationAlternativeRecipients'] = $recipients;
488 } else {
489 $cmdArray[$element->table][$element->uid]['version']['action'] = 'setStage';
490 $cmdArray[$element->table][$element->uid]['version']['stageId'] = $setStageId;
491 $cmdArray[$element->table][$element->uid]['version']['comment'] = $comments;
492 $cmdArray[$element->table][$element->uid]['version']['notificationAlternativeRecipients'] = $recipients;
493 }
494 }
495
496 $this->processTcaCmd($cmdArray);
497
498 $result = array(
499 'success' => TRUE,
500 );
501
502 return $result;
503 }
504
505 /**
506 * Gets the dialog window to be displayed before a record can be sent to a stage.
507 *
508 * @param $nextStageId
509 * @return array
510 */
511 protected function getSentToStageWindow($nextStageId) {
512 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getStageService()->getWorkspaceId());
513 $showNotificationFields = FALSE;
514 $stageTitle = $this->getStageService()->getStageTitle($nextStageId);
515 $result = array(
516 'title' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:actionSendToStage'),
517 'items' => array(
518 array(
519 'xtype' => 'panel',
520 'bodyStyle' => 'margin-bottom: 7px; border: none;',
521 'html' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.itemsWillBeSentTo') . ' ' . $stageTitle,
522 )
523 )
524 );
525
526 switch ($nextStageId) {
527 case Tx_Workspaces_Service_Stages::STAGE_PUBLISH_EXECUTE_ID:
528 case Tx_Workspaces_Service_Stages::STAGE_PUBLISH_ID:
529 if (!empty($workspaceRec['publish_allow_notificaton_settings'])) {
530 $showNotificationFields = TRUE;
531 }
532 break;
533 case Tx_Workspaces_Service_Stages::STAGE_EDIT_ID:
534 if (!empty($workspaceRec['edit_allow_notificaton_settings'])) {
535 $showNotificationFields = TRUE;
536 }
537 break;
538 default:
539 $allow_notificaton_settings = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($nextStageId, 'allow_notificaton_settings');
540 if (!empty($allow_notificaton_settings)) {
541 $showNotificationFields = TRUE;
542 }
543 break;
544 }
545
546 if ($showNotificationFields == TRUE) {
547 $result['items'][] = array(
548 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.sendMailTo'),
549 'xtype' => 'checkboxgroup',
550 'itemCls' => 'x-check-group-alt',
551 'columns' => 1,
552 'style' => 'max-height: 200px',
553 'autoScroll' => TRUE,
554 'items' => array(
555 $this->getReceipientsOfStage($nextStageId)
556 )
557 );
558
559 $result['items'][] = array(
560 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.additionalRecipients'),
561 'name' => 'additional',
562 'xtype' => 'textarea',
563 'width' => 250,
564 );
565 }
566
567 $result['items'][] = array(
568 'fieldLabel' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:window.sendToNextStageWindow.comments'),
569 'name' => 'comments',
570 'xtype' => 'textarea',
571 'width' => 250,
572 'value' => $this->getDefaultCommentOfStage($nextStageId),
573 );
574
575 return $result;
576 }
577
578 /**
579 * Gets all assigned recipients of a particular stage.
580 *
581 * @param integer $stage
582 * @return array
583 */
584 protected function getReceipientsOfStage($stage) {
585 $result = array();
586
587 $recipients = $this->getStageService()->getResponsibleBeUser($stage);
588 $default_recipients = $this->getStageService()->getResponsibleBeUser($stage, TRUE);
589
590 foreach ($recipients as $id => $user) {
591 if (t3lib_div::validEmail($user['email'])) {
592 $checked = FALSE;
593 $disabled = FALSE;
594 $name = $user['realName'] ? $user['realName'] : $user['username'];
595
596 // the notification mode can be configured in the workspace stage record
597 $notification_mode = $this->getStageService()->getNotificationMode($stage);
598 if (intval($notification_mode) === Tx_Workspaces_Service_Stages::MODE_NOTIFY_SOMEONE) {
599 // all responsible users are checked per default, as in versions before
600 $checked = TRUE;
601 } elseif (intval($notification_mode) === Tx_Workspaces_Service_Stages::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 (intval($notification_mode) === Tx_Workspaces_Service_Stages::MODE_NOTIFY_ALL_STRICT) {
610 // all responsible users are checked
611 $checked = TRUE;
612 $disabled = TRUE;
613 }
614
615 $result[] = array(
616 'boxLabel' => sprintf('%s (%s)', $name, $user['email']),
617 'name' => 'receipients-' . $id,
618 'checked' => $checked,
619 'disabled' => $disabled,
620 );
621 }
622 }
623
624 return $result;
625 }
626
627 /**
628 * Gets the default comment of a particular stage.
629 *
630 * @param integer $stage
631 * @return string
632 */
633 protected function getDefaultCommentOfStage($stage) {
634 $result = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
635
636 return $result;
637 }
638
639 /**
640 * Gets an instance of the Stage service.
641 *
642 * @return Tx_Workspaces_Service_Stages
643 */
644 protected function getStageService() {
645 if (!isset($this->stageService)) {
646 $this->stageService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
647 }
648 return $this->stageService;
649 }
650
651 /**
652 * Send all available workspace records to the previous stage.
653 *
654 * @param integer $id Current page id to process items to previous stage.
655 * @return array
656 *
657 * @author Michael Klapper <development@morphodo.com>
658 */
659 public function sendPageToPreviousStage($id) {
660 $workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
661 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), $filter = 1, $stage = -99, $id, $recursionLevel = 0, $selectionType = 'tables_modify');
662 list($currentStage, $previousStage) = $this->getStageService()->getPreviousStageForElementCollection($workspaceItemsArray);
663
664 // get only the relevant items for processing
665 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), $filter = 1, $currentStage['uid'], $id, $recursionLevel = 0, $selectionType = 'tables_modify');
666
667 return array (
668 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $previousStage['title'],
669 'items' => $this->getSentToStageWindow($previousStage['uid']),
670 'affects' => $workspaceItemsArray,
671 'stageId' => $previousStage['uid'],
672 );
673 }
674
675 /**
676 *
677 * @param integer $id Current Page id to select Workspace items from.
678 *
679 * @return array
680 *
681 * @author Michael Klapper <development@morphodo.com>
682 */
683 public function sendPageToNextStage($id) {
684 $workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
685 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), $filter = 1, $stage = -99, $id, $recursionLevel = 0, $selectionType = 'tables_modify');
686 list($currentStage, $nextStage) = $this->getStageService()->getNextStageForElementCollection($workspaceItemsArray);
687 // get only the relevant items for processing
688 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), $filter = 1, $currentStage['uid'], $id, $recursionLevel = 0, $selectionType = 'tables_modify');
689
690 return array (
691 'title' => 'Status message: Page send to next stage - ID: ' . $id . ' - Next stage title: ' . $nextStage['title'],
692 'items' => $this->getSentToStageWindow($nextStage['uid']),
693 'affects' => $workspaceItemsArray,
694 'stageId' => $nextStage['uid'],
695 );
696 }
697
698 /**
699 * Fetch the current label and visible state of the buttons.
700 *
701 * @param integer $id
702 * @return array Contains the visibility state and label of the stage change buttons.
703 *
704 * @author Michael Klapper <development@morphodo.com>
705 */
706 public function updateStageChangeButtons($id) {
707
708 $stageService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
709 $workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
710
711 // fetch the next and previous stage
712 $workspaceItemsArray = $workspaceService->selectVersionsInWorkspace($stageService->getWorkspaceId(), $filter = 1, $stage = -99, $id, $recursionLevel = 0, $selectionType = 'tables_modify');
713 list(, $nextStage) = $stageService->getNextStageForElementCollection($workspaceItemsArray);
714 list(, $previousStage) = $stageService->getPreviousStageForElementCollection($workspaceItemsArray);
715
716 $toolbarButtons = array(
717 'feToolbarButtonNextStage' => array(
718 'visible' => is_array($nextStage) && count($nextStage) > 0,
719 'text' => $nextStage['title'],
720 ),
721 'feToolbarButtonPreviousStage' => array(
722 'visible' => is_array($previousStage) && count($previousStage),
723 'text' => $previousStage['title'],
724 ),
725 'feToolbarButtonDiscardStage' => array(
726 'visible' => (is_array($nextStage) && count($nextStage) > 0) || (is_array($previousStage) && count($previousStage) > 0),
727 'text' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:label_doaction_discard', TRUE),
728 ),
729 );
730
731 return $toolbarButtons;
732 }
733 }
734
735
736 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/ActionHandler.php'])) {
737 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/ExtDirect/ActionHandler.php']);
738 }
739 ?>