mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-07 05:04:20 +01:00
This commit introduces a refactored EliminationFactory for better modularity, updates the elimination preparation process, and adds functionality to view eliminations. Backoffice templates and forms have been reorganized, minor translations were corrected, and additional assets like styles and flashes were included for enhanced user experience.
39 lines
944 B
PHP
39 lines
944 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Factory;
|
|
|
|
use App\Entity\Elimination;
|
|
use App\Entity\Quiz;
|
|
use App\Repository\CandidateRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
final readonly class EliminationFactory
|
|
{
|
|
public function __construct(
|
|
private CandidateRepository $candidateRepository,
|
|
private EntityManagerInterface $em,
|
|
) {}
|
|
|
|
public function createEliminationFromQuiz(Quiz $quiz): Elimination
|
|
{
|
|
$elimination = new Elimination($quiz);
|
|
$this->em->persist($elimination);
|
|
|
|
$scores = $this->candidateRepository->getScores($quiz);
|
|
|
|
$simpleScores = [];
|
|
|
|
foreach (array_reverse($scores) as $i => $score) {
|
|
$simpleScores[$score['name']] = $i < $quiz->getDropouts() ? Elimination::SCREEN_RED : Elimination::SCREEN_GREEN;
|
|
}
|
|
|
|
$elimination->setData($simpleScores);
|
|
|
|
$this->em->flush();
|
|
|
|
return $elimination;
|
|
}
|
|
}
|