<?php
namespace App\Entity;
use App\Repository\TimeSlotRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use \Boab\CmsBundle\Entity\User;
#[ORM\Entity(repositoryClass: TimeSlotRepository::class)]
class TimeSlot
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(inversedBy: 'timeSlots')]
private ?User $createdBy = null;
#[ORM\Column(length: 10)]
private ?string $day = null;
#[ORM\Column(type: Types::TIME_MUTABLE)]
private ?\DateTimeInterface $startTime = null;
#[ORM\Column(type: Types::TIME_MUTABLE)]
private ?\DateTimeInterface $endTime = null;
#[ORM\OneToMany(mappedBy: 'timeSlot', targetEntity: Appointment::class)]
private Collection $appointments;
public function __construct()
{
$this->appointments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
public function getDay(): ?string
{
return $this->day;
}
public function setDay(string $day): static
{
$this->day = $day;
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;
}
/**
* @return Collection<int, Appointment>
*/
public function getAppointments(): Collection
{
return $this->appointments;
}
public function addAppointment(Appointment $appointment): static
{
if (!$this->appointments->contains($appointment)) {
$this->appointments->add($appointment);
$appointment->setTimeSlot($this);
}
return $this;
}
public function removeAppointment(Appointment $appointment): static
{
if ($this->appointments->removeElement($appointment)) {
// set the owning side to null (unless already changed)
if ($appointment->getTimeSlot() === $this) {
$appointment->setTimeSlot(null);
}
}
return $this;
}
public function getDescription()
{
return sprintf('%s - %s', $this->getStartTime()->format('h.i A'), $this->getEndTime()->format('h.i A'));
}
}