mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-05 20:44:19 +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
65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Entity;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Gedmo\Mapping\Annotation as Gedmo;
|
|
use Symfony\Bridge\Doctrine\Types\UuidType;
|
|
use Symfony\Component\HttpFoundation\InputBag;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Tvdt\Repository\EliminationRepository;
|
|
|
|
#[ORM\Entity(repositoryClass: EliminationRepository::class)]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
class Elimination
|
|
{
|
|
public const string SCREEN_GREEN = 'green';
|
|
|
|
public const string SCREEN_RED = 'red';
|
|
|
|
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
|
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
|
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
|
#[ORM\Id]
|
|
public private(set) Uuid $id;
|
|
|
|
/** @var array<string, mixed> */
|
|
#[ORM\Column(type: Types::JSONB)]
|
|
public array $data = [];
|
|
|
|
#[Gedmo\Timestampable(on: 'create')]
|
|
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
|
public private(set) \DateTimeImmutable $created;
|
|
|
|
public function __construct(
|
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
|
#[ORM\ManyToOne(inversedBy: 'eliminations')]
|
|
public Quiz $quiz,
|
|
) {}
|
|
|
|
/** @param InputBag<bool|float|int|string> $inputBag */
|
|
public function updateFromInputBag(InputBag $inputBag): self
|
|
{
|
|
foreach (array_keys($this->data) as $name) {
|
|
$newColour = $inputBag->get('colour-'.mb_strtolower($name));
|
|
if (\is_string($newColour)) {
|
|
$this->data[$name] = $inputBag->get('colour-'.mb_strtolower($name));
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getScreenColour(?string $name): ?string
|
|
{
|
|
if (null === $name) {
|
|
return null;
|
|
}
|
|
|
|
return $this->data[$name] ?? null;
|
|
}
|
|
}
|