mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-05 20:44:19 +01:00
Implement flash messages, refactor candidate retrieval, and enhance quiz functionality
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user