<?php
namespace App\Entity;
use App\Repository\SeasonRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SeasonRepository::class)]
class Season
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private $name;
#[ORM\Column(type: 'date_immutable')]
private $startAt;
#[ORM\Column(type: 'date_immutable')]
private $endAt;
#[ORM\Column(type: 'boolean')]
private $isActive;
#[ORM\ManyToOne(targetEntity: GlobalSeason::class, inversedBy: 'seasons')]
#[ORM\JoinColumn(nullable: false)]
private $globalSeason;
#[ORM\OneToOne(inversedBy: 'nextSeason', targetEntity: self::class, cascade: ['persist'])]
private $previousSeason;
#[ORM\OneToOne(mappedBy: 'previousSeason', targetEntity: self::class, cascade: ['persist'])]
private $nextSeason;
#[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'seasons')]
#[ORM\JoinColumn(nullable: false)]
private $section;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Coach::class)]
private $coaches;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Lesson::class)]
private $lessons;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: DocumentModel::class)]
private $documentModels;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Registration::class)]
private $registrations;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Profiling::class)]
private $profilings;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: ProfilingPerson::class)]
private $profilingPersons;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Envelope::class)]
private $envelopes;
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Slot::class)]
private $slots;
#[ORM\Column(type: 'boolean')]
private $migrated = false;
public function __construct()
{
$this->coaches = new ArrayCollection();
$this->lessons = new ArrayCollection();
$this->documentModels = new ArrayCollection();
$this->registrations = new ArrayCollection();
$this->profilings = new ArrayCollection();
$this->profilingPersons = new ArrayCollection();
$this->envelopes = new ArrayCollection();
$this->slots = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
public function getName(): ?string
{
if ($this->name) {
return $this->name;
}
if ($this->getStartAt() && $this->getEndAt()) {
return sprintf('%s-%s', $this->getStartAt()->format('Y'), $this->getEndAt()->format('Y'));
}
return null;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getStartAt(): ?\DateTimeImmutable
{
return $this->startAt;
}
public function setStartAt(\DateTimeImmutable $startAt): self
{
$this->startAt = $startAt;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->endAt;
}
public function setEndAt(\DateTimeImmutable $endAt): self
{
$this->endAt = $endAt;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getGlobalSeason(): ?GlobalSeason
{
return $this->globalSeason;
}
public function setGlobalSeason(?GlobalSeason $globalSeason): self
{
$this->globalSeason = $globalSeason;
return $this;
}
public function getPreviousSeason(): ?self
{
return $this->previousSeason;
}
public function setPreviousSeason(?self $previousSeason): self
{
$this->previousSeason = $previousSeason;
return $this;
}
public function getNextSeason(): ?self
{
return $this->nextSeason;
}
public function setNextSeason(?self $nextSeason): self
{
// unset the owning side of the relation if necessary
if ($nextSeason === null && $this->nextSeason !== null) {
$this->nextSeason->setPreviousSeason(null);
}
// set the owning side of the relation if necessary
if ($nextSeason !== null && $nextSeason->getPreviousSeason() !== $this) {
$nextSeason->setPreviousSeason($this);
}
$this->nextSeason = $nextSeason;
return $this;
}
/**
* @return Collection<int, Coach>
*/
public function getCoaches(): Collection
{
return $this->coaches;
}
public function addCoach(Coach $coach): self
{
if (!$this->coaches->contains($coach)) {
$this->coaches[] = $coach;
$coach->setSeason($this);
}
return $this;
}
public function removeCoach(Coach $coach): self
{
if ($this->coaches->removeElement($coach)) {
// set the owning side to null (unless already changed)
if ($coach->getSeason() === $this) {
$coach->setSeason(null);
}
}
return $this;
}
/**
* @return Collection<int, Lesson>
*/
public function getLessons(): Collection
{
return $this->lessons;
}
public function addLesson(Lesson $lesson): self
{
if (!$this->lessons->contains($lesson)) {
$this->lessons[] = $lesson;
$lesson->setSeason($this);
}
return $this;
}
public function removeLesson(Lesson $lesson): self
{
if ($this->lessons->removeElement($lesson)) {
// set the owning side to null (unless already changed)
if ($lesson->getSeason() === $this) {
$lesson->setSeason(null);
}
}
return $this;
}
/**
* @param bool|null $includeDiscounts
* @return Collection<int, DocumentModel>
*/
public function getDocumentModels(?bool $includeDiscounts = true): Collection
{
if (false === $includeDiscounts) {
return $this->documentModels->filter(fn(DocumentModel $d) => $d->getDiscountModel() === null);
}
return $this->documentModels;
}
public function addDocumentModel(DocumentModel $documentModel): self
{
if (!$this->documentModels->contains($documentModel)) {
$this->documentModels[] = $documentModel;
$documentModel->setSeason($this);
}
return $this;
}
public function removeDocumentModel(DocumentModel $documentModel): self
{
if ($this->documentModels->removeElement($documentModel)) {
// set the owning side to null (unless already changed)
if ($documentModel->getSeason() === $this) {
$documentModel->setSeason(null);
}
}
return $this;
}
public function __toString(): string
{
return sprintf(
'%s %s - %s (%s)',
$this->getSection()?->getName(),
$this->getStartAt()?->format('d/m/Y'),
$this->getEndAt()?->format('d/m/Y'),
$this->name ?? 'N/A',
);
}
/**
* @return Collection<int, Registration>
*/
public function getRegistrations(): Collection
{
return $this->registrations;
}
public function addRegistration(Registration $registration): self
{
if (!$this->registrations->contains($registration)) {
$this->registrations[] = $registration;
$registration->setSeason($this);
}
return $this;
}
public function removeRegistration(Registration $registration): self
{
if ($this->registrations->removeElement($registration)) {
// set the owning side to null (unless already changed)
if ($registration->getSeason() === $this) {
$registration->setSeason(null);
}
}
return $this;
}
/**
* @return Collection<int, Profiling>
*/
public function getProfilings(): Collection
{
return $this->profilings;
}
public function addProfiling(Profiling $profiling): self
{
if (!$this->profilings->contains($profiling)) {
$this->profilings[] = $profiling;
$profiling->setSeason($this);
}
return $this;
}
public function removeProfiling(Profiling $profiling): self
{
if ($this->profilings->removeElement($profiling)) {
// set the owning side to null (unless already changed)
if ($profiling->getSeason() === $this) {
$profiling->setSeason(null);
}
}
return $this;
}
/**
* @return Collection<int, ProfilingPerson>
*/
public function getProfilingPersons(): Collection
{
return $this->profilingPersons;
}
public function addProfilingPerson(ProfilingPerson $profilingPerson): self
{
if (!$this->profilingPersons->contains($profilingPerson)) {
$this->profilingPersons[] = $profilingPerson;
$profilingPerson->setSeason($this);
}
return $this;
}
public function removeProfilingPerson(ProfilingPerson $profilingPerson): self
{
if ($this->profilingPersons->removeElement($profilingPerson)) {
// set the owning side to null (unless already changed)
if ($profilingPerson->getSeason() === $this) {
$profilingPerson->setSeason(null);
}
}
return $this;
}
/**
* @return Collection<int, Envelope>
*/
public function getEnvelopes(): Collection
{
return $this->envelopes;
}
public function addEnvelope(Envelope $envelope): self
{
if (!$this->envelopes->contains($envelope)) {
$this->envelopes[] = $envelope;
$envelope->setSeason($this);
}
return $this;
}
public function removeEnvelope(Envelope $envelope): self
{
if ($this->envelopes->removeElement($envelope)) {
// set the owning side to null (unless already changed)
if ($envelope->getSeason() === $this) {
$envelope->setSeason(null);
}
}
return $this;
}
/**
* @return Collection<int, Slot>
*/
public function getSlots(): Collection
{
return $this->slots;
}
public function addSlot(Slot $slot): self
{
if (!$this->slots->contains($slot)) {
$this->slots[] = $slot;
$slot->setSeason($this);
}
return $this;
}
public function removeSlot(Slot $slot): self
{
if ($this->slots->removeElement($slot)) {
// set the owning side to null (unless already changed)
if ($slot->getSeason() === $this) {
$slot->setSeason(null);
}
}
return $this;
}
public function isMigrated(): ?bool
{
return $this->migrated;
}
public function setMigrated(bool $migrated): self
{
$this->migrated = $migrated;
return $this;
}
}