mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 04:44:19 +01:00
Refactor elimination feature and improve backoffice usability
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.
This commit is contained in:
38
src/Factory/EliminationFactory.php
Normal file
38
src/Factory/EliminationFactory.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user