Пример #1
0
 /**
  * Get Contests which a certain user has participated in
  *
  * @param Request $r
  * @return Contests array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiContestStats(Request $r)
 {
     self::authenticateOrAllowUnauthenticatedRequest($r);
     $response = array();
     $response['contests'] = array();
     $user = self::resolveTargetUser($r);
     // Get contests where user had at least 1 run
     try {
         $contestsParticipated = ContestsDAO::getContestsParticipated($user->getUserId());
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     }
     $contests = array();
     foreach ($contestsParticipated as $contest) {
         // Get user ranking
         $scoreboardR = new Request(array('auth_token' => $r['auth_token'], 'contest_alias' => $contest->getAlias(), 'token' => $contest->getScoreboardUrlAdmin()));
         $scoreboardResponse = ContestController::apiScoreboard($scoreboardR);
         // Grab the place of the current user in the given contest
         $contests[$contest->getAlias()]['place'] = null;
         foreach ($scoreboardResponse['ranking'] as $userData) {
             if ($userData['username'] == $user->getUsername()) {
                 $contests[$contest->getAlias()]['place'] = $userData['place'];
                 break;
             }
         }
         $contest->toUnixTime();
         $contests[$contest->getAlias()]['data'] = $contest->asArray();
     }
     $response['contests'] = $contests;
     $response['status'] = 'ok';
     return $response;
 }
Пример #2
0
 /**
  * Get Contests which a certain user has participated in
  * 
  * @param Request $r
  * @return Contests array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiContestStats(Request $r)
 {
     self::authenticateOrAllowUnauthenticatedRequest($r);
     $response = array();
     $response["contests"] = array();
     $user = self::resolveTargetUser($r);
     $contest_user_key = new ContestsUsers();
     $contest_user_key->setUserId($user->getUserId());
     // Get contests where user had at least 1 run
     try {
         $contestsParticipated = ContestsDAO::getContestsParticipated($user->getUserId());
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     }
     $contests = array();
     foreach ($contestsParticipated as $contest) {
         // Get user ranking
         $scoreboardR = new Request(array("auth_token" => $r["auth_token"], "contest_alias" => $contest->getAlias(), "token" => $contest->getScoreboardUrlAdmin()));
         $scoreboardResponse = ContestController::apiScoreboard($scoreboardR);
         // Grab the place of the current user in the given contest
         $contests[$contest->getAlias()]["place"] = null;
         foreach ($scoreboardResponse["ranking"] as $userData) {
             if ($userData["username"] == $user->getUsername()) {
                 $contests[$contest->getAlias()]["place"] = $userData["place"];
                 break;
             }
         }
         $contest->toUnixTime();
         $contests[$contest->getAlias()]["data"] = $contest->asArray();
     }
     $response["contests"] = $contests;
     $response["status"] = "ok";
     return $response;
 }