Refactor entities and codebase for native property usage
Some checks failed
CI / Tests (push) Failing after 35s
CI / Deploy (push) Has been skipped

- 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:
2025-10-07 21:46:20 +02:00
parent ab187a28b9
commit b66d2f9e86
51 changed files with 615 additions and 1023 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -41,7 +41,7 @@ class QuizCandidateRepository extends ServiceEntityRepository
throw new \InvalidArgumentException('Quiz candidate not found');
}
$quizCandidate->setCorrections($corrections);
$quizCandidate->corrections = $corrections;
$this->getEntityManager()->flush();
}
}

View File

@@ -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();
}
}