<?php
namespace App\Entity;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeDetails;
use App\MDS\GreenPatioBundle\Entity\ReservationService;
use App\Repository\HtItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=HtItemRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class HtItem
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity=ReservationService::class, inversedBy="htItem", cascade={"persist", "remove"})
*/
private $reservationService;
/**
* @ORM\ManyToOne(targetEntity=ReservationLoungeDetails::class, inversedBy="htItems")
*/
private $loungeGp;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $loungeOther;
/**
* @ORM\Column(type="datetime")
*/
private $dateStart;
/**
* @ORM\Column(type="time")
*/
private $hourEnd;
/**
* @ORM\Column(type="integer")
*/
private $gratitudes;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $createdId;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $updatedId;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=HtFile::class, inversedBy="htItems")
* @ORM\JoinColumn(nullable=false)
*/
private $htFile;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $pax;
/**
* @ORM\OneToMany(targetEntity=HtMenu::class, mappedBy="htItem", cascade={"persist", "remove"})
*/
private $htMenus;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $observation;
/**
* @ORM\OneToMany(targetEntity=HtExtra::class, mappedBy="htItem", cascade={"persist", "remove"})
*/
private $htExtras;
/**
* @ORM\Column(type="string", length=55, nullable=true)
*/
private $type;
/**
* @ORM\OneToMany(targetEntity=HtNote::class, mappedBy="htItem", orphanRemoval=true)
*/
private $htNotes;
public function __construct()
{
$this->htExtras = new ArrayCollection();
$this->htNotes = new ArrayCollection();
$this->htMenu = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getReservationService(): ?ReservationService
{
return $this->reservationService;
}
public function setReservationService(?ReservationService $reservationService): self
{
$this->reservationService = $reservationService;
return $this;
}
public function getLoungeGp(): ?ReservationLoungeDetails
{
return $this->loungeGp;
}
public function setLoungeGp(?ReservationLoungeDetails $loungeGp): self
{
$this->loungeGp = $loungeGp;
return $this;
}
public function getLoungeOther(): ?string
{
return $this->loungeOther;
}
public function setLoungeOther(?string $loungeOther): self
{
$this->loungeOther = $loungeOther;
return $this;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart(\DateTimeInterface $dateStart): self
{
$this->dateStart = $dateStart;
return $this;
}
public function getHourEnd(): ?\DateTimeInterface
{
return $this->hourEnd;
}
public function setHourEnd(\DateTimeInterface $hourEnd): self
{
$this->hourEnd = $hourEnd;
return $this;
}
public function getGratitudes(): ?int
{
return $this->gratitudes;
}
public function setGratitudes(int $gratitudes): self
{
$this->gratitudes = $gratitudes;
return $this;
}
public function getCreatedId(): ?User
{
return $this->createdId;
}
public function setCreatedId(?User $createdId): self
{
$this->createdId = $createdId;
return $this;
}
public function getUpdatedId(): ?User
{
return $this->updatedId;
}
public function setUpdatedId(?User $updatedId): self
{
$this->updatedId = $updatedId;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTimeImmutable();
if ($this->dateStart === null) { $this->dateStart = new \DateTime(); }
if ($this->hourEnd === null) { $this->hourEnd = new \DateTime(); }
$this->gratitudes = 0;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->updatedAt = new \DateTimeImmutable();
}
public function getHtFile(): ?HtFile
{
return $this->htFile;
}
public function setHtFile(?HtFile $htFile): self
{
$this->htFile = $htFile;
return $this;
}
public function getPax(): ?int
{
return $this->pax;
}
public function setPax(?int $pax): self
{
$this->pax = $pax;
return $this;
}
/**
* @return Collection|HtMenu[]
*/
public function getHtMenus(): Collection
{
return $this->htMenus;
}
public function addHtMenu(HtMenu $htMenu): self
{
if (!$this->htMenus->contains($htMenu)) {
$this->htMenus[] = $htMenu;
$htMenu->setHtItem($this);
}
return $this;
}
public function removeHtMenu(HtMenu $htMenu): self
{
if ($this->htMenus->removeElement($htMenu)) {
// set the owning side to null (unless already changed)
if ($htMenu->getHtItem() === $this) {
$htMenu->setHtItem(null);
}
}
return $this;
}
public function getObservation(): ?string
{
return $this->observation;
}
public function setObservation(?string $observation): self
{
$this->observation = $observation;
return $this;
}
/**
* @return Collection<int, HtExtra>
*/
public function getHtExtras(): Collection
{
return $this->htExtras;
}
public function addHtExtra(HtExtra $htExtra): self
{
if (!$this->htExtras->contains($htExtra)) {
$this->htExtras[] = $htExtra;
$htExtra->setHtItem($this);
}
return $this;
}
public function removeHtExtra(HtExtra $htExtra): self
{
if ($this->htExtras->removeElement($htExtra)) {
// set the owning side to null (unless already changed)
if ($htExtra->getHtItem() === $this) {
$htExtra->setHtItem(null);
}
}
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, HtNote>
*/
public function getHtNotes(): Collection
{
return $this->htNotes;
}
public function addHtNote(HtNote $htNote): self
{
if (!$this->htNotes->contains($htNote)) {
$this->htNotes[] = $htNote;
$htNote->setHtItem($this);
}
return $this;
}
public function removeHtNote(HtNote $htNote): self
{
if ($this->htNotes->removeElement($htNote)) {
// set the owning side to null (unless already changed)
if ($htNote->getHtItem() === $this) {
$htNote->setHtItem(null);
}
}
return $this;
}
/**
* Para la función clone de php nativa
*/
public function __clone()
{
// Resetear el ID
$this->id = null;
// Clonar y resetear relaciones si es necesario
if ($this->reservationService) {
$this->reservationService = clone $this->reservationService;
}
if ($this->htMenus) {
$clonedMenus = [];
foreach ($this->htMenus as $menu) {
$clonedMenu = clone $menu;
$clonedMenu->setHtItem($this);
$clonedMenus[] = $clonedMenu;
}
$this->htMenus = $clonedMenus;
}
// Clonar colecciones de HtExtras
$this->htExtras = new ArrayCollection();
foreach ($this->htExtras as $extra) {
$clonedExtra = clone $extra;
$clonedExtra->setHtItem($this);
$this->htExtras->add($clonedExtra);
}
// Clonar colecciones de HtNotes
$this->htNotes = new ArrayCollection();
foreach ($this->htNotes as $note) {
$clonedNote = clone $note;
$clonedNote->setHtItem($this);
$this->htNotes->add($clonedNote);
}
// No es necesario clonar las relaciones ManyToOne o OneToOne que no se deben duplicar en profundidad
// pero se debe reasignar la relación inversa en caso de que se dupliquen.
}
}