コード例 #1
0
 /**
  * Returns details of a Contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiDetails(Request $r)
 {
     self::validateDetails($r);
     $result = array();
     self::getCachedDetails($r, $result);
     if (is_null($r['token'])) {
         // Adding timer info separately as it depends on the current user and we don't
         // want this to get generally cached for everybody
         // Save the time of the first access
         try {
             $contest_user = ContestsUsersDAO::CheckAndSaveFirstTimeAccess($r['current_user_id'], $r['contest']->contest_id);
         } catch (ApiException $e) {
             throw $e;
         } catch (Exception $e) {
             // Operation failed in the data layer
             throw new InvalidDatabaseOperationException($e);
         }
         // Add time left to response
         if ($r['contest']->getWindowLength() === null) {
             $result['submission_deadline'] = strtotime($r['contest']->getFinishTime());
         } else {
             $result['submission_deadline'] = min(strtotime($r['contest']->getFinishTime()), strtotime($contest_user->access_time) + $r['contest']->getWindowLength() * 60);
         }
         $result['admin'] = Authorization::IsContestAdmin($r['current_user_id'], $r['contest']);
         // Log the operation.
         ContestAccessLogDAO::save(new ContestAccessLog(array('user_id' => $r['current_user_id'], 'contest_id' => $r['contest']->contest_id, 'ip' => ip2long($_SERVER['REMOTE_ADDR']))));
     }
     $result['status'] = 'ok';
     return $result;
 }