/** * Creates a valid clarification */ public function testCreateValidClarification() { // Get a problem $problemData = ProblemsFactory::createProblem(); // Get a contest $contestData = ContestsFactory::createContest(); // Add the problem to the contest ContestsFactory::addProblemToContest($problemData, $contestData); // Create our contestant who will submit the clarification $contestant = UserFactory::createUser(); // Call the API $this->detourBroadcasterCalls(); $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant); // Assert status of new contest $this->assertArrayHasKey("clarification_id", $clarificationData['response']); // Verify that clarification was inserted in the database $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']); // Verify our retreived clarificatoin $this->assertNotNull($clarification); $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage()); // We need to verify that the contest and problem IDs where properly saved // Extractiing the contest and problem from DB to check IDs $problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]); $contest = ContestsDAO::getByAlias($contestData["request"]["alias"]); $this->assertEquals($contest->getContestId(), $clarification->getContestId()); $this->assertEquals($problem->getProblemId(), $clarification->getProblemId()); }
/** * Check in DB for problem added to contest * * @param array $problemData * @param array $contestData * @param Request $r */ public static function assertProblemAddedToContest($problemData, $contestData, $r) { // Get problem and contest from DB $problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]); $contest = ContestsDAO::getByAlias($contestData["request"]["alias"]); // Get problem-contest and verify it $contest_problems = ContestProblemsDAO::getByPK($contest->getContestId(), $problem->getProblemId()); self::assertNotNull($contest_problems); self::assertEquals($r["points"], $contest_problems->getPoints()); self::assertEquals($r["order_in_contest"], $contest_problems->getOrder()); }
/** * */ public function testViewProblemInAContestDetailsValid() { // Get a contest $contestData = ContestsFactory::createContest(); // Get a user to be the author $author = UserFactory::createUser(); // Get a problem $problemData = ProblemsFactory::createProblem(null, null, 1, $author); // Add the problem to the contest ContestsFactory::addProblemToContest($problemData, $contestData); // Get a user for our scenario $contestant = UserFactory::createUser(); // Prepare our request $r = new Request(); $r["contest_alias"] = $contestData["request"]["alias"]; $r["problem_alias"] = $problemData["request"]["alias"]; // Log in the user $r["auth_token"] = $this->login($contestant); // Explicitly join contest ContestController::apiOpen($r); // Call api $response = ProblemController::apiDetails($r); // Get problem and contest from DB to check it $problemDAO = ProblemsDAO::getByAlias($problemData["request"]["alias"]); $contestDAO = ContestsDAO::getByAlias($contestData["request"]["alias"]); $contestantsDAO = UsersDAO::search(new Users(array("username" => $contestant->getUsername()))); $contestantDAO = $contestantsDAO[0]; // Assert data $this->assertEquals($response["title"], $problemDAO->getTitle()); $this->assertEquals($response["alias"], $problemDAO->getAlias()); $this->assertEquals($response["validator"], $problemDAO->getValidator()); $this->assertEquals($response["time_limit"], $problemDAO->getTimeLimit()); $this->assertEquals($response["memory_limit"], $problemDAO->getMemoryLimit()); $this->assertEquals($response["problemsetter"]['username'], $author->username); $this->assertEquals($response["problemsetter"]['name'], $author->name); $this->assertEquals($response["source"], $problemDAO->getSource()); $this->assertContains("<h1>Entrada</h1>", $response["problem_statement"]); $this->assertEquals($response["order"], $problemDAO->getOrder()); $this->assertEquals($response["score"], 0); // Default data $this->assertEquals(0, $problemDAO->getVisits()); $this->assertEquals(0, $problemDAO->getSubmissions()); $this->assertEquals(0, $problemDAO->getAccepted()); $this->assertEquals(0, $problemDAO->getDifficulty()); // Verify that we have an empty array of runs $this->assertEquals(0, count($response["runs"])); // Verify that problem was marked as Opened $problem_opened = ContestProblemOpenedDAO::getByPK($contestDAO->getContestId(), $problemDAO->getProblemId(), $contestantDAO->getUserId()); $this->assertNotNull($problem_opened); // Verify open time $this->assertEquals(Utils::GetPhpUnixTimestamp(), Utils::GetPhpUnixTimestamp($problem_opened->getOpenTime())); }
/** * Validates that group alias and contest alias do exist * * @param Request $r * @throws InvalidDatabaseOperationException * @throws InvalidParameterException */ private static function validateGroupScoreboardAndContest(Request $r) { self::validateGroupScoreboard($r); Validators::isValidAlias($r["contest_alias"], "contest_alias"); try { $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]); } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } if (is_null($r["contest"])) { throw new InvalidParameterException("parameterNotFound", "Contest"); } if ($r["contest"]->public == 0 && !Authorization::IsContestAdmin($r["current_user_id"], $r["contest"])) { throw new ForbiddenAccessException(); } }
/** * Tests remove admins */ public function testRemoveAdmin() { // Get a contest $contestData = ContestsFactory::createContest(); // Get users $user = UserFactory::createUser(); $user2 = UserFactory::createUser(); ContestsFactory::addAdminUser($contestData, $user); ContestsFactory::addAdminUser($contestData, $user2); // Prepare request for remove one admin $r = new Request(); $r['auth_token'] = $this->login($contestData['director']); $r['usernameOrEmail'] = $user->getUsername(); $r['contest_alias'] = $contestData['request']['alias']; // Call api ContestController::apiRemoveAdmin($r); $contest = ContestsDAO::getByAlias($contestData['request']['alias']); $this->AssertFalse(Authorization::IsContestAdmin($user->getUserId(), $contest)); $this->AssertTrue(Authorization::IsContestAdmin($user2->getUserId(), $contest)); }
/** * Validate the request of apiCreate * * @param Request $r * @throws InvalidDatabaseOperationException * @throws NotFoundException */ private static function validateCreate(Request $r) { Validators::isStringNonEmpty($r["contest_alias"], "contest_alias"); Validators::isStringNonEmpty($r["problem_alias"], "problem_alias"); Validators::isStringNonEmpty($r["message"], "message"); try { $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]); $r["problem"] = ProblemsDAO::getByAlias($r["problem_alias"]); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r["contest"])) { throw new NotFoundException("contestNotFound"); } if (is_null($r["problem"])) { throw new NotFoundException("problemNotFound"); } // Is the combination contest_id and problem_id valid? if (is_null(ContestProblemsDAO::getByPK($r["contest"]->getContestId(), $r["problem"]->getProblemId()))) { throw new NotFoundException("problemNotFoundInContest"); } }
public static function setScoreboardPercentage($contestData, $percentage) { $contest = ContestsDAO::getByAlias($contestData['request']['alias']); $contest->setScoreboard($percentage); ContestsDAO::save($contest); }
/** * * Validates Create Run request * * @param Request $r * @throws ApiException * @throws InvalidDatabaseOperationException * @throws NotAllowedToSubmitException * @throws InvalidParameterException * @throws ForbiddenAccessException */ private static function validateCreateRequest(Request $r) { // https://github.com/omegaup/omegaup/issues/739 if ($r['current_user']->username == 'omi') { throw new ForbiddenAccessException(); } $allowedLanguages = array('kp', 'kj', 'c', 'cpp', 'cpp11', 'java', 'py', 'rb', 'pl', 'cs', 'pas', 'cat', 'hs'); try { Validators::isStringNonEmpty($r['problem_alias'], 'problem_alias'); // Check that problem exists $r['problem'] = ProblemsDAO::getByAlias($r['problem_alias']); if ($r['problem']->deprecated) { throw new PreconditionFailedException('problemDeprecated'); } $allowedLanguages = array_intersect($allowedLanguages, explode(',', $r['problem']->languages)); Validators::isInEnum($r['language'], 'language', $allowedLanguages); Validators::isStringNonEmpty($r['source'], 'source'); // Check for practice or public problem, there is no contest info in this scenario if ($r['contest_alias'] == '') { if (Authorization::IsProblemAdmin($r['current_user_id'], $r['problem']) || time() > ProblemsDAO::getPracticeDeadline($r['problem']->getProblemId()) || $r['problem']->getPublic() == true) { if (!RunsDAO::IsRunInsideSubmissionGap(null, $r['problem']->getProblemId(), $r['current_user_id']) && !Authorization::IsSystemAdmin($r['current_user_id'])) { throw new NotAllowedToSubmitException('runWaitGap'); } self::$practice = true; return; } else { throw new NotAllowedToSubmitException('problemIsNotPublic'); } } // Validate contest Validators::isStringNonEmpty($r['contest_alias'], 'contest_alias'); $r['contest'] = ContestsDAO::getByAlias($r['contest_alias']); if ($r['contest'] == null) { throw new InvalidParameterException('parameterNotFound', 'contest_alias'); } if ($r['contest']->languages !== null) { $allowedLanguages = array_intersect($allowedLanguages, explode(',', $r['contest']->languages)); Validators::isInEnum($r['language'], 'language', $allowedLanguages); } // Validate that the combination contest_id problem_id is valid if (!ContestProblemsDAO::getByPK($r['contest']->getContestId(), $r['problem']->getProblemId())) { throw new InvalidParameterException('parameterNotFound', 'problem_alias'); } // Contest admins can skip following checks if (!Authorization::IsContestAdmin($r['current_user_id'], $r['contest'])) { // Before submit something, contestant had to open the problem/contest if (!ContestsUsersDAO::getByPK($r['current_user_id'], $r['contest']->getContestId())) { throw new NotAllowedToSubmitException('runNotEvenOpened'); } // Validate that the run is timely inside contest if (!ContestsDAO::isInsideContest($r['contest'], $r['current_user_id'])) { throw new NotAllowedToSubmitException('runNotInsideContest'); } // Validate if contest is private then the user should be registered if ($r['contest']->getPublic() == 0 && is_null(ContestsUsersDAO::getByPK($r['current_user_id'], $r['contest']->getContestId()))) { throw new NotAllowedToSubmitException('runNotRegistered'); } // Validate if the user is allowed to submit given the submissions_gap if (!RunsDAO::IsRunInsideSubmissionGap($r['contest']->getContestId(), $r['problem']->getProblemId(), $r['current_user_id'])) { throw new NotAllowedToSubmitException('runWaitGap'); } } } catch (ApiException $apiException) { // Propagate ApiException throw $apiException; } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } }
/** * Validates that request contains contest_alias and the api is contest-admin only * * @param Request $r * @throws InvalidDatabaseOperationException * @throws ForbiddenAccessException */ private static function validateStats(Request $r) { Validators::isStringNonEmpty($r["contest_alias"], "contest_alias"); try { $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // This API is Contest Admin only if (is_null($r["contest"]) || !Authorization::IsContestAdmin($r["current_user_id"], $r["contest"])) { throw new ForbiddenAccessException("userNotAllowed"); } }
/** * Given a contest_alias, sets the recommended flag on/off. * Only omegaUp admins can call this API. * * @param Request $r * @return array */ public static function apiSetRecommended(Request $r) { self::authenticateRequest($r); if (!Authorization::IsSystemAdmin($r['current_user_id'])) { throw new ForbiddenAccessException('userNotAllowed'); } // Validate & get contest_alias try { $r['contest'] = ContestsDAO::getByAlias($r['contest_alias']); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r['contest'])) { throw new NotFoundException('contestNotFound'); } // Validate value param Validators::isInEnum($r['value'], 'value', array('0', '1')); $r['contest']->recommended = $r['value']; try { ContestsDAO::save($r['contest']); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } return array('status' => 'ok'); }
/** * Entry point for Problem Details API * * @param Request $r * @throws InvalidFilesystemOperationException * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { // Get user. // Allow unauthenticated requests if we are not openning a problem // inside a contest. try { self::authenticateRequest($r); } catch (UnauthorizedException $e) { if (!is_null($r['contest_alias'])) { throw $e; } } // Validate request self::validateDetails($r); $response = array(); // Create array of relevant columns $relevant_columns = array('title', 'alias', 'validator', 'time_limit', 'validator_time_limit', 'overall_wall_time_limit', 'extra_wall_time', 'memory_limit', 'output_limit', 'visits', 'submissions', 'accepted', 'difficulty', 'creation_date', 'source', 'order', 'points', 'public', 'languages', 'slow', 'stack_limit', 'email_clarifications'); // Read the file that contains the source if (!ProblemController::isLanguageSupportedForProblem($r)) { // If there is no language file for the problem, return the spanish version. $r['lang'] = 'es'; } $statement_type = ProblemController::getStatementType($r); Cache::getFromCacheOrSet(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $r['lang'] . '-' . $statement_type, $r, 'ProblemController::getProblemStatement', $file_content, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT); // Add problem statement to source $response['problem_statement'] = $file_content; $response['problem_statement_language'] = $r['lang']; // Add the example input. $sample_input = null; Cache::getFromCacheOrSet(Cache::PROBLEM_SAMPLE, $r['problem']->getAlias() . '-sample.in', $r, 'ProblemController::getSampleInput', $sample_input, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT); if (!empty($sample_input)) { $response['sample_input'] = $sample_input; } // Add the problem the response $response = array_merge($response, $r['problem']->asFilteredArray($relevant_columns)); // If the problem is public or if the user has admin privileges, show the // problem source and alias of owner. if ($r['problem']->public || Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) { $problemsetter = UsersDAO::getByPK($r['problem']->author_id); if (!is_null($problemsetter)) { $response['problemsetter'] = array('username' => $problemsetter->username, 'name' => is_null($problemsetter->name) ? $problemsetter->username : $problemsetter->name); } } else { unset($response['source']); } if (!is_null($r['current_user_id'])) { // Create array of relevant columns for list of runs $relevant_columns = array('guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay'); // Search the relevant runs from the DB $contest = ContestsDAO::getByAlias($r['contest_alias']); $keyrun = new Runs(array('user_id' => $r['current_user_id'], 'problem_id' => $r['problem']->getProblemId(), 'contest_id' => is_null($r['contest']) ? null : $r['contest']->getContestId())); // Get all the available runs done by the current_user try { $runs_array = RunsDAO::search($keyrun); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add each filtered run to an array if (count($runs_array) >= 0) { $runs_filtered_array = array(); foreach ($runs_array as $run) { $filtered = $run->asFilteredArray($relevant_columns); $filtered['alias'] = $r['problem']->alias; $filtered['username'] = $r['current_user']->username; $filtered['time'] = strtotime($filtered['time']); array_push($runs_filtered_array, $filtered); } } $response['runs'] = $runs_filtered_array; } if (!is_null($r['contest'])) { // At this point, contestant_user relationship should be established. try { 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); } // As last step, register the problem as opened if (!ContestProblemOpenedDAO::getByPK($r['contest']->getContestId(), $r['problem']->getProblemId(), $r['current_user_id'])) { //Create temp object $keyContestProblemOpened = new ContestProblemOpened(array('contest_id' => $r['contest']->getContestId(), 'problem_id' => $r['problem']->getProblemId(), 'user_id' => $r['current_user_id'])); try { // Save object in the DB ContestProblemOpenedDAO::save($keyContestProblemOpened); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } } } elseif (isset($r['show_solvers']) && $r['show_solvers']) { $response['solvers'] = RunsDAO::GetBestSolvingRunsForProblem($r['problem']->problem_id); } if (!is_null($r['current_user_id'])) { ProblemViewedDAO::MarkProblemViewed($r['current_user_id'], $r['problem']->problem_id); } $response['score'] = self::bestScore($r); $response['status'] = 'ok'; return $response; }
/** * Try to view a contest before it has started * * @expectedException PreconditionFailedException */ public function testContestNotStartedYet() { // Get a contest $contestData = ContestsFactory::createContest(); // Get a user for our scenario $contestant = UserFactory::createUser(); // Set contest to not started yet $contest = ContestsDAO::getByAlias($contestData['request']['alias']); $contest->setStartTime(Utils::GetTimeFromUnixTimestamp(Utils::GetPhpUnixTimestamp() + 30)); ContestsDAO::save($contest); // Prepare our request $r = new Request(); $r['contest_alias'] = $contestData['request']['alias']; // Log in the user $r['auth_token'] = $this->login($contestant); // Call api $response = ContestController::apiDetails($r); }
if (property_exists($c->meta, "syscall-count")) { $page->addComponent("<td>" . $c->meta->{'syscall-count'} . " </td>"); } else { $page->addComponent("<td> - </td>"); } $page->addComponent("<td><strong>" . $c->meta->status . "</strong></td>"); $page->addComponent("</tr>"); $page->addComponent("</table>"); $page->addComponent("</td></tr>"); } } $page->addComponent("</td>"); $page->addComponent("</tr>"); } $page->addComponent("</table>"); $aV = ContestsDAO::getByAlias($_GET["alias"]); $eContest = new DAOFormComponent($aV); $eContest->setEditable(false); $page->addComponent($eContest); $page->nextTab("Envios"); $page->nextTab("Chavos"); $page->addComponent("Enviar correos, bannear, nuevos weyes, etc"); $page->nextTab("Stats"); $page->addComponent("GAnalitics u otras cosas, mostrar los auth tokens de los weyes que entraron al concurso con los diferentes ip's"); $page->nextTab("Editar"); $page->addComponent("<script>\n\t\tfunction doEditar(){\n\t\t\t\t var toSend = {};\n\t\t\t\t //upadateContes\n\t\t\t\t \$(\"table input\").each( function (n, el ){ \n\t\t\t\t \t\tif(el.value.length == 0 ) return;\n\t\t\t\t\t\ttoSend[ el.name ] = el.value;\n\t\t\t\t });\n\t\t\t\t\n\n\t\t\t\t\$.ajax({\n url: \"../api/contest/\" + toSend.alias + \"/update/\",\n dataType: \"json\",\n type:\"POST\",\n data: toSend,\n beforeSend: function( xhr ) {\n //\$(\"#submit\").hide();\n },\n success: function(a,b,c){\n \$(\"<p title='OmegaUp'>Success !</p>\").dialog({\n\t\t\t\t\t\t\t\tmodal: true,\n\t\t\t\t\t\t\t\tbuttons: {\n\t\t\t\t\t\t\t\t\tOk: function() {\n\t\t\t\t\t\t\t\t\t\t\$( this ).dialog( \"close\" );\n\t\t\t\t\t\t\t\t\t\twindow.location = \"contest.php?alias=\" + \$(\"#_alias\").val();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n },\n error:function(a,b,c){\n r = \$.parseJSON(a.responseText);\n \$(\"<p title='OmegaUp'>\"+r.error+\"</p>\").dialog({\n\t\t\t\t\t\t\t\tmodal: true,\n\t\t\t\t\t\t\t\tbuttons: {\n\t\t\t\t\t\t\t\t\tOk: function() {\n\t\t\t\t\t\t\t\t\t\t\$( this ).dialog( \"close\" );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n }\n \n });\n\t\t\t\tconsole.log(toSend);\n\n\t\t}</script>"); $eContest = new DAOFormComponent($aV); $eContest->setEditable(true); $eContest->hideField("contest_id"); $eContest->addOnClick("Editar concurso", "doEditar()"); $page->addComponent($eContest);
/** * Contest director is god, should be able to submit whenever he wants * for testing purposes */ public function testInvalidRunInsideSubmissionsGapForContestDirector() { // Set the context for the first contest $r = $this->setValidRequest(); $this->detourGraderCalls($this->exactly(2)); // Log as contest director $r["auth_token"] = $this->login($this->contestData["director"]); // Set submissions gap of 20 seconds $contest = ContestsDAO::getByAlias($r["contest_alias"]); $contest->setSubmissionsGap(20); ContestsDAO::save($contest); // Call API $response = RunController::apiCreate($r); // Validate the run $this->assertRun($r, $response); // Send a second run. This one should not fail $response = RunController::apiCreate($r); // Validate the run $this->assertRun($r, $response); }
/** * Entry point for Problem Details API * * @param Request $r * @throws InvalidFilesystemOperationException * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { // Get user. // Allow unauthenticated requests if we are not openning a problem // inside a contest. try { self::authenticateRequest($r); } catch (ForbiddenAccessException $e) { if (!is_null($r["contest_alias"])) { throw $e; } } // Validate request self::validateDetails($r); $response = array(); // Create array of relevant columns $relevant_columns = array("title", "author_id", "alias", "validator", "time_limit", "validator_time_limit", "overall_wall_time_limit", "extra_wall_time", "memory_limit", "output_limit", "visits", "submissions", "accepted", "difficulty", "creation_date", "source", "order", "points", "public", "languages", "slow", "stack_limit", "email_clarifications"); // Read the file that contains the source if (!ProblemController::isLanguageSupportedForProblem($r)) { // If there is no language file for the problem, return the spanish version. $r['lang'] = 'es'; } $statement_type = ProblemController::getStatementType($r); Cache::getFromCacheOrSet(Cache::PROBLEM_STATEMENT, $r["problem"]->getAlias() . "-" . $r["lang"] . "-" . $statement_type, $r, 'ProblemController::getProblemStatement', $file_content, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT); // Add problem statement to source $response["problem_statement"] = $file_content; $response["problem_statement_language"] = $r['lang']; // Add the example input. $sample_input = null; Cache::getFromCacheOrSet(Cache::PROBLEM_SAMPLE, $r["problem"]->getAlias() . "-sample.in", $r, 'ProblemController::getSampleInput', $sample_input, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT); if (!empty($sample_input)) { $response['sample_input'] = $sample_input; } // Add the problem the response $response = array_merge($response, $r["problem"]->asFilteredArray($relevant_columns)); if (!is_null($r['current_user_id'])) { // Create array of relevant columns for list of runs $relevant_columns = array("guid", "language", "status", "verdict", "runtime", "penalty", "memory", "score", "contest_score", "time", "submit_delay"); // Search the relevant runs from the DB $contest = ContestsDAO::getByAlias($r["contest_alias"]); $keyrun = new Runs(array("user_id" => $r["current_user_id"], "problem_id" => $r["problem"]->getProblemId(), "contest_id" => is_null($r["contest"]) ? null : $r["contest"]->getContestId())); // Get all the available runs done by the current_user try { $runs_array = RunsDAO::search($keyrun); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add each filtered run to an array if (count($runs_array) >= 0) { $runs_filtered_array = array(); foreach ($runs_array as $run) { $filtered = $run->asFilteredArray($relevant_columns); $filtered['time'] = strtotime($filtered['time']); array_push($runs_filtered_array, $filtered); } } $response["runs"] = $runs_filtered_array; } if (!is_null($r["contest"])) { // At this point, contestant_user relationship should be established. 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); } // As last step, register the problem as opened if (!ContestProblemOpenedDAO::getByPK($r["contest"]->getContestId(), $r["problem"]->getProblemId(), $r["current_user_id"])) { //Create temp object $keyContestProblemOpened = new ContestProblemOpened(array("contest_id" => $r["contest"]->getContestId(), "problem_id" => $r["problem"]->getProblemId(), "user_id" => $r["current_user_id"])); try { // Save object in the DB ContestProblemOpenedDAO::save($keyContestProblemOpened); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } } } else { if (isset($r['show_solvers']) && $r['show_solvers']) { $response['solvers'] = RunsDAO::GetBestSolvingRunsForProblem($r['problem']->problem_id); } } if (!is_null($r['current_user_id'])) { ProblemViewedDAO::MarkProblemViewed($r['current_user_id'], $r['problem']->problem_id); } $response["score"] = self::bestScore($r); $response["status"] = "ok"; return $response; }
/** * Returns a list of contests * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiRefresh(Request $r) { // This is not supposed to be called by end-users, but by the // Grader service. Regular sessions cannot be used since they // expire, so use a pre-shared secret to authenticate that // grants admin-level privileges just for this call. if ($r['token'] !== OMEGAUP_GRADER_SECRET) { throw new ForbiddenAccessException(); } $contest = ContestsDAO::getByAlias($r['alias']); if ($contest === null) { throw new NotFoundException(); } $id = $contest->getContestId(); Scoreboard::RefreshScoreboardCache($id); return array('status' => 'ok'); }