Beispiel #1
0
 public function apply($student_id, $game_id)
 {
     $lotteryCheck = $this->getByStudentId($student_id);
     if (!empty($lotteryCheck)) {
         throw new \Exception('Already applied to this lottery');
     }
     $now = time();
     $game = new \tailgate\Resource\Game();
     $game->setId($game_id);
     $gameFactory = new GameFactory();
     if (!$gameFactory->loadByID($game)) {
         throw new \Exception('Game does not exist.');
     }
     if ($game->getSignupStart() > $now) {
         throw new \Exception('Signup period has not started.');
     }
     if ($game->getSignupEnd() < $now) {
         throw new \Exception('Signup period is over.');
     }
     if ($game->getCompleted()) {
         throw new \Exception('This game lottery is complete. No more applications are allowed.');
     }
     $lottery = new Resource();
     $lottery->setGameId($game_id);
     $lottery->setStudentId($student_id);
     self::saveResource($lottery);
 }