mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 12:44:20 +01:00
Refactor entities and codebase for native property usage
- 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:
@@ -8,7 +8,6 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\AnswerRepository;
|
||||
@@ -17,114 +16,45 @@ use Tvdt\Repository\AnswerRepository;
|
||||
class Answer
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT, options: ['default' => 0])]
|
||||
private int $ordering = 0;
|
||||
public int $ordering = 0;
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'answers')]
|
||||
private Question $question;
|
||||
public Question $question;
|
||||
|
||||
/** @var Collection<int, Candidate> */
|
||||
#[ORM\ManyToMany(targetEntity: Candidate::class, inversedBy: 'answersOnCandidate')]
|
||||
private Collection $candidates;
|
||||
public private(set) Collection $candidates;
|
||||
|
||||
/** @var Collection<int, GivenAnswer> */
|
||||
#[ORM\OneToMany(targetEntity: GivenAnswer::class, mappedBy: 'answer', orphanRemoval: true)]
|
||||
private Collection $givenAnswers;
|
||||
public private(set) Collection $givenAnswers;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Column(length: 255)]
|
||||
private string $text,
|
||||
public string $text,
|
||||
#[ORM\Column]
|
||||
private bool $isRightAnswer = false,
|
||||
public bool $isRightAnswer = false,
|
||||
) {
|
||||
$this->candidates = new ArrayCollection();
|
||||
$this->givenAnswers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getText(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function setText(string $text): static
|
||||
{
|
||||
$this->text = $text;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuestion(): Question
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
public function setQuestion(Question $question): static
|
||||
{
|
||||
$this->question = $question;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isRightAnswer(): bool
|
||||
{
|
||||
return $this->isRightAnswer;
|
||||
}
|
||||
|
||||
public function setRightAnswer(bool $isRightAnswer): static
|
||||
{
|
||||
$this->isRightAnswer = $isRightAnswer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Candidate> */
|
||||
public function getCandidates(): Collection
|
||||
{
|
||||
return $this->candidates;
|
||||
}
|
||||
|
||||
public function addCandidate(Candidate $candidate): static
|
||||
public function addCandidate(Candidate $candidate): void
|
||||
{
|
||||
if (!$this->candidates->contains($candidate)) {
|
||||
$this->candidates->add($candidate);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCandidate(Candidate $candidate): static
|
||||
public function removeCandidate(Candidate $candidate): void
|
||||
{
|
||||
$this->candidates->removeElement($candidate);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, GivenAnswer> */
|
||||
public function getGivenAnswers(): Collection
|
||||
{
|
||||
return $this->givenAnswers;
|
||||
}
|
||||
|
||||
public function getOrdering(): int
|
||||
{
|
||||
return $this->ordering;
|
||||
}
|
||||
|
||||
public function setOrdering(int $ordering): self
|
||||
{
|
||||
$this->ordering = $ordering;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Helpers\Base64;
|
||||
@@ -18,104 +17,52 @@ use Tvdt\Repository\CandidateRepository;
|
||||
class Candidate
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'candidates')]
|
||||
private Season $season;
|
||||
public Season $season;
|
||||
|
||||
/** @var Collection<int, Answer> */
|
||||
#[ORM\ManyToMany(targetEntity: Answer::class, mappedBy: 'candidates')]
|
||||
private Collection $answersOnCandidate;
|
||||
public private(set) Collection $answersOnCandidate;
|
||||
|
||||
/** @var Collection<int, GivenAnswer> */
|
||||
#[ORM\OneToMany(targetEntity: GivenAnswer::class, mappedBy: 'candidate', orphanRemoval: true)]
|
||||
private Collection $givenAnswers;
|
||||
public private(set) Collection $givenAnswers;
|
||||
|
||||
/** @var Collection<int, QuizCandidate> */
|
||||
#[ORM\OneToMany(targetEntity: QuizCandidate::class, mappedBy: 'candidate', orphanRemoval: true)]
|
||||
private Collection $quizData;
|
||||
public private(set) Collection $quizData;
|
||||
|
||||
public string $nameHash {
|
||||
get => Base64::base64UrlEncode($this->name);
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Column(length: 16)]
|
||||
private string $name,
|
||||
public string $name,
|
||||
) {
|
||||
$this->answersOnCandidate = new ArrayCollection();
|
||||
$this->givenAnswers = new ArrayCollection();
|
||||
$this->quizData = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSeason(): Season
|
||||
{
|
||||
return $this->season;
|
||||
}
|
||||
|
||||
public function setSeason(Season $season): static
|
||||
{
|
||||
$this->season = $season;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Answer> */
|
||||
public function getAnswersOnCandidate(): Collection
|
||||
{
|
||||
return $this->answersOnCandidate;
|
||||
}
|
||||
|
||||
public function addAnswersOnCandidate(Answer $answersOnCandidate): static
|
||||
public function addAnswersOnCandidate(Answer $answersOnCandidate): void
|
||||
{
|
||||
if (!$this->answersOnCandidate->contains($answersOnCandidate)) {
|
||||
$this->answersOnCandidate->add($answersOnCandidate);
|
||||
$answersOnCandidate->addCandidate($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAnswersOnCandidate(Answer $answersOnCandidate): static
|
||||
public function removeAnswersOnCandidate(Answer $answersOnCandidate): void
|
||||
{
|
||||
if ($this->answersOnCandidate->removeElement($answersOnCandidate)) {
|
||||
$answersOnCandidate->removeCandidate($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, GivenAnswer> */
|
||||
public function getGivenAnswers(): Collection
|
||||
{
|
||||
return $this->givenAnswers;
|
||||
}
|
||||
|
||||
/** @return Collection<int, QuizCandidate> */
|
||||
public function getQuizData(): Collection
|
||||
{
|
||||
return $this->quizData;
|
||||
}
|
||||
|
||||
public function getNameHash(): string
|
||||
{
|
||||
return Base64::base64UrlEncode($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\HttpFoundation\InputBag;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
@@ -22,48 +21,24 @@ class Elimination
|
||||
public const string SCREEN_RED = 'red';
|
||||
|
||||
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
#[ORM\Column(type: Types::JSON)]
|
||||
private array $data = [];
|
||||
#[ORM\Column(type: Types::JSONB)]
|
||||
public array $data = [];
|
||||
|
||||
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
||||
private \DateTimeImmutable $created;
|
||||
public private(set) \DateTimeImmutable $created;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
#[ORM\ManyToOne(inversedBy: 'eliminations')]
|
||||
private Quiz $quiz,
|
||||
public Quiz $quiz,
|
||||
) {}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
public function setData(array $data): self
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuiz(): Quiz
|
||||
{
|
||||
return $this->quiz;
|
||||
}
|
||||
|
||||
/** @param InputBag<bool|float|int|string> $inputBag */
|
||||
public function updateFromInputBag(InputBag $inputBag): self
|
||||
{
|
||||
@@ -87,9 +62,4 @@ class Elimination
|
||||
{
|
||||
$this->created = new DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getCreated(): \DateTimeInterface
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\GivenAnswerRepository;
|
||||
@@ -17,53 +16,28 @@ use Tvdt\Repository\GivenAnswerRepository;
|
||||
class GivenAnswer
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
||||
private \DateTimeImmutable $created;
|
||||
public private(set) \DateTimeImmutable $created;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'givenAnswers')]
|
||||
private Candidate $candidate,
|
||||
private(set) Candidate $candidate,
|
||||
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
#[ORM\ManyToOne]
|
||||
private Quiz $quiz,
|
||||
private(set) Quiz $quiz,
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'givenAnswers')]
|
||||
private Answer $answer,
|
||||
private(set) Answer $answer,
|
||||
) {}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCandidate(): Candidate
|
||||
{
|
||||
return $this->candidate;
|
||||
}
|
||||
|
||||
public function getQuiz(): Quiz
|
||||
{
|
||||
return $this->quiz;
|
||||
}
|
||||
|
||||
public function getAnswer(): Answer
|
||||
{
|
||||
return $this->answer;
|
||||
}
|
||||
|
||||
public function getCreated(): \DateTimeImmutable
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
#[ORM\PrePersist]
|
||||
public function setCreatedAtValue(): void
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\QuestionRepository;
|
||||
@@ -17,86 +16,39 @@ use Tvdt\Repository\QuestionRepository;
|
||||
class Question
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT, options: ['default' => 0])]
|
||||
private int $ordering;
|
||||
public int $ordering;
|
||||
|
||||
#[ORM\Column(type: Types::STRING, length: 255)]
|
||||
private string $question;
|
||||
public string $question;
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'questions')]
|
||||
private Quiz $quiz;
|
||||
public Quiz $quiz;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $enabled = true;
|
||||
public bool $enabled = true;
|
||||
|
||||
/** @var Collection<int, Answer> */
|
||||
#[ORM\OneToMany(targetEntity: Answer::class, mappedBy: 'question', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['ordering' => 'ASC'])]
|
||||
private Collection $answers;
|
||||
public private(set) Collection $answers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->answers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getQuestion(): string
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
public function setQuestion(string $question): static
|
||||
{
|
||||
$this->question = $question;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuiz(): Quiz
|
||||
{
|
||||
return $this->quiz;
|
||||
}
|
||||
|
||||
public function setQuiz(Quiz $quiz): static
|
||||
{
|
||||
$this->quiz = $quiz;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isEnabled(): ?bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
public function setEnabled(bool $enabled): static
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Answer> */
|
||||
public function getAnswers(): Collection
|
||||
{
|
||||
return $this->answers;
|
||||
}
|
||||
|
||||
public function addAnswer(Answer $answer): static
|
||||
{
|
||||
if (!$this->answers->contains($answer)) {
|
||||
$this->answers->add($answer);
|
||||
$answer->setQuestion($this);
|
||||
$answer->question = $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -108,7 +60,7 @@ class Question
|
||||
return 'This question has no answers';
|
||||
}
|
||||
|
||||
$correctAnswers = $this->answers->filter(static fn (Answer $answer): bool => $answer->isRightAnswer())->count();
|
||||
$correctAnswers = $this->answers->filter(static fn (Answer $answer): bool => $answer->isRightAnswer)->count();
|
||||
|
||||
if (0 === $correctAnswers) {
|
||||
return 'This question has no correct answers';
|
||||
@@ -120,16 +72,4 @@ class Question
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOrdering(): int
|
||||
{
|
||||
return $this->ordering;
|
||||
}
|
||||
|
||||
public function setOrdering(int $ordering): static
|
||||
{
|
||||
$this->ordering = $ordering;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\QuizRepository;
|
||||
@@ -17,34 +16,34 @@ use Tvdt\Repository\QuizRepository;
|
||||
class Quiz
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(length: 64)]
|
||||
private string $name;
|
||||
public string $name;
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'quizzes')]
|
||||
private Season $season;
|
||||
public Season $season;
|
||||
|
||||
/** @var Collection<int, Question> */
|
||||
#[ORM\OneToMany(targetEntity: Question::class, mappedBy: 'quiz', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['ordering' => 'ASC'])]
|
||||
private Collection $questions;
|
||||
public private(set) Collection $questions;
|
||||
|
||||
/** @var Collection<int, QuizCandidate> */
|
||||
#[ORM\OneToMany(targetEntity: QuizCandidate::class, mappedBy: 'quiz', orphanRemoval: true)]
|
||||
private Collection $candidateData;
|
||||
public private(set) Collection $candidateData;
|
||||
|
||||
#[ORM\Column(nullable: false, options: ['default' => 1])]
|
||||
private int $dropouts = 1;
|
||||
public int $dropouts = 1;
|
||||
|
||||
/** @var Collection<int, Elimination> */
|
||||
#[ORM\OneToMany(targetEntity: Elimination::class, mappedBy: 'quiz', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['created' => 'DESC'])]
|
||||
private Collection $eliminations;
|
||||
public private(set) Collection $eliminations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -53,75 +52,16 @@ class Quiz
|
||||
$this->eliminations = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSeason(): Season
|
||||
{
|
||||
return $this->season;
|
||||
}
|
||||
|
||||
public function setSeason(Season $season): static
|
||||
{
|
||||
$this->season = $season;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Question> */
|
||||
public function getQuestions(): Collection
|
||||
{
|
||||
return $this->questions;
|
||||
}
|
||||
|
||||
public function addQuestion(Question $question): static
|
||||
{
|
||||
if (!$this->questions->contains($question)) {
|
||||
$this->questions->add($question);
|
||||
$question->setQuiz($this);
|
||||
$question->quiz = $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, QuizCandidate> */
|
||||
public function getCandidateData(): Collection
|
||||
{
|
||||
return $this->candidateData;
|
||||
}
|
||||
|
||||
public function getDropouts(): int
|
||||
{
|
||||
return $this->dropouts;
|
||||
}
|
||||
|
||||
public function setDropouts(int $dropouts): static
|
||||
{
|
||||
$this->dropouts = $dropouts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Elimination> */
|
||||
public function getEliminations(): Collection
|
||||
{
|
||||
return $this->eliminations;
|
||||
}
|
||||
|
||||
public function addElimination(Elimination $elimination): self
|
||||
{
|
||||
$this->eliminations->add($elimination);
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\QuizCandidateRepository;
|
||||
@@ -18,59 +17,27 @@ use Tvdt\Repository\QuizCandidateRepository;
|
||||
class QuizCandidate
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column]
|
||||
private float $corrections = 0;
|
||||
public float $corrections = 0;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
|
||||
private \DateTimeImmutable $created;
|
||||
public private(set) \DateTimeImmutable $created;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'candidateData')]
|
||||
private Quiz $quiz,
|
||||
public Quiz $quiz,
|
||||
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'quizData')]
|
||||
private Candidate $candidate,
|
||||
public Candidate $candidate,
|
||||
) {}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCandidate(): Candidate
|
||||
{
|
||||
return $this->candidate;
|
||||
}
|
||||
|
||||
public function getQuiz(): Quiz
|
||||
{
|
||||
return $this->quiz;
|
||||
}
|
||||
|
||||
public function getCorrections(): ?float
|
||||
{
|
||||
return $this->corrections;
|
||||
}
|
||||
|
||||
public function setCorrections(float $corrections): static
|
||||
{
|
||||
$this->corrections = $corrections;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreated(): \DateTimeImmutable
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
#[ORM\PrePersist]
|
||||
public function setCreatedAtValue(): void
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Tvdt\Entity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\SeasonRepository;
|
||||
@@ -18,37 +17,37 @@ class Season
|
||||
private const string SEASON_CODE_CHARACTERS = 'bcdfghjklmnpqrstvwxz';
|
||||
|
||||
#[ORM\Column(type: UuidType::NAME)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(length: 64)]
|
||||
private string $name;
|
||||
public string $name;
|
||||
|
||||
#[ORM\Column(length: 5)]
|
||||
private string $seasonCode;
|
||||
public string $seasonCode;
|
||||
|
||||
/** @var Collection<int, Quiz> */
|
||||
#[ORM\OneToMany(targetEntity: Quiz::class, mappedBy: 'season', cascade: ['persist'], orphanRemoval: true)]
|
||||
private Collection $quizzes;
|
||||
public private(set) Collection $quizzes;
|
||||
|
||||
/** @var Collection<int, Candidate> */
|
||||
#[ORM\OneToMany(targetEntity: Candidate::class, mappedBy: 'season', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
private Collection $candidates;
|
||||
public private(set) Collection $candidates;
|
||||
|
||||
/** @var Collection<int, User> */
|
||||
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'seasons')]
|
||||
private Collection $owners;
|
||||
public private(set) Collection $owners;
|
||||
|
||||
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
|
||||
#[ORM\ManyToOne]
|
||||
private ?Quiz $ActiveQuiz = null;
|
||||
public ?Quiz $activeQuiz = null;
|
||||
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
|
||||
private ?SeasonSettings $settings = null;
|
||||
public ?SeasonSettings $settings = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -58,73 +57,26 @@ class Season
|
||||
$this->owners = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSeasonCode(): ?string
|
||||
{
|
||||
return $this->seasonCode;
|
||||
}
|
||||
|
||||
public function setSeasonCode(string $seasonCode): static
|
||||
{
|
||||
$this->seasonCode = $seasonCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Quiz> */
|
||||
public function getQuizzes(): Collection
|
||||
{
|
||||
return $this->quizzes;
|
||||
}
|
||||
|
||||
public function addQuiz(Quiz $quiz): static
|
||||
{
|
||||
if (!$this->quizzes->contains($quiz)) {
|
||||
$this->quizzes->add($quiz);
|
||||
$quiz->setSeason($this);
|
||||
$quiz->season = $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Candidate> */
|
||||
public function getCandidates(): Collection
|
||||
{
|
||||
return $this->candidates;
|
||||
}
|
||||
|
||||
public function addCandidate(Candidate $candidate): static
|
||||
{
|
||||
if (!$this->candidates->contains($candidate)) {
|
||||
$this->candidates->add($candidate);
|
||||
$candidate->setSeason($this);
|
||||
$candidate->season = $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, User> */
|
||||
public function getOwners(): Collection
|
||||
{
|
||||
return $this->owners;
|
||||
}
|
||||
|
||||
public function addOwner(User $owner): static
|
||||
{
|
||||
if (!$this->owners->contains($owner)) {
|
||||
@@ -141,18 +93,6 @@ class Season
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActiveQuiz(): ?Quiz
|
||||
{
|
||||
return $this->ActiveQuiz;
|
||||
}
|
||||
|
||||
public function setActiveQuiz(?Quiz $ActiveQuiz): static
|
||||
{
|
||||
$this->ActiveQuiz = $ActiveQuiz;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isOwner(User $user): bool
|
||||
{
|
||||
return $this->owners->contains($user);
|
||||
@@ -171,16 +111,4 @@ class Season
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSettings(): ?SeasonSettings
|
||||
{
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
public function setSettings(SeasonSettings $settings): static
|
||||
{
|
||||
$this->settings = $settings;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Tvdt\Entity;
|
||||
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Tvdt\Repository\SeasonSettingsRepository;
|
||||
@@ -15,43 +14,14 @@ use Tvdt\Repository\SeasonSettingsRepository;
|
||||
class SeasonSettings
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
|
||||
private bool $showNumbers = false;
|
||||
public bool $showNumbers = false;
|
||||
|
||||
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
|
||||
private bool $confirmAnswers = false;
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function isShowNumbers(): bool
|
||||
{
|
||||
return $this->showNumbers;
|
||||
}
|
||||
|
||||
public function setShowNumbers(bool $showNumbers): self
|
||||
{
|
||||
$this->showNumbers = $showNumbers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isConfirmAnswers(): bool
|
||||
{
|
||||
return $this->confirmAnswers;
|
||||
}
|
||||
|
||||
public function setConfirmAnswers(bool $confirmAnswers): self
|
||||
{
|
||||
$this->confirmAnswers = $confirmAnswers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
public bool $confirmAnswers = false;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UuidType;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
@@ -23,51 +22,38 @@ use Tvdt\Repository\UserRepository;
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
#[ORM\Column(type: UuidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Id]
|
||||
private Uuid $id;
|
||||
public private(set) Uuid $id;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
private string $email;
|
||||
public string $email;
|
||||
|
||||
/** @var list<string> The user roles */
|
||||
#[ORM\Column(type: Types::JSON)]
|
||||
private array $roles = [];
|
||||
public array $roles = [];
|
||||
|
||||
/** @var string The hashed password */
|
||||
#[ORM\Column]
|
||||
private string $password;
|
||||
public string $password;
|
||||
|
||||
/** @var Collection<int, Season> */
|
||||
#[ORM\ManyToMany(targetEntity: Season::class, mappedBy: 'owners')]
|
||||
private Collection $seasons;
|
||||
public private(set) Collection $seasons;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $isVerified = false;
|
||||
public bool $isVerified = false;
|
||||
|
||||
public bool $isAdmin {
|
||||
get => \in_array('ROLE_ADMIN', $this->getRoles(), true);
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->seasons = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): static
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual identifier that represents this user.
|
||||
*
|
||||
@@ -97,27 +83,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
return array_unique($roles);
|
||||
}
|
||||
|
||||
/** @param list<string> $roles */
|
||||
public function setRoles(array $roles): static
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @see PasswordAuthenticatedUserInterface */
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword(string $password): static
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @see UserInterface */
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
@@ -125,12 +96,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
// $this->plainPassword = null;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Season> */
|
||||
public function getSeasons(): Collection
|
||||
{
|
||||
return $this->seasons;
|
||||
}
|
||||
|
||||
public function addSeason(Season $season): static
|
||||
{
|
||||
if (!$this->seasons->contains($season)) {
|
||||
@@ -149,21 +114,4 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isVerified(): bool
|
||||
{
|
||||
return $this->isVerified;
|
||||
}
|
||||
|
||||
public function setIsVerified(bool $isVerified): static
|
||||
{
|
||||
$this->isVerified = $isVerified;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return \in_array('ROLE_ADMIN', $this->getRoles(), true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user