aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/app
diff options
context:
space:
mode:
Diffstat (limited to 'services/app')
-rw-r--r--services/app/src/App.php2
-rw-r--r--services/app/src/Repositories/AnswerRepository.php33
2 files changed, 11 insertions, 24 deletions
diff --git a/services/app/src/App.php b/services/app/src/App.php
index ec64efd..cd7798f 100644
--- a/services/app/src/App.php
+++ b/services/app/src/App.php
@@ -261,7 +261,7 @@ final class App
if ($quiz->isRankingHidden()) {
$ranking = null;
} else {
- $ranking = $answerRepo->getRankingByBestScores($quiz->quiz_id, upto: 20);
+ $ranking = $answerRepo->getRankingByBestScores($quiz->quiz_id, upto: null);
}
return $this->render($request, $response, 'quiz_view.html.twig', [
diff --git a/services/app/src/Repositories/AnswerRepository.php b/services/app/src/Repositories/AnswerRepository.php
index 7ea3d4f..6ccfb32 100644
--- a/services/app/src/Repositories/AnswerRepository.php
+++ b/services/app/src/Repositories/AnswerRepository.php
@@ -94,28 +94,10 @@ final class AnswerRepository
}
/**
- * @param positive-int $upto
+ * @param ?positive-int $upto
* @return Answer[]
*/
- public function getRanking(int $quiz_id, int $upto): array
- {
- $result = $this->conn
- ->query()
- ->select('answers')
- ->leftJoin('users', 'answers.author_id = users.user_id')
- ->fields([...self::ANSWER_FIELDS, ...self::ANSWER_JOIN_USER_FIELDS])
- ->where('quiz_id = :quiz_id AND execution_status = :execution_status')
- ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']])
- ->limit($upto)
- ->execute(['quiz_id' => $quiz_id, 'execution_status' => AggregatedExecutionStatus::OK->toInt()]);
- return array_map($this->mapRawRowToAnswer(...), $result);
- }
-
- /**
- * @param positive-int $upto
- * @return Answer[]
- */
- public function getRankingByBestScores(int $quiz_id, int $upto): array
+ public function getRankingByBestScores(int $quiz_id, ?int $upto): array
{
$q = $this->conn
->query()
@@ -128,7 +110,7 @@ final class AnswerRepository
])
->where('quiz_id = :quiz_id AND execution_status = :execution_status');
- $result = $this->conn
+ $query = $this->conn
->query()
->select($q)
->fields([
@@ -137,8 +119,13 @@ final class AnswerRepository
'author_is_admin',
])
->where('r = 1')
- ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']])
- ->limit($upto)
+ ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']]);
+
+ if ($upto !== null) {
+ $query = $query->limit($upto);
+ }
+
+ $result = $query
->execute(['quiz_id' => $quiz_id, 'execution_status' => AggregatedExecutionStatus::OK->toInt()]);
return array_map($this->mapRawRowToAnswer(...), $result);
}