<?phpnamespace App\Entity;use App\Repository\AppointmentDateRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: AppointmentDateRepository::class)]class AppointmentDate{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $date = null; #[ORM\Column(type: Types::TIME_MUTABLE)] private ?\DateTimeInterface $startTime = null; #[ORM\Column(type: Types::TIME_MUTABLE)] private ?\DateTimeInterface $endTime = null; #[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $closeStartTime = null; #[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $closeEndTime = null; #[ORM\OneToMany(mappedBy: 'date', targetEntity: TimeSlot::class, orphanRemoval: true)] private Collection $timeSlots; public function __construct() { $this->timeSlots = new ArrayCollection(); } public function __clone(): void { if($this->getId()) { $this->id = null; $this->date = null; } } public function getId(): ?int { return $this->id; } public function getDate(): ?\DateTimeInterface { return $this->date; } public function setDate(\DateTimeInterface $date): static { $this->date = $date; return $this; } public function getStartTime(): ?\DateTimeInterface { return $this->startTime; } public function setStartTime(\DateTimeInterface $startTime): static { $this->startTime = $startTime; return $this; } public function getEndTime(): ?\DateTimeInterface { return $this->endTime; } public function setEndTime(\DateTimeInterface $endTime): static { $this->endTime = $endTime; return $this; } public function getCloseStartTime(): ?\DateTimeInterface { return $this->closeStartTime; } public function setCloseStartTime(?\DateTimeInterface $closeStartTime): static { $this->closeStartTime = $closeStartTime; return $this; } public function getCloseEndTime(): ?\DateTimeInterface { return $this->closeEndTime; } public function setCloseEndTime(?\DateTimeInterface $closeEndTime): static { $this->closeEndTime = $closeEndTime; return $this; } /** * @return Collection<int, TimeSlot> */ public function getTimeSlots(): Collection { return $this->timeSlots; } public function addTimeSlot(TimeSlot $timeSlot): static { if (!$this->timeSlots->contains($timeSlot)) { $this->timeSlots->add($timeSlot); $timeSlot->setDate($this); } return $this; } public function removeTimeSlot(TimeSlot $timeSlot): static { if ($this->timeSlots->removeElement($timeSlot)) { // set the owning side to null (unless already changed) if ($timeSlot->getDate() === $this) { $timeSlot->setDate(null); } } return $this; } public function isFull(): bool { $slots = $this->timeSlots; /** @var TimeSlot $slot */ foreach ($slots as $slot) { if(!$slot->getAppointment()) { return false; } } return true; } public function getFreeSlots(): int { $total = 0; $slots = $this->timeSlots; /** @var TimeSlot $slot */ foreach ($slots as $slot) { if($slot->getAppointment()) { $total++; } } return $this->timeSlots->count() - $total; } public function appointmentsCount(): int { $total = 0; foreach ($this->getTimeSlots() as $timeSlot) { $appointment = $timeSlot->getAppointment(); if($appointment && (!$appointment->getLinkedTo() || ($appointment->getLinkedTo() && $appointment->isIsMain()))) { $total++; } }; return $total; }}