Implement flash messages, refactor candidate retrieval, and enhance quiz functionality

This commit is contained in:
2025-03-04 22:20:35 +01:00
parent 26b99a8353
commit 29bc74fe4f
9 changed files with 88 additions and 17 deletions

View File

@@ -29,6 +29,11 @@ class CandidateRepository extends ServiceEntityRepository
return null;
}
return $this->findOneBy(['season' => $season, 'name' => $name]);
return $this->createQueryBuilder('c')
->where('c.season = :season')
->andWhere('lower(c.name) = lower(:name)')
->setParameter('season', $season)
->setParameter('name', $name)
->getQuery()->getOneOrNullResult();
}
}

View File

@@ -4,6 +4,8 @@ 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;
@@ -17,4 +19,25 @@ class QuestionRepository extends ServiceEntityRepository
{
parent::__construct($registry, Question::class);
}
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('ga.id')
->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')
->setMaxResults(1)
->setParameter('candidate', $candidate)
->setParameter('quiz', $candidate->getSeason()->getActiveQuiz())
->getQuery()->getSingleResult();
}
}