mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 04:44:19 +01:00
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.
This commit is contained in:
@@ -6,8 +6,10 @@ namespace Tvdt\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Safe\Exceptions\DatetimeException;
|
||||
use Safe\Exceptions\UrlException;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Dto\Result;
|
||||
use Tvdt\Entity\Candidate;
|
||||
use Tvdt\Entity\Quiz;
|
||||
use Tvdt\Entity\Season;
|
||||
@@ -15,9 +17,6 @@ use Tvdt\Helpers\Base64;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Candidate>
|
||||
*
|
||||
* @phpstan-type Result array{id: Uuid, name: string, correct: int, time: \DateInterval, corrections: float, score: float}
|
||||
* @phpstan-type ResultList list<Result>
|
||||
*/
|
||||
class CandidateRepository extends ServiceEntityRepository
|
||||
{
|
||||
@@ -53,25 +52,39 @@ class CandidateRepository extends ServiceEntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/** @return ResultList */
|
||||
/**
|
||||
* @throws DatetimeException
|
||||
*
|
||||
* @return list<Result>
|
||||
*/
|
||||
public function getScores(Quiz $quiz): array
|
||||
{
|
||||
return $this->getEntityManager()->createQuery(<<<DQL
|
||||
$result = $this->getEntityManager()->createQuery(<<<DQL
|
||||
select
|
||||
c.id,
|
||||
c.name,
|
||||
count(case when a.isRightAnswer = true then 1 else null end) as correct,
|
||||
sum(case when a.isRightAnswer = true then 1 else 0 end) as correct,
|
||||
qc.corrections,
|
||||
max(ga.created) - qc.created as time,
|
||||
(count(case when a.isRightAnswer = true then 1 else null end) + qc.corrections) as score
|
||||
max(ga.created) as end_time,
|
||||
qc.created as start_time,
|
||||
(sum(case when a.isRightAnswer = true then 1 else 0 end) + qc.corrections) as score
|
||||
from Tvdt\Entity\Candidate c
|
||||
join c.givenAnswers ga
|
||||
join ga.answer a
|
||||
join c.quizData qc
|
||||
where qc.quiz = :quiz and ga.quiz = :quiz
|
||||
group by ga.quiz, c.id, qc.id
|
||||
order by score desc, time asc
|
||||
order by score desc, max(ga.created) - qc.created asc
|
||||
DQL
|
||||
)->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class QuestionRepository extends ServiceEntityRepository
|
||||
DQL)
|
||||
->setMaxResults(1)
|
||||
->setParameter('candidate', $candidate)
|
||||
->setParameter('quiz', $candidate->getSeason()->getActiveQuiz())
|
||||
->setParameter('quiz', $candidate->season->activeQuiz)
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class QuizCandidateRepository extends ServiceEntityRepository
|
||||
throw new \InvalidArgumentException('Quiz candidate not found');
|
||||
}
|
||||
|
||||
$quizCandidate->setCorrections($corrections);
|
||||
$quizCandidate->corrections = $corrections;
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
|
||||
* */
|
||||
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
|
||||
{
|
||||
$user->setPassword($newHashedPassword);
|
||||
$user->password = $newHashedPassword;
|
||||
$this->getEntityManager()->persist($user);
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
|
||||
throw new \InvalidArgumentException('User not found');
|
||||
}
|
||||
|
||||
$user->setRoles(['ROLE_ADMIN']);
|
||||
$user->roles = ['ROLE_ADMIN'];
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user