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