/** * Returns the best score of a problem. * Problem must be loadad in $r["problem"] * Contest could be loadad in $r["contest"]. If set, will only look for * runs inside that contest. * * Authentication is expected to be performed earlier. * * @param Request $r * @return float * @throws InvalidDatabaseOperationException */ private static function bestScore(Request $r, Users $user = null) { $current_user_id = is_null($user) ? $r['current_user_id'] : $user->getUserId(); if (is_null($current_user_id)) { return 0; } $score = 0; try { // Add best score info if (is_null($r['contest'])) { $score = RunsDAO::GetBestScore($r['problem']->getProblemId(), $current_user_id); } else { $bestRun = RunsDAO::GetBestRun($r['contest']->getContestId(), $r['problem']->getProblemId(), $current_user_id, strtotime($r['contest']->getFinishTime()), false); $score = is_null($bestRun->getContestScore()) ? 0 : $bestRun->getContestScore(); } } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } return $score; }