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; } }
/** * Attempts to form a group with all the members of the group from the previous round. * If a group can be formed, sets it as the current group for all of its members, * then returns that group. * Otherwise, sets the current status of this session to Session::group_request_pending, * then returns FALSE. * * A group is considered "ready to be formed" when the status of each of its members * is Session::group_request_pending. * * @param Session $session * @return Group if the group is formed, FALSE otherwise */ public static function getOldGroup(Session $session) { // set given group's satus as "request pending". this is for internal state checks. $session->setStatus(Session::group_request_pending); // get the group for the previous round $previous_group = $session->getGroup($session->currentRound()->previousRound()); // are all members ready? $ready = array_reduce($previous_group->members, function ($v, $w) { return $v && $w->getStatus() == Session::group_request_pending; }, TRUE); if ($ready) { // let the group members know they're in a group self::setSessionsGroup($previous_group->members, $previous_group); return $previous_group; } else { return FALSE; } }