TYPO3 API  SVNRelease
Stages.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00030  * @package Workspaces
00031  * @subpackage Service
00032  */
00033 
00034 class Tx_Workspaces_Service_Stages {
00035     const TABLE_STAGE = 'sys_workspace_stage';
00036         // 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
00037     const STAGE_PUBLISH_EXECUTE_ID = -20;
00038         // ready to publish stage
00039     const STAGE_PUBLISH_ID = -10;
00040     const STAGE_EDIT_ID = 0;
00041 
00042     /**
00043      * Current workspace ID
00044      * @var integer
00045      */
00046     private $workspaceId = NULL;
00047 
00048     /**
00049      * Path to the locallang file
00050      * @var string
00051      */
00052     private $pathToLocallang = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xml';
00053 
00054     /**
00055      * Local cache to reduce number of database queries for stages, groups, etc.
00056      * @var array
00057      */
00058     protected $workspaceStageCache = array();
00059 
00060     /**
00061      * @var array
00062      */
00063     protected $workspaceStageAllowedCache = array();
00064 
00065     /**
00066      * @var array
00067      */
00068     protected $fetchGroupsCache = array();
00069 
00070     /**
00071      * @var array
00072      */
00073     protected $userGroups = array();
00074 
00075     /**
00076      * Getter for current workspace id
00077      *
00078      * @return int current workspace id
00079      */
00080     public function getWorkspaceId() {
00081         if ($this->workspaceId == NULL) {
00082             $this->setWorkspaceId($GLOBALS['BE_USER']->workspace);
00083         }
00084         return $this->workspaceId;
00085     }
00086 
00087     /**
00088      * Setter for current workspace id
00089      *
00090      * @param int current workspace id
00091      */
00092     private function setWorkspaceId($wsid) {
00093         $this->workspaceId = $wsid;
00094     }
00095 
00096     /**
00097      * constructor for workspace library
00098      *
00099      * @param int current workspace id
00100      */
00101     public function __construct() {
00102         $this->setWorkspaceId($GLOBALS['BE_USER']->workspace);
00103     }
00104 
00105     /**
00106      * Building an array with all stage ids and titles related to the given workspace
00107      *
00108      * @return array id and title of the stages
00109      */
00110     public function getStagesForWS() {
00111         $stages = array();
00112 
00113         if (isset($this->workspaceStageCache[$this->getWorkspaceId()])) {
00114             $stages = $this->workspaceStageCache[$this->getWorkspaceId()];
00115         } else {
00116             $stages[] = array(
00117                 'uid' => self::STAGE_EDIT_ID,
00118                 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing') . '"'
00119             );
00120 
00121             $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
00122             if ($workspaceRec['custom_stages'] > 0) {
00123                     // Get all stage records for this workspace
00124                 $workspaceStageRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00125                     '*',
00126                     self::TABLE_STAGE,
00127                         'parentid=' . $this->getWorkspaceId() . ' AND parenttable="sys_workspace" AND deleted = 0',
00128                     '',
00129                     'sorting',
00130                     '',
00131                     'uid'
00132                 );
00133                 foreach($workspaceStageRecs as $stage) {
00134                     $stage['title'] =  $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $stage['title'] . '"'; 
00135                     $stages[] = $stage;
00136                 }
00137             }
00138 
00139             $stages[] = array(
00140                 'uid' => self::STAGE_PUBLISH_ID,
00141                 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xml:stage_ready_to_publish') . '"'
00142             );
00143 
00144             $stages[] = array(
00145                 'uid' => self::STAGE_PUBLISH_EXECUTE_ID,
00146                 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':publish_execute_action_option')
00147             );
00148             $this->workspaceStageCache[$this->getWorkspaceId()] = $stages;
00149         }
00150 
00151         return $stages;
00152     }
00153 
00154     /**
00155      * Returns an array of stages, the user is allowed to send to
00156      * @return array id and title of stages
00157      */
00158     public function getStagesForWSUser() {
00159 
00160         $stagesForWSUserData = array();
00161         $allowedStages = array();
00162         $orderedAllowedStages = array();
00163 
00164         $workspaceStageRecs = $this->getStagesForWS();
00165         if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
00166             if ($GLOBALS['BE_USER']->isAdmin()) {
00167                 $orderedAllowedStages = $workspaceStageRecs;
00168             } else {
00169                 foreach ($workspaceStageRecs as $workspaceStageRec) {
00170                     if ($this->isStageAllowedForUser($workspaceStageRec['uid'])) {
00171                         $stagesForWSUserData[$workspaceStageRec['uid']] = $workspaceStageRec;
00172                     } else if ($workspaceStageRec['uid'] == self::STAGE_PUBLISH_EXECUTE_ID && $GLOBALS['BE_USER']->workspacePublishAccess($this->getWorkspaceId())) {
00173                         $allowedStages[] = $workspaceStageRec;
00174                         $stagesForWSUserData[$workspaceStageRec['uid']] = $workspaceStageRec;
00175                     }
00176                 }
00177 
00178                 foreach ($stagesForWSUserData as $allowedStage) {
00179                     $nextStage = $this->getNextStage($allowedStage['uid']);
00180                     $prevStage = $this->getPrevStage($allowedStage['uid']);
00181                     if (isset($nextStage['uid'])) {
00182                         $allowedStages[$nextStage['uid']] = $nextStage;
00183                     }
00184                     if (isset($prevStage['uid'])) {
00185                         $allowedStages[$prevStage['uid']] = $prevStage;
00186                     }
00187                 }
00188 
00189                 $orderedAllowedStages = array_values($allowedStages);
00190             }
00191         }
00192         return $orderedAllowedStages;
00193     }
00194 
00195     /**
00196      * Check if given workspace has custom staging activated
00197      *
00198      * @return bool true or false
00199      */
00200     public function checkCustomStagingForWS() {
00201         $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
00202         return $workspaceRec['custom_stages'] > 0;
00203     }
00204 
00205     /**
00206      * Gets the title of a stage.
00207      *
00208      * @param integer $ver_stage
00209      * @return string
00210      */
00211     public function getStageTitle($ver_stage) {
00212         global $LANG;
00213         $stageTitle = '';
00214 
00215         switch ($ver_stage) {
00216             case self::STAGE_PUBLISH_EXECUTE_ID:
00217                 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_publish');
00218                 break;
00219             case self::STAGE_PUBLISH_ID:
00220                 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xml:stage_ready_to_publish');
00221                 break;
00222             case self::STAGE_EDIT_ID:
00223                 $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing');
00224                 break;
00225             default:
00226                 $stageTitle = $this->getPropertyOfCurrentWorkspaceStage($ver_stage, 'title');
00227 
00228                 if ($stageTitle == null) {
00229                     $stageTitle = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.getStageTitle.stageNotFound');
00230                 }
00231                 break;
00232         }
00233 
00234         return $stageTitle;
00235     }
00236 
00237     /**
00238      * Gets a particular stage record.
00239      *
00240      * @param integer $stageid
00241      * @return array
00242      */
00243     public function getStageRecord($stageid) {
00244         return t3lib_BEfunc::getRecord('sys_workspace_stage', $stageid);
00245     }
00246 
00247     /**
00248      * Gets next stage in process for given stage id
00249      *
00250      * @param integer $stageid Id of the stage to fetch the next one for
00251      * @return integer The next stage Id
00252      */
00253     public function getNextStage($stageId) {
00254         if (!t3lib_div::testInt($stageId)) {
00255             throw new InvalidArgumentException(
00256                 $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'),
00257                 1291109987
00258             );
00259         }
00260 
00261         $nextStage = FALSE;
00262         $workspaceStageRecs = $this->getStagesForWS();
00263 
00264         if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
00265             reset($workspaceStageRecs);
00266             while (!is_null($workspaceStageRecKey = key($workspaceStageRecs))) {
00267                 $workspaceStageRec = current($workspaceStageRecs);
00268                 if ($workspaceStageRec['uid'] == $stageId) {
00269                     $nextStage = next($workspaceStageRecs);
00270                     break;
00271                 }
00272                 next($workspaceStageRecs);
00273             }
00274         } else {
00275             // @todo consider to throw an exception here
00276         }
00277 
00278         if ($nextStage === FALSE) {
00279             $nextStage[] = array(
00280                 'uid' => self::STAGE_EDIT_ID,
00281                 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':actionSendToStage') . ' "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:stage_editing') . '"'
00282             );
00283         }
00284 
00285         return $nextStage;
00286     }
00287 
00288     /**
00289      * Recursive function to get all next stages for a record depending on user permissions
00290      *
00291      * @param   array   next stages
00292      * @param   int     stage id
00293      * @param   int     current stage id of the record
00294      * @return  array   next stages
00295      */
00296     public function getNextStages(array &$nextStageArray, $stageId) {
00297             // Current stage is "Ready to publish" - there is no next stage
00298         if ($stageId == self::STAGE_PUBLISH_ID) {
00299             return $nextStageArray;
00300         } else {
00301             $nextStageRecord = $this->getNextStage($stageId);
00302             if (empty($nextStageRecord) || !is_array($nextStageRecord)) {
00303                     // There is no next stage
00304                 return $nextStageArray;
00305             } else {
00306                     // Check if the user has the permission to for the current stage
00307                     // If this next stage record is the first next stage after the current the user
00308                     // has always the needed permission
00309                 if ($this->isStageAllowedForUser($stageId)) {
00310                     $nextStageArray[] = $nextStageRecord;
00311                     return $this->getNextStages($nextStageArray, $nextStageRecord['uid']);
00312                 } else {
00313                         // He hasn't - return given next stage array
00314                     return $nextStageArray;
00315                 }
00316             }
00317         }
00318     }
00319 
00320     /**
00321      * Get next stage in process for given stage id
00322      *
00323      * @param int           workspace id
00324      * @param int           stageid
00325      * @return int          id
00326      */
00327     public function getPrevStage($stageid) {
00328 
00329         if (!t3lib_div::testInt($stageid)) {
00330             throw new InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'));
00331         }
00332 
00333         $prevStage = FALSE;
00334         $workspaceStageRecs = $this->getStagesForWS();
00335         if (is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
00336             end($workspaceStageRecs);
00337             while (!is_null($workspaceStageRecKey = key($workspaceStageRecs))) {
00338                 $workspaceStageRec = current($workspaceStageRecs);
00339                 if ($workspaceStageRec['uid'] == $stageid) {
00340                     $prevStage = prev($workspaceStageRecs);
00341                     break;
00342                 }
00343                 prev($workspaceStageRecs);
00344             }
00345         } else {
00346             // @todo consider to throw an exception here
00347         }
00348         return $prevStage;
00349     }
00350 
00351     /**
00352      * Recursive function to get all prev stages for a record depending on user permissions
00353      *
00354      * @param   array   prev stages
00355      * @param   int     workspace id
00356      * @param   int     stage id
00357      * @param   int     current stage id of the record
00358      * @return  array   prev stages
00359      */
00360     public function getPrevStages(array &$prevStageArray, $stageId) {
00361             // Current stage is "Editing" - there is no prev stage
00362         if ($stageId != self::STAGE_EDIT_ID) {
00363             $prevStageRecord = $this->getPrevStage($stageId);
00364 
00365             if (!empty($prevStageRecord) && is_array($prevStageRecord)) {
00366                     // Check if the user has the permission to switch to that stage
00367                     // If this prev stage record is the first previous stage before the current
00368                     // the user has always the needed permission
00369                 if ($this->isStageAllowedForUser($stageId)) {
00370                     $prevStageArray[] = $prevStageRecord;
00371                     $prevStageArray = $this->getPrevStages($prevStageArray, $prevStageRecord['uid']);
00372 
00373                 }
00374             }
00375         }
00376         return $prevStageArray;
00377     }
00378 
00379     /**
00380      * Get array of all responsilbe be_users for a stage
00381      *
00382      * @param   int stage id
00383      * @return  array be_users with e-mail and name
00384      */
00385     public function getResponsibleBeUser($stageId) {
00386         $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $this->getWorkspaceId());
00387         $recipientArray = array();
00388 
00389         switch ($stageId) {
00390             case self::STAGE_PUBLISH_EXECUTE_ID:
00391             case self::STAGE_PUBLISH_ID:
00392                 $userList = $this->getResponsibleUser($workspaceRec['adminusers']);
00393                 break;
00394             case self::STAGE_EDIT_ID:
00395                 $userList = $this->getResponsibleUser($workspaceRec['members']);
00396                 break;
00397             default:
00398                 $responsible_persons = $this->getPropertyOfCurrentWorkspaceStage($stageId, 'responsible_persons');
00399                 $userList = $this->getResponsibleUser($responsible_persons);
00400                 break;
00401         }
00402 
00403         if (!empty($userList)) {
00404             $userRecords = t3lib_BEfunc::getUserNames('username, uid, email, realName',
00405                     'AND uid IN (' . $userList . ')');
00406         }
00407 
00408         if (!empty($userRecords) && is_array($userRecords)) {
00409             foreach ($userRecords as $userUid => $userRecord) {
00410                 $recipientArray[$userUid] = $userRecord;
00411             }
00412         }
00413         return $recipientArray;
00414     }
00415 
00416     /**
00417      * Get uids of all responsilbe persons for a stage
00418      *
00419      * @param   string  responsible_persion value from stage record
00420      * @return  string  uid list of responsible be_users
00421      */
00422     public function getResponsibleUser($stageRespValue) {
00423         $stageValuesArray = array();
00424         $stageValuesArray = t3lib_div::trimExplode(',', $stageRespValue);
00425 
00426         $beuserUidArray = array();
00427         $begroupUidArray = array();
00428         $allBeUserArray = array();
00429         $begroupUidList = array();
00430 
00431         foreach ($stageValuesArray as $key => $uidvalue) {
00432             if (strstr($uidvalue, 'be_users') !== FALSE) { // Current value is a uid of a be_user record
00433                 $beuserUidArray[] = str_replace('be_users_', '', $uidvalue);
00434             } elseif (strstr($uidvalue, 'be_groups') !== FALSE) {
00435                 $begroupUidArray[] = str_replace('be_groups_', '', $uidvalue);
00436             } else {
00437                 $beuserUidArray[] = $uidvalue;
00438             }
00439         }
00440         if (!empty($begroupUidArray)) {
00441             $allBeUserArray = t3lib_befunc::getUserNames();
00442 
00443             $begroupUidList = implode(',', $begroupUidArray);
00444 
00445             $this->userGroups = array();
00446             $begroupUidArray = $this->fetchGroups($begroupUidList);
00447 
00448             foreach ($begroupUidArray as $groupkey => $groupData) {
00449                 foreach ($allBeUserArray as $useruid => $userdata) {
00450                     if (t3lib_div::inList($userdata['usergroup'], $groupData['uid'])) {
00451                         $beuserUidArray[] = $useruid;
00452                     }
00453                 }
00454             }
00455         }
00456 
00457         array_unique($beuserUidArray);
00458         return implode(',', $beuserUidArray);
00459     }
00460 
00461 
00462     /**
00463      * @param  $grList
00464      * @param string $idList
00465      * @return array
00466      */
00467     private function fetchGroups($grList, $idList = '') {
00468 
00469         $cacheKey = md5($grList . $idList);
00470         $groupList = array();
00471         if (isset($this->fetchGroupsCache[$cacheKey])) {
00472             $groupList = $this->fetchGroupsCache[$cacheKey];
00473         } else {
00474             if ($idList === '') {
00475                     // we're at the beginning of the recursion and therefore we need to reset the userGroups member
00476                 $this->userGroups = array();
00477             }
00478             $groupList = $this->fetchGroupsRecursive($grList);
00479             $this->fetchGroupsCache[$cacheKey] = $groupList;
00480         }
00481         return $groupList;
00482     }
00483 
00484     /**
00485      * @param  array    $groups
00486      * @return void
00487      */
00488     private function fetchGroupsFromDB(array $groups) {
00489         $whereSQL = 'deleted=0 AND hidden=0 AND pid=0 AND uid IN (' . implode(',', $groups) . ') ';
00490         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'be_groups', $whereSQL);
00491 
00492             // The userGroups array is filled
00493         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00494             $this->userGroups[$row['uid']] = $row;
00495         }
00496     }
00497 
00498     /**
00499      * Fetches particular groups recursively.
00500      *
00501      * @param  $grList
00502      * @param string $idList
00503      * @return array
00504      */
00505     private function fetchGroupsRecursive($grList, $idList = '') {
00506         $requiredGroups = t3lib_div::intExplode(',', $grList, TRUE);
00507         $existingGroups = array_keys($this->userGroups);
00508         $missingGroups = array_diff($requiredGroups, $existingGroups);
00509 
00510         if (count($missingGroups) > 0) {
00511             $this->fetchGroupsFromDB($missingGroups);
00512         }
00513 
00514             // Traversing records in the correct order
00515         foreach ($requiredGroups as $uid) { // traversing list
00516                 // Get row:
00517             $row = $this->userGroups[$uid];
00518             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
00519                     // If the localconf.php option isset the user of the sub- sub- groups will also be used
00520                 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['customStageShowRecipientRecursive'] == 1) {
00521                         // Include sub groups
00522                     if (trim($row['subgroup'])) {
00523                             // Make integer list
00524                         $theList = implode(',', t3lib_div::intExplode(',', $row['subgroup']));
00525                             // Get the subarray
00526                         $subbarray = $this->fetchGroups($theList, $idList . ',' . $uid);
00527                         list($subUid, $subArray) = each($subbarray);
00528                             // Merge the subarray to the already existing userGroups array
00529                         $this->userGroups[$subUid] = $subArray;
00530                     }
00531                 }
00532             }
00533         }
00534 
00535         return $this->userGroups;
00536     }
00537 
00538     /**
00539      * Gets a property of a workspaces stage.
00540      *
00541      * @param integer $stageId
00542      * @param string $property
00543      * @return string
00544      */
00545     public function getPropertyOfCurrentWorkspaceStage($stageId, $property) {
00546         $result = NULL;
00547 
00548         if (!t3lib_div::testInt($stageId)) {
00549             throw new InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:error.stageId.integer'));
00550         }
00551 
00552         $workspaceStage = t3lib_BEfunc::getRecord(self::TABLE_STAGE, $stageId);
00553 
00554         if (is_array($workspaceStage) && isset($workspaceStage[$property])) {
00555             $result = $workspaceStage[$property];
00556         }
00557 
00558         return $result;
00559     }
00560 
00561     /**
00562      * 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
00563      *
00564      * @param integer $stageId
00565      * @return array position => 3, count => 20
00566      */
00567     public function getPositionOfCurrentStage($stageId) {
00568         $stagesOfWS = $this->getStagesForWS();
00569         $countOfStages = count($stagesOfWS);
00570 
00571         switch ($stageId) {
00572             case self::STAGE_PUBLISH_ID:
00573                     $position = $countOfStages;
00574                 break;
00575             case self::STAGE_EDIT_ID:
00576                     $position = 1;
00577                 break;
00578             default:
00579                 $position = 1;
00580                 foreach ($stagesOfWS as $key => $stageInfoArray) {
00581                     $position++;
00582                     if ($stageId == $stageInfoArray['uid']) {
00583                         break;
00584                     }
00585                 }
00586                 break;
00587         }
00588         return array('position' => $position, 'count' => $countOfStages);
00589     }
00590 
00591     /**
00592      * Check if the user has access to the previous stage, relative to the given stage
00593      *
00594      * @param  integer $stageId
00595      * @return bool
00596      */
00597     public function isPrevStageAllowedForUser($stageId) {
00598         $isAllowed = FALSE;
00599         try {
00600             $prevStage = $this->getPrevStage($stageId);
00601                 // if there's no prev-stage the stageIds match,
00602                 // otherwise we've to check if the user is permitted to use the stage
00603             if (!empty($prevStage) && $prevStage['uid'] != $stageId) {
00604                     // if the current stage is allowed for the user, the user is also allowed to send to prev
00605                 $isAllowed = $this->isStageAllowedForUser($stageId);
00606             }
00607         } catch (Exception $e) {
00608             // Exception raised - we're not allowed to go this way
00609         }
00610 
00611         return $isAllowed;
00612     }
00613 
00614     /**
00615      * Check if the user has access to the next stage, relative to the given stage
00616      *
00617      * @param  integer $stageId
00618      * @return bool
00619      */
00620     public function isNextStageAllowedForUser($stageId) {
00621         $isAllowed = FALSE;
00622         try {
00623             $nextStage = $this->getNextStage($stageId);
00624                 // if there's no next-stage the stageIds match,
00625                 // otherwise we've to check if the user is permitted to use the stage
00626             if (!empty($nextStage) && $nextStage['uid'] != $stageId) {
00627                     // if the current stage is allowed for the user, the user is also allowed to send to next
00628                 $isAllowed = $this->isStageAllowedForUser($stageId);
00629             }
00630         } catch (Exception $e) {
00631             // Exception raised - we're not allowed to go this way
00632         }
00633 
00634         return $isAllowed;
00635     }
00636 
00637     /**
00638      * @param  $stageId
00639      * @return bool
00640      */
00641     protected function isStageAllowedForUser($stageId) {
00642         $cacheKey = $this->getWorkspaceId() . '_' . $stageId;
00643         $isAllowed = FALSE;
00644         if (isset($this->workspaceStageAllowedCache[$cacheKey])) {
00645             $isAllowed = $this->workspaceStageAllowedCache[$cacheKey];
00646          } else {
00647             $isAllowed = $GLOBALS['BE_USER']->workspaceCheckStageForCurrent($stageId);
00648             $this->workspaceStageAllowedCache[$cacheKey] = $isAllowed;
00649          }
00650         return $isAllowed;
00651     }
00652 
00653     /**
00654      * Determines whether a stage Id is valid.
00655      *
00656      * @param integer $stageId The stage Id to be checked
00657      * @return boolean
00658      */
00659     public function isValid($stageId) {
00660         $isValid = FALSE;
00661         $stages = $this->getStagesForWS();
00662 
00663         foreach ($stages as $stage) {
00664             if ($stage['uid'] == $stageId) {
00665                 $isValid = TRUE;
00666                 break;
00667             }
00668         }
00669 
00670         return $isValid;
00671     }
00672 }
00673 
00674 
00675 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Stages.php'])) {
00676     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Stages.php']);
00677 }
00678 ?>