diff --git a/.idea/php.xml b/.idea/php.xml
index d1445bb..c04d845 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -26,6 +26,11 @@
+
+
+
+
+
diff --git a/config/packages/security.yaml b/config/packages/security.yaml
index 58a5c8e..7f5b574 100644
--- a/config/packages/security.yaml
+++ b/config/packages/security.yaml
@@ -37,7 +37,7 @@ security:
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
- # - { path: ^/profile, roles: ROLE_USER }
+ - { path: ^/backoffice, roles: ROLE_USER }
when@test:
security:
diff --git a/src/Controller/Backoffice/QuizController.php b/src/Controller/Backoffice/QuizController.php
index 538eebc..c3bac3b 100644
--- a/src/Controller/Backoffice/QuizController.php
+++ b/src/Controller/Backoffice/QuizController.php
@@ -51,7 +51,7 @@ class QuizController extends AbstractController
#[Route(
'/backoffice/season/{seasonCode:season}/quiz/{quiz}/enable',
name: 'app_backoffice_enable',
- requirements: ['seasonCode' => self::SEASON_CODE_REGEX, 'quiz' => Requirement::UUID],
+ requirements: ['seasonCode' => self::SEASON_CODE_REGEX, 'quiz' => Requirement::UUID.'|null'],
)]
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]
public function enableQuiz(Season $season, ?Quiz $quiz, EntityManagerInterface $em): RedirectResponse
diff --git a/src/Repository/CandidateRepository.php b/src/Repository/CandidateRepository.php
index 01029a9..c314ef8 100644
--- a/src/Repository/CandidateRepository.php
+++ b/src/Repository/CandidateRepository.php
@@ -34,12 +34,14 @@ class CandidateRepository extends ServiceEntityRepository
return null;
}
- return $this->createQueryBuilder('c')
- ->where('c.season = :season')
- ->andWhere('lower(c.name) = lower(:name)')
- ->setParameter('season', $season)
+ return $this->getEntityManager()->createQuery(<<setParameter('season', $season)
->setParameter('name', $name)
- ->getQuery()->getOneOrNullResult();
+ ->getOneOrNullResult();
}
public function save(Candidate $candidate, bool $flush = true): void
@@ -54,44 +56,22 @@ class CandidateRepository extends ServiceEntityRepository
/** @return ResultList */
public function getScores(Quiz $quiz): array
{
- $qb = $this->createQueryBuilder('c', 'c.id')
- ->select('c.id', 'c.name', 'sum(case when a.isRightAnswer = true then 1 else 0 end) as correct', 'qc.corrections', 'max(ga.created) - qc.created as time')
- ->join('c.givenAnswers', 'ga')
- ->join('ga.answer', 'a')
- ->join('c.quizData', 'qc')
- ->where('qc.quiz = :quiz')
- ->groupBy('ga.quiz', 'c.id', 'qc.id')
- ->setParameter('quiz', $quiz);
-
- return $this->sortResults(
- $this->calculateScore(
- $qb->getQuery()->getResult(),
- ),
- );
- }
-
- /**
- * @param array $in
- *
- * @return array
- */
- private function calculateScore(array $in): array
- {
- return array_map(static fn ($candidate): array => [
- ...$candidate,
- 'score' => $candidate['correct'] + $candidate['corrections'],
- ], $in);
- }
-
- /**
- * @param array $results
- *
- * @return ResultList
- * */
- private function sortResults(array $results): array
- {
- usort($results, static fn ($a, $b): int => $b['score'] <=> $a['score']);
-
- return $results;
+ return $this->getEntityManager()->createQuery(<<setParameter('quiz', $quiz)->getResult();
}
}
diff --git a/src/Repository/QuestionRepository.php b/src/Repository/QuestionRepository.php
index 2bbb123..77bbd0a 100644
--- a/src/Repository/QuestionRepository.php
+++ b/src/Repository/QuestionRepository.php
@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Repository;
use App\Entity\Candidate;
-use App\Entity\GivenAnswer;
use App\Entity\Question;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -22,22 +21,21 @@ class QuestionRepository extends ServiceEntityRepository
public function findNextQuestionForCandidate(Candidate $candidate): ?Question
{
- $qb = $this->createQueryBuilder('q');
-
- return $qb->join('q.quiz', 'qz')
- ->andWhere($qb->expr()->notIn('q.id', $this->getEntityManager()->createQueryBuilder()
- ->select('q1')
- ->from(GivenAnswer::class, 'ga')
- ->join('ga.answer', 'a')
- ->join('a.question', 'q1')
- ->andWhere($qb->expr()->isNotNull('ga.answer'))
- ->andWhere('ga.candidate = :candidate')
- ->andWhere('q1.quiz = :quiz')
- ->getDQL()))
- ->andWhere('qz = :quiz')
+ return $this->getEntityManager()->createQuery(<<setMaxResults(1)
->setParameter('candidate', $candidate)
->setParameter('quiz', $candidate->getSeason()->getActiveQuiz())
- ->getQuery()->getOneOrNullResult();
+ ->getOneOrNullResult();
}
}
diff --git a/src/Repository/SeasonRepository.php b/src/Repository/SeasonRepository.php
index 2d09619..6ae3c7f 100644
--- a/src/Repository/SeasonRepository.php
+++ b/src/Repository/SeasonRepository.php
@@ -22,11 +22,9 @@ class SeasonRepository extends ServiceEntityRepository
/** @return list Returns an array of Season objects */
public function getSeasonsForUser(User $user): array
{
- $qb = $this->createQueryBuilder('s')
- ->where(':user MEMBER OF s.owners')
- ->orderBy('s.name')
- ->setParameter('user', $user);
-
- return $qb->getQuery()->getResult();
+ return $this->getEntityManager()->createQuery(<<setParameter('user', $user)->getResult();
}
}