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