diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-03-10 12:48:43 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-03-10 12:48:43 +0900 |
| commit | e73324f8f6db9ee2fe218c11f135134f7f66057d (patch) | |
| tree | b580aa1eea0c2cba37cca84c3acdb1fe115c99a5 /services/app/src/Repositories/AnswerRepository.php | |
| parent | 9dd611a2fd1fc1d62511161639b3ede824075130 (diff) | |
| download | phperkaigi-2024-albatross-e73324f8f6db9ee2fe218c11f135134f7f66057d.tar.gz phperkaigi-2024-albatross-e73324f8f6db9ee2fe218c11f135134f7f66057d.tar.zst phperkaigi-2024-albatross-e73324f8f6db9ee2fe218c11f135134f7f66057d.zip | |
remove limit of the number of shown users in ranking
Diffstat (limited to 'services/app/src/Repositories/AnswerRepository.php')
| -rw-r--r-- | services/app/src/Repositories/AnswerRepository.php | 33 |
1 files changed, 10 insertions, 23 deletions
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); } |
