src/Entity/HtItem.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\MDS\VenuesBundle\Entity\ReservationLoungeDetails;
  4. use App\MDS\VenuesBundle\Entity\ReservationService;
  5. use App\Repository\HtItemRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=HtItemRepository::class)
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class HtItem
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\OneToOne(targetEntity=ReservationService::class, inversedBy="htItem", cascade={"persist", "remove"})
  25.      */
  26.     private $reservationService;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=ReservationLoungeDetails::class)
  29.      */
  30.     private $loungeGp;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $loungeOther;
  35.     /**
  36.      * @ORM\Column(type="datetime")
  37.      */
  38.     private $dateStart;
  39.     /**
  40.      * @ORM\Column(type="time")
  41.      */
  42.     private $hourEnd;
  43.     /**
  44.      * @ORM\Column(type="integer")
  45.      */
  46.     private $gratitudes;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=User::class)
  49.      * @ORM\JoinColumn(nullable=false)
  50.      */
  51.     private $createdId;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=User::class)
  54.      * @ORM\JoinColumn(nullable=false)
  55.      */
  56.     private $updatedId;
  57.     /**
  58.      * @ORM\Column(type="datetime_immutable")
  59.      */
  60.     private $createdAt;
  61.     /**
  62.      * @ORM\Column(type="datetime_immutable")
  63.      */
  64.     private $updatedAt;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity=HtFile::class, inversedBy="htItems")
  67.      * @ORM\JoinColumn(nullable=false)
  68.      */
  69.     private $htFile;
  70.     /**
  71.      * @ORM\Column(type="integer", nullable=true)
  72.      */
  73.     private $pax;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=HtMenu::class, mappedBy="htItem", cascade={"persist", "remove"})
  76.      */
  77.     private $htMenus;
  78.     /**
  79.      * @ORM\Column(type="text", nullable=true)
  80.      */
  81.     private $observation;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=HtExtra::class, mappedBy="htItem", cascade={"persist", "remove"})
  84.      */
  85.     private $htExtras;
  86.     /**
  87.      * @ORM\Column(type="string", length=55, nullable=true)
  88.      */
  89.     private $type;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity=HtNote::class, mappedBy="htItem", orphanRemoval=true)
  92.      */
  93.     private $htNotes;
  94.     public function __construct()
  95.     {
  96.         $this->htExtras = new ArrayCollection();
  97.         $this->htNotes = new ArrayCollection();
  98.         $this->htMenus = new ArrayCollection();
  99.     }
  100.     public function getId(): ?int
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function getReservationService(): ?ReservationService
  105.     {
  106.         return $this->reservationService;
  107.     }
  108.     public function setReservationService(?ReservationService $reservationService): self
  109.     {
  110.         $this->reservationService $reservationService;
  111.         return $this;
  112.     }
  113.     public function getLoungeGp(): ?ReservationLoungeDetails
  114.     {
  115.         return $this->loungeGp;
  116.     }
  117.     public function setLoungeGp(?ReservationLoungeDetails $loungeGp): self
  118.     {
  119.         $this->loungeGp $loungeGp;
  120.         return $this;
  121.     }
  122.     public function getLoungeOther(): ?string
  123.     {
  124.         return $this->loungeOther;
  125.     }
  126.     public function setLoungeOther(?string $loungeOther): self
  127.     {
  128.         $this->loungeOther $loungeOther;
  129.         return $this;
  130.     }
  131.     public function getDateStart(): ?\DateTimeInterface
  132.     {
  133.         return $this->dateStart;
  134.     }
  135.     public function setDateStart(\DateTimeInterface $dateStart): self
  136.     {
  137.         $this->dateStart $dateStart;
  138.         return $this;
  139.     }
  140.     public function getHourEnd(): ?\DateTimeInterface
  141.     {
  142.         return $this->hourEnd;
  143.     }
  144.     public function setHourEnd(\DateTimeInterface $hourEnd): self
  145.     {
  146.         $this->hourEnd $hourEnd;
  147.         return $this;
  148.     }
  149.     public function getGratitudes(): ?int
  150.     {
  151.         return $this->gratitudes;
  152.     }
  153.     public function setGratitudes(int $gratitudes): self
  154.     {
  155.         $this->gratitudes $gratitudes;
  156.         return $this;
  157.     }
  158.     public function getCreatedId(): ?User
  159.     {
  160.         return $this->createdId;
  161.     }
  162.     public function setCreatedId(?User $createdId): self
  163.     {
  164.         $this->createdId $createdId;
  165.         return $this;
  166.     }
  167.     public function getUpdatedId(): ?User
  168.     {
  169.         return $this->updatedId;
  170.     }
  171.     public function setUpdatedId(?User $updatedId): self
  172.     {
  173.         $this->updatedId $updatedId;
  174.         return $this;
  175.     }
  176.     public function getCreatedAt(): ?\DateTimeImmutable
  177.     {
  178.         return $this->createdAt;
  179.     }
  180.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  181.     {
  182.         $this->createdAt $createdAt;
  183.         return $this;
  184.     }
  185.     public function getUpdatedAt(): ?\DateTimeImmutable
  186.     {
  187.         return $this->updatedAt;
  188.     }
  189.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  190.     {
  191.         $this->updatedAt $updatedAt;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @ORM\PrePersist
  196.      */
  197.     public function setCreatedAtValue()
  198.     {
  199.         $this->createdAt = new \DateTimeImmutable();
  200.         if ($this->dateStart === null) { $this->dateStart = new \DateTime(); }
  201.         if ($this->hourEnd === null) { $this->hourEnd = new \DateTime(); }
  202.         $this->gratitudes 0;
  203.     }
  204.     /**
  205.      * @ORM\PrePersist
  206.      * @ORM\PreUpdate
  207.      */
  208.     public function setUpdatedAtValue()
  209.     {
  210.         $this->updatedAt = new \DateTimeImmutable();
  211.     }
  212.     public function getHtFile(): ?HtFile
  213.     {
  214.         return $this->htFile;
  215.     }
  216.     public function setHtFile(?HtFile $htFile): self
  217.     {
  218.         $this->htFile $htFile;
  219.         return $this;
  220.     }
  221.     public function getPax(): ?int
  222.     {
  223.         return $this->pax;
  224.     }
  225.     public function setPax(?int $pax): self
  226.     {
  227.         $this->pax $pax;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return Collection|HtMenu[]
  232.      */
  233.     public function getHtMenus(): Collection
  234.     {
  235.         return $this->htMenus;
  236.     }
  237.     public function addHtMenu(HtMenu $htMenu): self
  238.     {
  239.         if (!$this->htMenus->contains($htMenu)) {
  240.             $this->htMenus[] = $htMenu;
  241.             $htMenu->setHtItem($this);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeHtMenu(HtMenu $htMenu): self
  246.     {
  247.         if ($this->htMenus->removeElement($htMenu)) {
  248.             // set the owning side to null (unless already changed)
  249.             if ($htMenu->getHtItem() === $this) {
  250.                 $htMenu->setHtItem(null);
  251.             }
  252.         }
  253.         return $this;
  254.     }
  255.     public function getObservation(): ?string
  256.     {
  257.         return $this->observation;
  258.     }
  259.     public function setObservation(?string $observation): self
  260.     {
  261.         $this->observation $observation;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, HtExtra>
  266.      */
  267.     public function getHtExtras(): Collection
  268.     {
  269.         return $this->htExtras;
  270.     }
  271.     public function addHtExtra(HtExtra $htExtra): self
  272.     {
  273.         if (!$this->htExtras->contains($htExtra)) {
  274.             $this->htExtras[] = $htExtra;
  275.             $htExtra->setHtItem($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeHtExtra(HtExtra $htExtra): self
  280.     {
  281.         if ($this->htExtras->removeElement($htExtra)) {
  282.             // set the owning side to null (unless already changed)
  283.             if ($htExtra->getHtItem() === $this) {
  284.                 $htExtra->setHtItem(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     public function getType(): ?string
  290.     {
  291.         return $this->type;
  292.     }
  293.     public function setType(?string $type): self
  294.     {
  295.         $this->type $type;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection<int, HtNote>
  300.      */
  301.     public function getHtNotes(): Collection
  302.     {
  303.         return $this->htNotes;
  304.     }
  305.     public function addHtNote(HtNote $htNote): self
  306.     {
  307.         if (!$this->htNotes->contains($htNote)) {
  308.             $this->htNotes[] = $htNote;
  309.             $htNote->setHtItem($this);
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeHtNote(HtNote $htNote): self
  314.     {
  315.         if ($this->htNotes->removeElement($htNote)) {
  316.             // set the owning side to null (unless already changed)
  317.             if ($htNote->getHtItem() === $this) {
  318.                 $htNote->setHtItem(null);
  319.             }
  320.         }
  321.         return $this;
  322.     }
  323.     /**
  324.      * Para la función clone de php nativa
  325.      */
  326.     public function __clone()
  327.     {
  328.         // Resetear el ID
  329.         $this->id null;
  330.         // Clonar y resetear relaciones si es necesario
  331.         if ($this->reservationService) {
  332.             $this->reservationService = clone $this->reservationService;
  333.         }
  334.         if ($this->htMenus) {
  335.             $clonedMenus = [];
  336.             foreach ($this->htMenus as $menu) {
  337.                 $clonedMenu = clone $menu;
  338.                 $clonedMenu->setHtItem($this);
  339.                 $clonedMenus[] = $clonedMenu;
  340.             }
  341.             $this->htMenus $clonedMenus;
  342.         }
  343.         // Clonar colecciones de HtExtras
  344.         $this->htExtras = new ArrayCollection();
  345.         foreach ($this->htExtras as $extra) {
  346.             $clonedExtra = clone $extra;
  347.             $clonedExtra->setHtItem($this);
  348.             $this->htExtras->add($clonedExtra);
  349.         }
  350.         // Clonar colecciones de HtNotes
  351.         $this->htNotes = new ArrayCollection();
  352.         foreach ($this->htNotes as $note) {
  353.             $clonedNote = clone $note;
  354.             $clonedNote->setHtItem($this);
  355.             $this->htNotes->add($clonedNote);
  356.         }
  357.         // No es necesario clonar las relaciones ManyToOne o OneToOne que no se deben duplicar en profundidad
  358.         // pero se debe reasignar la relación inversa en caso de que se dupliquen.
  359.     }
  360.     /**
  361.      * @Assert\Callback
  362.      */
  363.     public function validateDateRange(ExecutionContextInterface $context$payload): void
  364.     {
  365.         if ($this->htFile === null || $this->dateStart === null) {
  366.             return;
  367.         }
  368.         $fileStart $this->htFile->getDateStart();
  369.         $fileEnd $this->htFile->getDateEnd();
  370.         if ($fileStart && $this->dateStart $fileStart) {
  371.             $context->buildViolation('La fecha no puede ser anterior a la fecha de inicio del expediente (%date%).')
  372.                 ->setParameter('%date%'$fileStart->format('d/m/Y H:i'))
  373.                 ->atPath('dateStart')
  374.                 ->addViolation();
  375.         }
  376.         if ($fileEnd && $this->dateStart $fileEnd) {
  377.             $context->buildViolation('La fecha no puede ser posterior a la fecha de fin del expediente (%date%).')
  378.                 ->setParameter('%date%'$fileEnd->format('d/m/Y H:i'))
  379.                 ->atPath('dateStart')
  380.                 ->addViolation();
  381.         }
  382.     }
  383.     public function __toString(): string
  384.     {
  385.         return (string) ($this->id ?? 'nuevo');
  386.     }
  387. }