Пример #1
0
 /**
  * Constructs a GroupRequestQueue with entries matching the specified game and step.
  * 
  * @param Game $game the desired game
  * @param Round $round the desired round
  */
 public function __construct(Game $game, Round $round)
 {
     $this->requests = array();
     $dbh = Database::handle();
     $sth = $dbh->prepare('SELECT * FROM group_requests WHERE game = :game AND step = :step');
     $sth->bindValue(':game', $game->getID());
     $sth->bindValue(':step', strval($round));
     $sth->execute();
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $expires = Util::sql2unixtime($row['expires']);
         if ($expires == 0) {
             $expires = NULL;
         }
         $this->requests[] = new GroupRequest(Session::fromSessionID($row['session']), $expires);
     }
 }
Пример #2
0
 /** @deprecated */
 public static function getGroup(Game $game, $step, Session $session)
 {
     $dbh = Database::handle();
     // find all groups with this game and step
     $sth = $dbh->prepare('SELECT * FROM groups WHERE game = :game AND step = :step');
     $sth->bindValue(':game', $game->getID());
     $sth->bindValue(':step', $step);
     $sth->execute();
     // find one that contains this session
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $session_ids = unserialize($row['sessions']);
         if (in_array($session->id, $session_ids)) {
             // use it to construct the group
             $sessions = array_map(function ($session_id) {
                 return Session::fromSessionID($session_id);
             }, $session_ids);
             return new Group($row['id'], $sessions, unserialize($row['data']));
         }
     }
     // couldn't find anything!
     throw new Exception('could not find group with matching game, step, and session');
 }
Пример #3
0
 /**
  * Returns the session identified by the given assignment id.
  * 
  * @param string $assignment_id the AMT assignment ID, a unique ID given by Amazon to each assignment
  * @param Game $game the game associated with this assignment (should be known because HitId is also passed)
  * @throws DoesNotExistException if there is no session with this assignment ID and game
  */
 public static function fromAssignmentID($assignment_id, Game $game)
 {
     $game_id = $game->getID();
     $dbh = Database::handle();
     $sth = $dbh->prepare('SELECT session_id FROM sessions WHERE assignment_id = ? AND game = ?');
     $sth->execute(array($assignment_id, $game_id));
     if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $session_id = $row['session_id'];
         return self::fromSessionID($session_id);
     } else {
         throw new DoesNotExistException('unknown assignment id');
     }
 }