/** * Returns details of a Contest. This is shared between apiDetails and * apiAdminDetails. * * @param Request $r * @param $result */ private static function getCachedDetails(Request $r, &$result) { Cache::getFromCacheOrSet(Cache::CONTEST_INFO, $r["contest_alias"], $r, function (Request $r) { // Create array of relevant columns $relevant_columns = array("title", "description", "start_time", "finish_time", "window_length", "alias", "scoreboard", "points_decay_factor", "partial_score", "submissions_gap", "feedback", "penalty", "time_start", "penalty_type", "penalty_calc_policy", "public", "show_scoreboard_after", "contestant_must_register", "languages"); // Initialize response to be the contest information $result = $r["contest"]->asFilteredArray($relevant_columns); $result['start_time'] = strtotime($result['start_time']); $result['finish_time'] = strtotime($result['finish_time']); try { $result['director'] = UsersDAO::getByPK($r['contest']->director_id)->username; } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Get problems of the contest $key_problemsInContest = new ContestProblems(array("contest_id" => $r["contest"]->getContestId())); try { $problemsInContest = ContestProblemsDAO::search($key_problemsInContest, "order"); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add info of each problem to the contest $problemsResponseArray = array(); // Set of columns that we want to show through this API. Doesn't include the SOURCE $relevant_columns = array("title", "alias", "validator", "time_limit", "overall_wall_time_limit", "extra_wall_time", "memory_limit", "visits", "submissions", "accepted", "dificulty", "order", "languages"); $letter = 0; foreach ($problemsInContest as $problemkey) { try { // Get the data of the problem $temp_problem = ProblemsDAO::getByPK($problemkey->getProblemId()); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add the 'points' value that is stored in the ContestProblem relationship $temp_array = $temp_problem->asFilteredArray($relevant_columns); $temp_array["points"] = $problemkey->getPoints(); $temp_array['letter'] = ContestController::columnName($letter++); if (!empty($result['languages'])) { $temp_array['languages'] = join(',', array_intersect(explode(',', $result['languages']), explode(',', $temp_array['languages']))); } // Save our array into the response array_push($problemsResponseArray, $temp_array); } // Add problems to response $result['problems'] = $problemsResponseArray; return $result; }, $result, APC_USER_CACHE_CONTEST_INFO_TIMEOUT); }
/** * Returns details of a Contest * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { self::validateDetails($r); Cache::getFromCacheOrSet(Cache::CONTEST_INFO, $r["contest_alias"], $r, function (Request $r) { // Create array of relevant columns $relevant_columns = array("title", "description", "start_time", "finish_time", "window_length", "alias", "scoreboard", "points_decay_factor", "partial_score", "submissions_gap", "feedback", "penalty", "time_start", "penalty_type", "penalty_calc_policy", "public", "show_scoreboard_after", "contestant_must_register", "languages"); // Initialize response to be the contest information $result = $r["contest"]->asFilteredArray($relevant_columns); $result['start_time'] = strtotime($result['start_time']); $result['finish_time'] = strtotime($result['finish_time']); try { $result['director'] = UsersDAO::getByPK($r['contest']->director_id)->username; } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Get problems of the contest $key_problemsInContest = new ContestProblems(array("contest_id" => $r["contest"]->getContestId())); try { $problemsInContest = ContestProblemsDAO::search($key_problemsInContest, "order"); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add info of each problem to the contest $problemsResponseArray = array(); // Set of columns that we want to show through this API. Doesn't include the SOURCE $relevant_columns = array("title", "alias", "validator", "time_limit", "overall_wall_time_limit", "extra_wall_time", "memory_limit", "visits", "submissions", "accepted", "dificulty", "order", "languages"); $letter = 0; foreach ($problemsInContest as $problemkey) { try { // Get the data of the problem $temp_problem = ProblemsDAO::getByPK($problemkey->getProblemId()); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add the 'points' value that is stored in the ContestProblem relationship $temp_array = $temp_problem->asFilteredArray($relevant_columns); $temp_array["points"] = $problemkey->getPoints(); $temp_array['letter'] = ContestController::columnName($letter++); if (!empty($result['languages'])) { $temp_array['languages'] = join(',', array_intersect(explode(',', $result['languages']), explode(',', $temp_array['languages']))); } // Save our array into the response array_push($problemsResponseArray, $temp_array); } // Add problems to response $result['problems'] = $problemsResponseArray; return $result; }, $result, APC_USER_CACHE_CONTEST_INFO_TIMEOUT); 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"]->getContestId()); } 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->getAccessTime()) + $r["contest"]->getWindowLength() * 60); } $result['admin'] = Authorization::IsContestAdmin($r["current_user_id"], $r["contest"]); } $result["status"] = "ok"; return $result; }