示例#1
0
 public function __construct(Session $session)
 {
     $this->session_variables = new SessionVariables($session);
     /*
      * Basset variables are set at the end of one round,
      * then accessed when the next round has already started.
      * However, for the user writing the template, the "current" round
      * should actually still be the last round.
      * We therefore use the status of the current session to determine 
      * where in the process we are.
      */
     if ($session->getStatus() == Session::finished_step) {
         // we are at the end of a step, where the variables are set.
         // we use the current round in the session
         $round = $session->currentRound();
     } elseif ($session->getStatus() == Session::awaiting_user_input) {
         // we are at the beginning of a step, where variables are read.
         // we want to use the previous step/repetition
         try {
             $round = $session->currentRound()->previousRound();
         } catch (DoesNotExistException $e) {
             // A DoesNotExistException thrown by previousRound means this is the first step.
             // There cannot be any step variables.
             // So we set them to NULL and exit.
             $this->step_variables = NULL;
             return;
             //TODO: create a blank instance of UserVariables, instead of NULL?
         }
     } else {
         throw new Exception('unknown use case for BassetVariables (created with status ' . $session->getStatus() . ')');
     }
     $this->step_variables = new StepVariables($session, $round);
     try {
         $group = $session->getGroup($round);
         $this->group_variables = new GroupRoundVariables($group, $session, $round);
     } catch (DoesNotExistException $e) {
         // there is no group for this step
         $this->group_variables = NULL;
     }
 }
示例#2
0
文件: Session.php 项目: blar/session
 /**
  * Resume a Session if a Cookie exists
  */
 public static function resume()
 {
     if (Session::getStatus() == Session::STATUS_ACTIVE) {
         return FALSE;
     }
     if (!Session::cookieExists()) {
         return FALSE;
     }
     Session::start();
 }