*/ class CandidateRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Candidate::class); } public function getCandidateByHash(Season $season, string $hash): ?Candidate { try { $name = Base64::base64UrlDecode($hash); } catch (UrlException) { return null; } return $this->getEntityManager()->createQuery(<<setParameter('season', $season) ->setParameter('name', $name) ->getOneOrNullResult(); } public function save(Candidate $candidate, bool $flush = true): void { $this->getEntityManager()->persist($candidate); if ($flush) { $this->getEntityManager()->flush(); } } /** * @throws DatetimeException * * @return list */ public function getScores(Quiz $quiz): array { $result = $this->getEntityManager()->createQuery(<<setParameter('quiz', $quiz)->getResult(); return array_map(static fn (array $row): Result => new Result( id: $row['id'], name: $row['name'], correct: (int) $row['correct'], corrections: $row['corrections'], time: new DateTimeImmutable($row['end_time'])->diff($row['start_time']), score: $row['score'], ), $result); } }