*/ #[ORM\OneToMany(targetEntity: Quiz::class, mappedBy: 'season', cascade: ['persist'], orphanRemoval: true)] public private(set) Collection $quizzes; /** @var Collection */ #[ORM\OneToMany(targetEntity: Candidate::class, mappedBy: 'season', cascade: ['persist'], orphanRemoval: true)] #[ORM\OrderBy(['name' => 'ASC'])] public private(set) Collection $candidates; /** @var Collection */ #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'seasons')] public private(set) Collection $owners; #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] #[ORM\ManyToOne] public ?Quiz $activeQuiz = null; #[ORM\JoinColumn(nullable: true)] #[ORM\OneToOne(cascade: ['persist', 'remove'])] public ?SeasonSettings $settings = null; public function __construct() { $this->settings = new SeasonSettings(); $this->quizzes = new ArrayCollection(); $this->candidates = new ArrayCollection(); $this->owners = new ArrayCollection(); } public function addQuiz(Quiz $quiz): static { if (!$this->quizzes->contains($quiz)) { $this->quizzes->add($quiz); $quiz->season = $this; } return $this; } public function addCandidate(Candidate $candidate): static { if (!$this->candidates->contains($candidate)) { $this->candidates->add($candidate); $candidate->season = $this; } return $this; } public function addOwner(User $owner): static { if (!$this->owners->contains($owner)) { $this->owners->add($owner); } return $this; } public function removeOwner(User $owner): static { $this->owners->removeElement($owner); return $this; } public function isOwner(User $user): bool { return $this->owners->contains($user); } public function generateSeasonCode(): void { $code = ''; $len = mb_strlen(self::SEASON_CODE_CHARACTERS) - 1; for ($i = 0; $i < 5; ++$i) { $code .= self::SEASON_CODE_CHARACTERS[random_int(0, $len)]; } $this->seasonCode = $code; } }