示例#1
0
 /**
  * Show the contest intro unless you are admin, or you
  * already started this contest.
  */
 public static function showContestIntro(Request $r)
 {
     try {
         $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]);
     } catch (Exception $e) {
         throw new NotFoundException("contestNotFound");
     }
     if (is_null($r['contest'])) {
         throw new NotFoundException("contestNotFound");
     }
     try {
         // Half-authenticate, in case there is no session in place.
         $session = SessionController::apiCurrentSession($r);
         if ($session['valid'] && !is_null($session['user'])) {
             $r["current_user"] = $session['user'];
             $r["current_user_id"] = $session['user']->user_id;
         }
         self::canAccessContest($r);
     } catch (Exception $e) {
         // Could not access contest. Private contests must not be leaked, so
         // unless they were manually added beforehand, show them a 404 error.
         if (!ContestController::isInvitedToContest($r)) {
             throw $e;
         }
         self::$log->error("Exception while trying to verify access: " . $e);
         return ContestController::SHOW_INTRO;
     }
     $cs = SessionController::apiCurrentSession();
     // You already started the contest.
     $contestOpened = ContestsUsersDAO::getByPK($r['current_user_id'], $r["contest"]->getContestId());
     if (!is_null($contestOpened) && $contestOpened->access_time != "0000-00-00 00:00:00") {
         self::$log->debug("Not intro because you already started the contest");
         return !ContestController::SHOW_INTRO;
     }
     return ContestController::SHOW_INTRO;
 }