mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 12:44:20 +01:00
* Some tests * More tests! * Tests 3 * Move getScores from Candidate to Quiz * Add some suggestions for future refactoring * - **Add Gedmo doctrine-extensions and Stof bundle integration** - Added `stof/doctrine-extensions-bundle` and `gedmo/doctrine-extensions` dependencies. - Integrated `Timestampable` behavior for `Created` fields in entities. - Updated `bundles.php` to register StofDoctrineExtensionsBundle. - Added configuration for the Stof bundle. - Simplified `SeasonVoter` with `match` expression and added new tests. - Minor fixes and adjustments across various files. * WIP * All the tests * Base64 tests * Symfomny 7.4.0 * Update * Update recipe * PHP 8.5 * Rector changes * More 8.5 * Things
39 lines
919 B
PHP
39 lines
919 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Factory;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Tvdt\Entity\Elimination;
|
|
use Tvdt\Entity\Quiz;
|
|
use Tvdt\Repository\QuizRepository;
|
|
|
|
final readonly class EliminationFactory
|
|
{
|
|
public function __construct(
|
|
private QuizRepository $quizRepository,
|
|
private EntityManagerInterface $em,
|
|
) {}
|
|
|
|
public function createEliminationFromQuiz(Quiz $quiz): Elimination
|
|
{
|
|
$elimination = new Elimination($quiz);
|
|
$this->em->persist($elimination);
|
|
|
|
$scores = $this->quizRepository->getScores($quiz);
|
|
|
|
$simpleScores = [];
|
|
|
|
foreach (array_reverse($scores) as $i => $score) {
|
|
$simpleScores[$score->name] = $i < $quiz->dropouts ? Elimination::SCREEN_RED : Elimination::SCREEN_GREEN;
|
|
}
|
|
|
|
$elimination->data = $simpleScores;
|
|
|
|
$this->em->flush();
|
|
|
|
return $elimination;
|
|
}
|
|
}
|