src/Entity/AppointmentDate.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AppointmentDateRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassAppointmentDateRepository::class)]
  9. class AppointmentDate
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  16.     private ?\DateTimeInterface $date null;
  17.     #[ORM\Column(typeTypes::TIME_MUTABLE)]
  18.     private ?\DateTimeInterface $startTime null;
  19.     #[ORM\Column(typeTypes::TIME_MUTABLE)]
  20.     private ?\DateTimeInterface $endTime null;
  21.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  22.     private ?\DateTimeInterface $closeStartTime null;
  23.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  24.     private ?\DateTimeInterface $closeEndTime null;
  25.     #[ORM\OneToMany(mappedBy'date'targetEntityTimeSlot::class, orphanRemovaltrue)]
  26.     private Collection $timeSlots;
  27.     public function __construct()
  28.     {
  29.         $this->timeSlots = new ArrayCollection();
  30.     }
  31.     public function __clone(): void
  32.     {
  33.         if($this->getId()) {
  34.             $this->id null;
  35.             $this->date null;
  36.         }
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getDate(): ?\DateTimeInterface
  43.     {
  44.         return $this->date;
  45.     }
  46.     public function setDate(\DateTimeInterface $date): static
  47.     {
  48.         $this->date $date;
  49.         return $this;
  50.     }
  51.     public function getStartTime(): ?\DateTimeInterface
  52.     {
  53.         return $this->startTime;
  54.     }
  55.     public function setStartTime(\DateTimeInterface $startTime): static
  56.     {
  57.         $this->startTime $startTime;
  58.         return $this;
  59.     }
  60.     public function getEndTime(): ?\DateTimeInterface
  61.     {
  62.         return $this->endTime;
  63.     }
  64.     public function setEndTime(\DateTimeInterface $endTime): static
  65.     {
  66.         $this->endTime $endTime;
  67.         return $this;
  68.     }
  69.     public function getCloseStartTime(): ?\DateTimeInterface
  70.     {
  71.         return $this->closeStartTime;
  72.     }
  73.     public function setCloseStartTime(?\DateTimeInterface $closeStartTime): static
  74.     {
  75.         $this->closeStartTime $closeStartTime;
  76.         return $this;
  77.     }
  78.     public function getCloseEndTime(): ?\DateTimeInterface
  79.     {
  80.         return $this->closeEndTime;
  81.     }
  82.     public function setCloseEndTime(?\DateTimeInterface $closeEndTime): static
  83.     {
  84.         $this->closeEndTime $closeEndTime;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return Collection<int, TimeSlot>
  89.      */
  90.     public function getTimeSlots(): Collection
  91.     {
  92.         return $this->timeSlots;
  93.     }
  94.     public function addTimeSlot(TimeSlot $timeSlot): static
  95.     {
  96.         if (!$this->timeSlots->contains($timeSlot)) {
  97.             $this->timeSlots->add($timeSlot);
  98.             $timeSlot->setDate($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeTimeSlot(TimeSlot $timeSlot): static
  103.     {
  104.         if ($this->timeSlots->removeElement($timeSlot)) {
  105.             // set the owning side to null (unless already changed)
  106.             if ($timeSlot->getDate() === $this) {
  107.                 $timeSlot->setDate(null);
  108.             }
  109.         }
  110.         return $this;
  111.     }
  112.     public function isFull(): bool
  113.     {
  114.         $slots $this->timeSlots;
  115.         /** @var TimeSlot $slot */
  116.         foreach ($slots as  $slot) {
  117.             if(!$slot->getAppointment()) {
  118.                 return false;
  119.             }
  120.         }
  121.         return true;
  122.     }
  123.     public function getFreeSlots(): int
  124.     {
  125.         $total 0;
  126.         $slots $this->timeSlots;
  127.         /** @var TimeSlot $slot */
  128.         foreach ($slots as  $slot) {
  129.             if($slot->getAppointment()) {
  130.                 $total++;
  131.             }
  132.         }
  133.         return $this->timeSlots->count() - $total;
  134.     }
  135.     public function appointmentsCount(): int
  136.     {
  137.         $total 0;
  138.         foreach ($this->getTimeSlots() as $timeSlot) {
  139.             $appointment $timeSlot->getAppointment();
  140.             if($appointment && (!$appointment->getLinkedTo() || ($appointment->getLinkedTo() && $appointment->isIsMain()))) {
  141.                 $total++;
  142.             }
  143.         };
  144.         return $total;
  145.     }
  146. }