<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ReflectionClass;
#[ORM\Entity]
#[ORM\Table(name: "calendar")]
#[ORM\InheritanceType("SINGLE_TABLE")]
#[ORM\DiscriminatorColumn(name: "calendarType", type: "string")]
#[ORM\DiscriminatorMap(["activity" => Activity::class, "staffSchedule" => StaffSchedule::class])]
abstract class Calendar
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
protected ?int $id = null;
#[ORM\Column(length: 255)]
protected ?string $title = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
public ?\DateTimeInterface $start = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
protected ?\DateTimeInterface $end = null;
/**
* @ORM\OneToMany(mappedBy="calendar", targetEntity="PurchaseItem", cascade={"remove"})
*/
private Collection $purchaseItems;
/*
#[ORM\OneToMany(mappedBy: 'calendar', targetEntity: PurchaseItem::class)]
private Collection $purchaseItems; */
#[ORM\ManyToMany(targetEntity: Staff::class, inversedBy: 'calendars', cascade: ['remove'])]
#[ORM\JoinColumn(nullable: true)]
private $staffs;
#[ORM\ManyToOne(inversedBy: 'calendars')]
#[ORM\JoinColumn(nullable: false)]
protected ?Category $category = null;
#[ORM\ManyToMany(targetEntity: Tide::class, inversedBy: 'calendars')]
protected Collection $tides;
#[ORM\Column]
private ?bool $visible = null;
#[ORM\Column(nullable: true)]
private ?bool $annulation = null;
public function __construct()
{
$this->staffs = new ArrayCollection();
$this->tides = new ArrayCollection();
$this->annulation = false;
}
// #[ORM\Column(nullable: true)]
// private ?int $price = null;
// #[ORM\Column(nullable: true)]
// private ?int $modifiedPrice = null;
/*#[Assert\NotBlank] */
/* #[ORM\Column(length: 255,nullable: true)]
private ?string $picture = null; */
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getStart(): ?\DateTimeInterface
{
return $this->start;
}
public function setStart(\DateTimeInterface $start): self
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTimeInterface
{
return $this->end;
}
public function setEnd(\DateTimeInterface $end): self
{
$this->end = $end;
return $this;
}
protected function getDefaultPrice(): ?int
{
// Récupérer le prix par défaut de la catégorie associée à l'activité
$category = $this->getCategory();
if ($category) {
$categorySetting = $category->getCategorySetting();
if ($categorySetting) {
return $categorySetting->getPrice();
}
}
return null;
}
public function getPrice(): ?int
{
if ($this->modifiedPrice !== null) {
return $this->modifiedPrice;
} else {
return $this->getDefaultPrice();
}
}
public function getModifiedPrice(): ?int
{
return $this->modifiedPrice;
}
public function setModifiedPrice(?int $modifiedPrice): self
{
$this->modifiedPrice = $modifiedPrice;
// Si modifiedPrice est défini, on l'utilise à la place de price
$this->price = $modifiedPrice !== null ? $modifiedPrice : $this->price;
return $this;
}
/**
* @return Collection<int, Staff>
*/
public function getStaffs(): Collection
{
return $this->staffs ?? new ArrayCollection(); // Utilisez un opérateur de coalescence null pour retourner une nouvelle collection si $staffs est null
}
public function addStaff(Staff $staff): static
{
$this->staffs = $this->staffs ?? new ArrayCollection(); // Initialiser $this->staffs si elle est null
if (!$this->staffs->contains($staff)) {
$this->staffs->add($staff);
$staff->addCalendar($this);
}
return $this;
}
public function removeStaff(Staff $staff): static
{
if ($this->staffs->removeElement($staff)) {
$staff->removeCalendar($this);
}
return $this;
}
public function getClassName(){
$class = new ReflectionClass($this);
return $class->getShortName();
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
/**
* @return Collection<int, Tide>
*/
public function getTides(): Collection
{
return $this->tides;
}
public function addTide(Tide $tide): static
{
if (!$this->tides->contains($tide)) {
$this->tides->add($tide);
}
return $this;
}
public function removeTide(Tide $tide): static
{
$this->tides->removeElement($tide);
return $this;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): static
{
$this->visible = $visible;
return $this;
}
public function isAnnulation(): ?bool
{
return $this->annulation;
}
public function setAnnulation(?bool $annulation): static
{
$this->annulation = $annulation;
return $this;
}
}