Files
TijdVoorDeTest/src/Repository/QuestionRepository.php
Marijn Doeve b66d2f9e86
Some checks failed
CI / Tests (push) Failing after 35s
CI / Deploy (push) Has been skipped
Refactor entities and codebase for native property usage
- Replaced getters/setters with direct property access across entities and repositories.
- Added and configured `martin-georgiev/postgresql-for-doctrine` for PostgreSQL enhancements.
- Updated Doctrine configuration with types, mappings, and JSONB query functions.
- Removed unused `EliminationService` and related YAML configurations.
2025-10-08 20:50:33 +02:00

42 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tvdt\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Tvdt\Entity\Candidate;
use Tvdt\Entity\Question;
/**
* @extends ServiceEntityRepository<Question>
*/
class QuestionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Question::class);
}
public function findNextQuestionForCandidate(Candidate $candidate): ?Question
{
return $this->getEntityManager()->createQuery(<<<DQL
select q from Tvdt\Entity\Question q
join q.quiz qz
where q.id not in (
select q1.id from Tvdt\Entity\GivenAnswer ga
join ga.answer a
join a.question q1
where ga.candidate = :candidate
and q1.quiz = :quiz
)
and qz = :quiz
DQL)
->setMaxResults(1)
->setParameter('candidate', $candidate)
->setParameter('quiz', $candidate->season->activeQuiz)
->getOneOrNullResult();
}
}