src/Entity/Slot.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SlotRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassSlotRepository::class)]
  8. class Slot
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\Column(type'smallint'nullabletrue)]
  15.     private $capacity;
  16.     #[ORM\Column(type'time_immutable')]
  17.     private $startAt;
  18.     #[ORM\Column(type'time_immutable')]
  19.     private $endAt;
  20.     #[ORM\Column(type'string'length20)]
  21.     private $weekDay;
  22.     #[ORM\Column(type'string'length50nullabletrue)]
  23.     private $zone;
  24.     #[ORM\Column(type'smallint')]
  25.     private $cost;
  26.     #[ORM\ManyToMany(targetEntityCoach::class, inversedBy'slots')]
  27.     private $coachs;
  28.     #[ORM\ManyToMany(targetEntityLesson::class, inversedBy'slots')]
  29.     private $lessons;
  30.     #[ORM\ManyToMany(targetEntityRegistration::class, mappedBy'slots')]
  31.     private $registrations;
  32.     #[ORM\ManyToOne(targetEntityLocation::class, inversedBy'slots')]
  33.     #[ORM\JoinColumn(nullablefalse)]
  34.     private $location;
  35.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'slots')]
  36.     #[ORM\JoinColumn(nullablefalse)]
  37.     private $season;
  38.     #[ORM\ManyToMany(targetEntityRegistration::class, mappedBy'proposedSlots')]
  39.     private $registrationPropositions;
  40.     public function __construct()
  41.     {
  42.         $this->coachs = new ArrayCollection();
  43.         $this->lessons = new ArrayCollection();
  44.         $this->registrations = new ArrayCollection();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getCapacity(): ?int
  51.     {
  52.         return $this->capacity;
  53.     }
  54.     public function setCapacity(?int $capacity): self
  55.     {
  56.         $this->capacity $capacity;
  57.         return $this;
  58.     }
  59.     public function remainingCapacity(): int
  60.     {
  61.         return $this->getCapacity() - $this->getRegistrations()->count();
  62.     }
  63.     public function getStartAt(): ?\DateTimeImmutable
  64.     {
  65.         return $this->startAt;
  66.     }
  67.     public function setStartAt(\DateTimeImmutable $startAt): self
  68.     {
  69.         $this->startAt $startAt;
  70.         return $this;
  71.     }
  72.     public function getEndAt(): ?\DateTimeImmutable
  73.     {
  74.         return $this->endAt;
  75.     }
  76.     public function setEndAt(\DateTimeImmutable $endAt): self
  77.     {
  78.         $this->endAt $endAt;
  79.         return $this;
  80.     }
  81.     public function getWeekDay(): ?string
  82.     {
  83.         return $this->weekDay;
  84.     }
  85.     public function setWeekDay(string $weekDay): self
  86.     {
  87.         $this->weekDay $weekDay;
  88.         return $this;
  89.     }
  90.     public function getZone(): ?string
  91.     {
  92.         return $this->zone;
  93.     }
  94.     public function setZone(?string $zone): self
  95.     {
  96.         $this->zone $zone;
  97.         return $this;
  98.     }
  99.     public function getCost(): ?int
  100.     {
  101.         return $this->cost;
  102.     }
  103.     public function setCost(int $cost): self
  104.     {
  105.         $this->cost $cost;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection<int, Coach>
  110.      */
  111.     public function getCoachs(): Collection
  112.     {
  113.         return $this->coachs;
  114.     }
  115.     public function addCoach(Coach $coach): self
  116.     {
  117.         if (!$this->coachs->contains($coach)) {
  118.             $this->coachs[] = $coach;
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeCoach(Coach $coach): self
  123.     {
  124.         $this->coachs->removeElement($coach);
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return Collection<int, Lesson>
  129.      */
  130.     public function getLessons(): Collection
  131.     {
  132.         return $this->lessons;
  133.     }
  134.     public function addLesson(Lesson $lesson): self
  135.     {
  136.         if (!$this->lessons->contains($lesson)) {
  137.             $this->lessons[] = $lesson;
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeLesson(Lesson $lesson): self
  142.     {
  143.         $this->lessons->removeElement($lesson);
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, Registration>
  148.      */
  149.     public function getRegistrations(?bool $proposed false): Collection
  150.     {
  151.         $registrations $this->registrations;
  152.         if ($proposed) {
  153.             foreach ($this->getRegistrationPropositions() as $registrationProposition) {
  154.                 $this->registrations->add($registrationProposition);
  155.             }
  156.         }
  157.         return $registrations;
  158.     }
  159.     public function addRegistration(Registration $registration): self
  160.     {
  161.         if (!$this->registrations->contains($registration)) {
  162.             $this->registrations[] = $registration;
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeRegistration(Registration $registration): self
  167.     {
  168.         $this->registrations->removeElement($registration);
  169.         return $this;
  170.     }
  171.     public function getLocation(): ?Location
  172.     {
  173.         return $this->location;
  174.     }
  175.     public function setLocation(?Location $location): self
  176.     {
  177.         $this->location $location;
  178.         return $this;
  179.     }
  180.     public function __toString(): string
  181.     {
  182.         return sprintf(
  183.             '%s %s %s %s',
  184.             $this->getZone(),
  185.             $this->getWeekDay(),
  186.             $this->getStartAt()?->format('H:i'),
  187.             $this->getEndAt()?->format('H:i'),
  188.         );
  189.     }
  190.     public function getSeason(): ?Season
  191.     {
  192.         return $this->season;
  193.     }
  194.     public function setSeason(?Season $Season): self
  195.     {
  196.         $this->season $Season;
  197.         return $this;
  198.     }
  199.     public function getName($showCapacity false): string
  200.     {
  201.         $str sprintf(
  202.             '%s / %s / %s-%s / %s',
  203.             $this->getLocation()->getName(),
  204.             $this->getWeekDay(),
  205.             $this->getStartAt()?->format('H:i'),
  206.             $this->getEndAt()?->format('H:i'),
  207.             $this->getZone(),
  208.         );
  209.         if ($showCapacity) {
  210.             $str sprintf(
  211.                 '%s [%s/%s]',
  212.                 $str,
  213.                 $this->getRegistrations()->count(),
  214.                 $this->getCapacity()
  215.             );
  216.         }
  217.         return $str;
  218.     }
  219.     /**
  220.      * @return Collection<int, Registration>
  221.      */
  222.     public function getRegistrationPropositions(): Collection
  223.     {
  224.         return $this->registrationPropositions;
  225.     }
  226.     public function __clone()
  227.     {
  228.         $this->id null;
  229.         $this->coachs = new ArrayCollection();
  230.         $this->lessons = new ArrayCollection();
  231.         $this->registrations = new ArrayCollection();
  232.         $this->season null;
  233.         $this->registrationPropositions = new ArrayCollection();
  234.     }
  235.     public function getSortableString(): string
  236.     {
  237.         $startAt $this->getStartAt()?->format('His') ?? '000000';
  238.         $weekday = match ($this->getWeekDay()) {
  239.             'Lundi' => '01',
  240.             'Mardi' => '02',
  241.             'Mercredi' => '03',
  242.             'Jeudi' => '04',
  243.             'Vendredi' => '05',
  244.             'Samedi' => '06',
  245.             'Dimanche' => '07',
  246.             default => '00'
  247.         };
  248.         return sprintf("%s%s"$weekday$startAt);
  249.     }
  250. }