src/Entity/Lesson.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Sortable;
  4. use App\Repository\LessonRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassLessonRepository::class)]
  9. class Lesson
  10. {
  11.     use Sortable;
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length100)]
  17.     private $name;
  18.     #[ORM\Column(type'string'length10)]
  19.     private $acronym;
  20.     #[ORM\Column(type'date_immutable'nullabletrue)]
  21.     private $yearMin;
  22.     #[ORM\Column(type'date_immutable'nullabletrue)]
  23.     private $yearMax;
  24.     #[ORM\Column(type'smallint'nullabletrue)]
  25.     private $price;
  26.     #[ORM\Column(type'smallint')]
  27.     private $minSlot 1;
  28.     #[ORM\Column(type'smallint')]
  29.     private $maxSlot 1;
  30.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'lessons')]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private $season;
  33.     #[ORM\ManyToMany(targetEntitySlot::class, mappedBy'lessons')]
  34.     private $slots;
  35.     #[ORM\OneToMany(targetEntityRegistration::class, mappedBy'lesson')]
  36.     private $registrations;
  37.     #[ORM\OneToMany(mappedBy'lesson'targetEntityCartItemLesson::class)]
  38.     private $cartItemLessons;
  39.     public function __construct()
  40.     {
  41.         $this->slots = new ArrayCollection();
  42.         $this->registrations = new ArrayCollection();
  43.         $this->cartItemLessons = new ArrayCollection();
  44.     }
  45.     public function __toString(): string
  46.     {
  47.         return $this->getName();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName($full false): ?string
  54.     {
  55.         if ($full) {
  56.             return sprintf('[%s] %s'$this->getAcronym(), $this->name);
  57.         }
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     public function getAcronym(): ?string
  66.     {
  67.         return $this->acronym;
  68.     }
  69.     public function setAcronym(string $acronym): self
  70.     {
  71.         $this->acronym $acronym;
  72.         return $this;
  73.     }
  74.     public function getYearMin(): ?\DateTimeImmutable
  75.     {
  76.         return $this->yearMin;
  77.     }
  78.     public function setYearMin(?\DateTimeImmutable $yearMin): self
  79.     {
  80.         $this->yearMin $yearMin;
  81.         return $this;
  82.     }
  83.     public function getYearMax(): ?\DateTimeImmutable
  84.     {
  85.         return $this->yearMax;
  86.     }
  87.     public function setYearMax(?\DateTimeImmutable $yearMax): self
  88.     {
  89.         $this->yearMax $yearMax;
  90.         return $this;
  91.     }
  92.     public function getPrice(): ?int
  93.     {
  94.         return $this->price ?? 0;
  95.     }
  96.     public function setPrice(?int $price): self
  97.     {
  98.         $this->price $price;
  99.         return $this;
  100.     }
  101.     public function getMinSlot(): ?int
  102.     {
  103.         return $this->minSlot;
  104.     }
  105.     public function setMinSlot(int $minSlot): self
  106.     {
  107.         $this->minSlot $minSlot;
  108.         return $this;
  109.     }
  110.     public function getMaxSlot(): ?int
  111.     {
  112.         return $this->maxSlot;
  113.     }
  114.     public function setMaxSlot(int $maxSlot): self
  115.     {
  116.         $this->maxSlot $maxSlot;
  117.         return $this;
  118.     }
  119.     public function getSeason(): ?Season
  120.     {
  121.         return $this->season;
  122.     }
  123.     public function setSeason(?Season $season): self
  124.     {
  125.         $this->season $season;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, Slot>
  130.      */
  131.     public function getSlots(): Collection
  132.     {
  133.         return $this->slots;
  134.     }
  135.     public function addSlot(Slot $slot): self
  136.     {
  137.         if (!$this->slots->contains($slot)) {
  138.             $this->slots[] = $slot;
  139.             $slot->addLesson($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeSlot(Slot $slot): self
  144.     {
  145.         if ($this->slots->removeElement($slot)) {
  146.             $slot->removeLesson($this);
  147.         }
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection<int, Registration>
  152.      */
  153.     public function getRegistrations(): Collection
  154.     {
  155.         return $this->registrations;
  156.     }
  157.     public function addRegistration(Registration $registration): self
  158.     {
  159.         if (!$this->registrations->contains($registration)) {
  160.             $this->registrations[] = $registration;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeRegistration(Registration $registration): self
  165.     {
  166.         $this->registrations->removeElement($registration);
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, CartItemLesson>
  171.      */
  172.     public function getCartItemLessons(): Collection
  173.     {
  174.         return $this->cartItemLessons;
  175.     }
  176.     public function addCartItemLesson(CartItemLesson $cartItemLesson): self
  177.     {
  178.         if (!$this->cartItemLessons->contains($cartItemLesson)) {
  179.             $this->cartItemLessons[] = $cartItemLesson;
  180.             $cartItemLesson->setLesson($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeCartItemLesson(CartItemLesson $cartItemLesson): self
  185.     {
  186.         if ($this->cartItemLessons->removeElement($cartItemLesson)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($cartItemLesson->getLesson() === $this) {
  189.                 $cartItemLesson->setLesson(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function __clone()
  195.     {
  196.         $this->id null;
  197.         $this->season null;
  198.         $this->slots = new ArrayCollection();
  199.         $this->registrations = new ArrayCollection();
  200.         $this->cartItemLessons = new ArrayCollection();
  201.         $yearMin \DateTime::createFromImmutable($this->yearMin);
  202.         $yearMax \DateTime::createFromImmutable($this->yearMax);
  203.         $yearMin->add(new \DateInterval('P1Y'));
  204.         $yearMax->add(new \DateInterval('P1Y'));
  205.         $this->yearMin \DateTimeImmutable::createFromMutable($yearMin);
  206.         $this->yearMax \DateTimeImmutable::createFromMutable($yearMax);
  207.     }
  208. }