[TASK] Refactor core usages of testInt, calcPriority, calcParenthesis
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Service / Stages.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 Service
32 */
33
34 class Tx_Workspaces_Service_Stages {
35 const TABLE_STAGE = 'sys_workspace_stage';
36 // if a record is in the "ready to publish" stage STAGE_PUBLISH_ID the nextStage is STAGE_PUBLISH_EXECUTE_ID, this id wont be saved at any time in db
37 const STAGE_PUBLISH_EXECUTE_ID = -20;
38 // ready to publish stage
39 const STAGE_PUBLISH_ID = -10;
40 const STAGE_EDIT_ID = 0;
41 const MODE_NOTIFY_SOMEONE = 0;
42 const MODE_NOTIFY_ALL = 1;
43 const MODE_NOTIFY_ALL_STRICT = 2;
44
45 /**
46 * Current workspace ID
47 * @var integer
48 */
49 private $workspaceId = NULL;
50
51 /**
52 * Path to the locallang file
53 * @var string
54 */
55 private $pathToLocallang = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xml';
56
57 /**
58 * Local cache to reduce number of database queries for stages, groups, etc.
59 * @var array
60 */
61 protected $workspaceStageCache = array();
62
63 /**
64 * @var array
65 */
66 protected $workspaceStageAllowedCache = array();
67
68 /**
69 * @var array
70 */
71 protected $fetchGroupsCache = array();
72
73 /**
74 * @var array
75 */
76 protected $userGroups = array();
77
78 /**
79 * Getter for current workspace id
80 *
81 * @return int current workspace id
82 */
83 public function getWorkspaceId() {
84 if ($this->workspaceId == NULL) {
85 $this->setWorkspaceId($GLOBALS['BE_USER']->workspace);
86 }
87 return $this->workspaceId;
88 }
89
90 /**
91 * Setter for current workspace id
92 *
93 * @param int current workspace id
94 */
95 private function setWorkspaceId($wsid) {
96 $this->workspaceId = $wsid;
97 }
98
99 /**
100 * constructor for workspace library
101 *
102 * @param int current workspace id
103 */
104 public function __construct() {
105 $this->setWorkspaceId($GLOBALS['BE_USER']->workspace);
106 }
107
108 /**
109 * Building an array with all stage ids and titles related to the given workspace
110 *
111 * @return array id and title of the stages
112 */
113 public function getStagesForWS() {
114 $stages = array();
115
116 if (isset($this->workspaceStageCache[$this->getWorkspaceId()])) {
117 $stages = $this->workspaceStageCache[$this->getWorkspaceId()];
118 } else {
119 $stages[] = array(
120 'uid' => self::STAGE_EDIT_ID,
121 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing') . '"'
122 );
123
124 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
125 if ($workspaceRec['custom_stages'] > 0) {
126 // Get all stage records for this workspace
127 $workspaceStageRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
128 '*',
129 self::TABLE_STAGE,
130 'parentid=' . $this->getWorkspaceId() . ' AND parenttable=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('sys_workspace', self::TABLE_STAGE) . ' AND deleted=0',
131 '',
132 'sorting',
133 '',
134 'uid'
135 );
136 foreach($workspaceStageRecs as $stage) {
137 $stage['title'] = $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $stage['title'] . '"';
138 $stages[] = $stage;
139 }
140 }
141
142 $stages[] = array(
143 'uid' => self::STAGE_PUBLISH_ID,
144 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xml:stage_ready_to_publish') . '"'
145 );
146
147 $stages[] = array(
148 'uid' => self::STAGE_PUBLISH_EXECUTE_ID,
149 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':publish_execute_action_option')
150 );
151 $this->workspaceStageCache[$this->getWorkspaceId()] = $stages;
152 }
153
154 return $stages;
155 }
156
157 /**
158 * Returns an array of stages, the user is allowed to send to
159 * @return array id and title of stages
160 */
161 public function getStagesForWSUser() {
162
163 $stagesForWSUserData = array();
164 $allowedStages = array();
165 $orderedAllowedStages = array();
166
167 $workspaceStageRecs = $this->getStagesForWS();
168 if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
169 if ($GLOBALS['BE_USER']->isAdmin()) {
170 $orderedAllowedStages = $workspaceStageRecs;
171 } else {
172 foreach ($workspaceStageRecs as $workspaceStageRec) {
173 if ($this->isStageAllowedForUser($workspaceStageRec['uid'])) {
174 $stagesForWSUserData[$workspaceStageRec['uid']] = $workspaceStageRec;
175 } elseif ($workspaceStageRec['uid'] == self::STAGE_PUBLISH_EXECUTE_ID && $GLOBALS['BE_USER']->workspacePublishAccess($this->getWorkspaceId())) {
176 $allowedStages[] = $workspaceStageRec;
177 $stagesForWSUserData[$workspaceStageRec['uid']] = $workspaceStageRec;
178 }
179 }
180
181 foreach ($stagesForWSUserData as $allowedStage) {
182 $nextStage = $this->getNextStage($allowedStage['uid']);
183 $prevStage = $this->getPrevStage($allowedStage['uid']);
184 if (isset($nextStage['uid'])) {
185 $allowedStages[$nextStage['uid']] = $nextStage;
186 }
187 if (isset($prevStage['uid'])) {
188 $allowedStages[$prevStage['uid']] = $prevStage;
189 }
190 }
191
192 $orderedAllowedStages = array_values($allowedStages);
193 }
194 }
195 return $orderedAllowedStages;
196 }
197
198 /**
199 * Check if given workspace has custom staging activated
200 *
201 * @return bool TRUE or FALSE
202 */
203 public function checkCustomStagingForWS() {
204 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
205 return $workspaceRec['custom_stages'] > 0;
206 }
207
208 /**
209 * Gets the title of a stage.
210 *
211 * @param integer $ver_stage
212 * @return string
213 */
214 public function getStageTitle($ver_stage) {
215 global $LANG;
216 $stageTitle = '';
217
218 switch ($ver_stage) {
219 case self::STAGE_PUBLISH_EXECUTE_ID:
220 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_publish');
221 break;
222 case self::STAGE_PUBLISH_ID:
223 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xml:stage_ready_to_publish');
224 break;
225 case self::STAGE_EDIT_ID:
226 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing');
227 break;
228 default:
229 $stageTitle = $this->getPropertyOfCurrentWorkspaceStage($ver_stage, 'title');
230
231 if ($stageTitle == NULL) {
232 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.getStageTitle.stageNotFound');
233 }
234 break;
235 }
236
237 return $stageTitle;
238 }
239
240 /**
241 * Gets a particular stage record.
242 *
243 * @param integer $stageid
244 * @return array
245 */
246 public function getStageRecord($stageid) {
247 return t3lib_BEfunc::getRecord('sys_workspace_stage', $stageid);
248 }
249
250 /**
251 * Gets next stage in process for given stage id
252 *
253 * @param integer $stageid Id of the stage to fetch the next one for
254 * @return integer The next stage Id
255 */
256 public function getNextStage($stageId) {
257 if (!t3lib_utility_Math::canBeInterpretedAsInteger($stageId)) {
258 throw new InvalidArgumentException(
259 $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'),
260 1291109987
261 );
262 }
263
264 $nextStage = FALSE;
265 $workspaceStageRecs = $this->getStagesForWS();
266
267 if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
268 reset($workspaceStageRecs);
269 while (!is_null($workspaceStageRecKey = key($workspaceStageRecs))) {
270 $workspaceStageRec = current($workspaceStageRecs);
271 if ($workspaceStageRec['uid'] == $stageId) {
272 $nextStage = next($workspaceStageRecs);
273 break;
274 }
275 next($workspaceStageRecs);
276 }
277 } else {
278 // @todo consider to throw an exception here
279 }
280
281 if ($nextStage === FALSE) {
282 $nextStage[] = array(
283 'uid' => self::STAGE_EDIT_ID,
284 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing') . '"'
285 );
286 }
287
288 return $nextStage;
289 }
290
291 /**
292 * Recursive function to get all next stages for a record depending on user permissions
293 *
294 * @param array next stages
295 * @param int stage id
296 * @param int current stage id of the record
297 * @return array next stages
298 */
299 public function getNextStages(array &$nextStageArray, $stageId) {
300 // Current stage is "Ready to publish" - there is no next stage
301 if ($stageId == self::STAGE_PUBLISH_ID) {
302 return $nextStageArray;
303 } else {
304 $nextStageRecord = $this->getNextStage($stageId);
305 if (empty($nextStageRecord) || !is_array($nextStageRecord)) {
306 // There is no next stage
307 return $nextStageArray;
308 } else {
309 // Check if the user has the permission to for the current stage
310 // If this next stage record is the first next stage after the current the user
311 // has always the needed permission
312 if ($this->isStageAllowedForUser($stageId)) {
313 $nextStageArray[] = $nextStageRecord;
314 return $this->getNextStages($nextStageArray, $nextStageRecord['uid']);
315 } else {
316 // He hasn't - return given next stage array
317 return $nextStageArray;
318 }
319 }
320 }
321 }
322
323 /**
324 * Get next stage in process for given stage id
325 *
326 * @param int workspace id
327 * @param int stageid
328 * @return int id
329 */
330 public function getPrevStage($stageid) {
331
332 if (!t3lib_utility_Math::canBeInterpretedAsInteger($stageid)) {
333 throw new InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'));
334 }
335
336 $prevStage = FALSE;
337 $workspaceStageRecs = $this->getStagesForWS();
338 if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
339 end($workspaceStageRecs);
340 while (!is_null($workspaceStageRecKey = key($workspaceStageRecs))) {
341 $workspaceStageRec = current($workspaceStageRecs);
342 if ($workspaceStageRec['uid'] == $stageid) {
343 $prevStage = prev($workspaceStageRecs);
344 break;
345 }
346 prev($workspaceStageRecs);
347 }
348 } else {
349 // @todo consider to throw an exception here
350 }
351 return $prevStage;
352 }
353
354 /**
355 * Recursive function to get all prev stages for a record depending on user permissions
356 *
357 * @param array prev stages
358 * @param int workspace id
359 * @param int stage id
360 * @param int current stage id of the record
361 * @return array prev stages
362 */
363 public function getPrevStages(array &$prevStageArray, $stageId) {
364 // Current stage is "Editing" - there is no prev stage
365 if ($stageId != self::STAGE_EDIT_ID) {
366 $prevStageRecord = $this->getPrevStage($stageId);
367
368 if (!empty($prevStageRecord) && is_array($prevStageRecord)) {
369 // Check if the user has the permission to switch to that stage
370 // If this prev stage record is the first previous stage before the current
371 // the user has always the needed permission
372 if ($this->isStageAllowedForUser($stageId)) {
373 $prevStageArray[] = $prevStageRecord;
374 $prevStageArray = $this->getPrevStages($prevStageArray, $prevStageRecord['uid']);
375
376 }
377 }
378 }
379 return $prevStageArray;
380 }
381
382 /**
383 * Get array of all responsilbe be_users for a stage
384 *
385 * @param int stage id
386 * @param boolean if field notification_defaults should be selected instead of responsible users
387 * @return array be_users with e-mail and name
388 */
389 public function getResponsibleBeUser($stageId, $selectDefaultUserField = FALSE) {
390 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
391 $recipientArray = array();
392
393 switch ($stageId) {
394 case self::STAGE_PUBLISH_EXECUTE_ID:
395 case self::STAGE_PUBLISH_ID:
396 if ($selectDefaultUserField == FALSE) {
397 $userList = $this->getResponsibleUser($workspaceRec['adminusers']);
398 } else {
399 $notification_default_user = $workspaceRec['publish_notification_defaults'];
400 $userList = $this->getResponsibleUser($notification_default_user);
401 }
402 break;
403 case self::STAGE_EDIT_ID:
404 if ($selectDefaultUserField == FALSE) {
405 $userList = $this->getResponsibleUser($workspaceRec['members']);
406 } else {
407 $notification_default_user = $workspaceRec['edit_notification_defaults'];
408 $userList = $this->getResponsibleUser($notification_default_user);
409 }
410 break;
411 default:
412 if ($selectDefaultUserField == FALSE) {
413 $responsible_persons = $this->getPropertyOfCurrentWorkspaceStage($stageId, 'responsible_persons');
414 $userList = $this->getResponsibleUser($responsible_persons);
415 } else {
416 $notification_default_user = $this->getPropertyOfCurrentWorkspaceStage($stageId, 'notification_defaults');
417 $userList = $this->getResponsibleUser($notification_default_user);
418 }
419 break;
420 }
421
422 if (!empty($userList)) {
423 $userRecords = t3lib_BEfunc::getUserNames('username, uid, email, realName',
424 'AND uid IN (' . $userList . ')');
425 }
426
427 if (!empty($userRecords) && is_array($userRecords)) {
428 foreach ($userRecords as $userUid => $userRecord) {
429 $recipientArray[$userUid] = $userRecord;
430 }
431 }
432 return $recipientArray;
433 }
434
435 /**
436 * Get uids of all responsilbe persons for a stage
437 *
438 * @param string responsible_persion value from stage record
439 * @return string uid list of responsible be_users
440 */
441 public function getResponsibleUser($stageRespValue) {
442 $stageValuesArray = array();
443 $stageValuesArray = t3lib_div::trimExplode(',', $stageRespValue);
444
445 $beuserUidArray = array();
446 $begroupUidArray = array();
447 $allBeUserArray = array();
448 $begroupUidList = array();
449
450 foreach ($stageValuesArray as $key => $uidvalue) {
451 if (strstr($uidvalue, 'be_users') !== FALSE) { // Current value is a uid of a be_user record
452 $beuserUidArray[] = str_replace('be_users_', '', $uidvalue);
453 } elseif (strstr($uidvalue, 'be_groups') !== FALSE) {
454 $begroupUidArray[] = str_replace('be_groups_', '', $uidvalue);
455 } else {
456 $beuserUidArray[] = $uidvalue;
457 }
458 }
459 if (!empty($begroupUidArray)) {
460 $allBeUserArray = t3lib_befunc::getUserNames();
461
462 $begroupUidList = implode(',', $begroupUidArray);
463
464 $this->userGroups = array();
465 $begroupUidArray = $this->fetchGroups($begroupUidList);
466
467 foreach ($begroupUidArray as $groupkey => $groupData) {
468 foreach ($allBeUserArray as $useruid => $userdata) {
469 if (t3lib_div::inList($userdata['usergroup_cached_list'], $groupData['uid'])) {
470 $beuserUidArray[] = $useruid;
471 }
472 }
473 }
474 }
475
476 array_unique($beuserUidArray);
477 return implode(',', $beuserUidArray);
478 }
479
480
481 /**
482 * @param $grList
483 * @param string $idList
484 * @return array
485 */
486 private function fetchGroups($grList, $idList = '') {
487
488 $cacheKey = md5($grList . $idList);
489 $groupList = array();
490 if (isset($this->fetchGroupsCache[$cacheKey])) {
491 $groupList = $this->fetchGroupsCache[$cacheKey];
492 } else {
493 if ($idList === '') {
494 // we're at the beginning of the recursion and therefore we need to reset the userGroups member
495 $this->userGroups = array();
496 }
497 $groupList = $this->fetchGroupsRecursive($grList);
498 $this->fetchGroupsCache[$cacheKey] = $groupList;
499 }
500 return $groupList;
501 }
502
503 /**
504 * @param array $groups
505 * @return void
506 */
507 private function fetchGroupsFromDB(array $groups) {
508 $whereSQL = 'deleted=0 AND hidden=0 AND pid=0 AND uid IN (' . implode(',', $groups) . ') ';
509 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'be_groups', $whereSQL);
510
511 // The userGroups array is filled
512 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
513 $this->userGroups[$row['uid']] = $row;
514 }
515 }
516
517 /**
518 * Fetches particular groups recursively.
519 *
520 * @param $grList
521 * @param string $idList
522 * @return array
523 */
524 private function fetchGroupsRecursive($grList, $idList = '') {
525 $requiredGroups = t3lib_div::intExplode(',', $grList, TRUE);
526 $existingGroups = array_keys($this->userGroups);
527 $missingGroups = array_diff($requiredGroups, $existingGroups);
528
529 if (count($missingGroups) > 0) {
530 $this->fetchGroupsFromDB($missingGroups);
531 }
532
533 // Traversing records in the correct order
534 foreach ($requiredGroups as $uid) { // traversing list
535 // Get row:
536 $row = $this->userGroups[$uid];
537 if (is_array($row) && !t3lib_div::inList($idList, $uid)) { // Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist
538 // If the localconf.php option isset the user of the sub- sub- groups will also be used
539 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['customStageShowRecipientRecursive'] == 1) {
540 // Include sub groups
541 if (trim($row['subgroup'])) {
542 // Make integer list
543 $theList = implode(',', t3lib_div::intExplode(',', $row['subgroup']));
544 // Get the subarray
545 $subbarray = $this->fetchGroups($theList, $idList . ',' . $uid);
546 list($subUid, $subArray) = each($subbarray);
547 // Merge the subarray to the already existing userGroups array
548 $this->userGroups[$subUid] = $subArray;
549 }
550 }
551 }
552 }
553
554 return $this->userGroups;
555 }
556
557 /**
558 * Gets a property of a workspaces stage.
559 *
560 * @param integer $stageId
561 * @param string $property
562 * @return string
563 */
564 public function getPropertyOfCurrentWorkspaceStage($stageId, $property) {
565 $result = NULL;
566
567 if (!t3lib_utility_Math::canBeInterpretedAsInteger($stageId)) {
568 throw new InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'));
569 }
570
571 $workspaceStage = t3lib_BEfunc::getRecord(self::TABLE_STAGE, $stageId);
572
573 if (is_array($workspaceStage) && isset($workspaceStage[$property])) {
574 $result = $workspaceStage[$property];
575 }
576
577 return $result;
578 }
579
580 /**
581 * Gets the position of the given workspace in the hole process f.e. 3 means step 3 of 20, by which 1 is edit and 20 is ready to publish
582 *
583 * @param integer $stageId
584 * @return array position => 3, count => 20
585 */
586 public function getPositionOfCurrentStage($stageId) {
587 $stagesOfWS = $this->getStagesForWS();
588 $countOfStages = count($stagesOfWS);
589
590 switch ($stageId) {
591 case self::STAGE_PUBLISH_ID:
592 $position = $countOfStages;
593 break;
594 case self::STAGE_EDIT_ID:
595 $position = 1;
596 break;
597 default:
598 $position = 1;
599 foreach ($stagesOfWS as $key => $stageInfoArray) {
600 $position++;
601 if ($stageId == $stageInfoArray['uid']) {
602 break;
603 }
604 }
605 break;
606 }
607 return array('position' => $position, 'count' => $countOfStages);
608 }
609
610 /**
611 * Check if the user has access to the previous stage, relative to the given stage
612 *
613 * @param integer $stageId
614 * @return bool
615 */
616 public function isPrevStageAllowedForUser($stageId) {
617 $isAllowed = FALSE;
618 try {
619 $prevStage = $this->getPrevStage($stageId);
620 // if there's no prev-stage the stageIds match,
621 // otherwise we've to check if the user is permitted to use the stage
622 if (!empty($prevStage) && $prevStage['uid'] != $stageId) {
623 // if the current stage is allowed for the user, the user is also allowed to send to prev
624 $isAllowed = $this->isStageAllowedForUser($stageId);
625 }
626 } catch (Exception $e) {
627 // Exception raised - we're not allowed to go this way
628 }
629
630 return $isAllowed;
631 }
632
633 /**
634 * Check if the user has access to the next stage, relative to the given stage
635 *
636 * @param integer $stageId
637 * @return bool
638 */
639 public function isNextStageAllowedForUser($stageId) {
640 $isAllowed = FALSE;
641 try {
642 $nextStage = $this->getNextStage($stageId);
643 // if there's no next-stage the stageIds match,
644 // otherwise we've to check if the user is permitted to use the stage
645 if (!empty($nextStage) && $nextStage['uid'] != $stageId) {
646 // if the current stage is allowed for the user, the user is also allowed to send to next
647 $isAllowed = $this->isStageAllowedForUser($stageId);
648 }
649 } catch (Exception $e) {
650 // Exception raised - we're not allowed to go this way
651 }
652
653 return $isAllowed;
654 }
655
656 /**
657 * @param $stageId
658 * @return bool
659 */
660 protected function isStageAllowedForUser($stageId) {
661 $cacheKey = $this->getWorkspaceId() . '_' . $stageId;
662 $isAllowed = FALSE;
663 if (isset($this->workspaceStageAllowedCache[$cacheKey])) {
664 $isAllowed = $this->workspaceStageAllowedCache[$cacheKey];
665 } else {
666 $isAllowed = $GLOBALS['BE_USER']->workspaceCheckStageForCurrent($stageId);
667 $this->workspaceStageAllowedCache[$cacheKey] = $isAllowed;
668 }
669 return $isAllowed;
670 }
671
672 /**
673 * Determines whether a stage Id is valid.
674 *
675 * @param integer $stageId The stage Id to be checked
676 * @return boolean
677 */
678 public function isValid($stageId) {
679 $isValid = FALSE;
680 $stages = $this->getStagesForWS();
681
682 foreach ($stages as $stage) {
683 if ($stage['uid'] == $stageId) {
684 $isValid = TRUE;
685 break;
686 }
687 }
688
689 return $isValid;
690 }
691
692 /**
693 * Returns the notification mode from stage configuration
694 *
695 * Return values:
696 * 0 = notify someone / old way / default setting
697 * 1 = notify all responsible users (some users checked per default and you're not allowed to uncheck them)
698 * 2 = notify all responsible users (all users are checked and nothing can be changed during stage change)
699 *
700 * @param integer stage id to return the notification mode for
701 * @return integer
702 */
703 public function getNotificationMode($stageId) {
704 if (!t3lib_div::testInt($stageId)) {
705 throw new InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'));
706 }
707
708 switch ($stageId) {
709 case self::STAGE_PUBLISH_EXECUTE_ID:
710 case self::STAGE_PUBLISH_ID:
711 $workspaceRecord = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
712 return $workspaceRecord['publish_notification_mode'];
713 break;
714 case self::STAGE_EDIT_ID:
715 $workspaceRecord = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
716 return $workspaceRecord['edit_notification_mode'];
717 break;
718 default:
719 $workspaceStage = t3lib_BEfunc::getRecord(self::TABLE_STAGE, $stageId);
720
721 if (is_array($workspaceStage) && isset($workspaceStage['notification_mode'])) {
722 return $workspaceStage['notification_mode'];
723 }
724 break;
725 }
726 }
727 }
728
729
730 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Stages.php'])) {
731 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Stages.php']);
732 }
733 ?>