src/Entity/HtFile.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\MDS\VenuesBundle\Entity\Reservation;
  4. use App\Repository\HtFileRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=HtFileRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class HtFile
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=Client::class)
  24.      */
  25.     private $client;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class)
  28.      * @ORM\JoinColumn(nullable=false)
  29.      */
  30.     private $createdId;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=User::class)
  33.      * @ORM\JoinColumn(nullable=false)
  34.      */
  35.     private $updatedId;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $title;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $status;
  44.     /**
  45.      * @ORM\Column(type="integer", nullable=true)
  46.      */
  47.     private $daysBlock;
  48.     /**
  49.      * @ORM\Column(type="integer", nullable=true)
  50.      */
  51.     private $pax;
  52.     /**
  53.      * @ORM\Column(type="text", nullable=true)
  54.      */
  55.     private $description;
  56.     /**
  57.      * @ORM\Column(type="text", nullable=true)
  58.      */
  59.     private $descriptionTwo;
  60.     /**
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $contactUnregistered;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      */
  67.     private $nameContactUnregistered;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      */
  71.     private $phoneContactUnregistered;
  72.     /**
  73.      * @ORM\Column(type="datetime", nullable=true)
  74.      */
  75.     private $dateStart;
  76.     /**
  77.      * @ORM\Column(type="datetime", nullable=true)
  78.      */
  79.     private $dateEnd;
  80.     /**
  81.      * @ORM\Column(type="datetime_immutable")
  82.      */
  83.     private $createdAt;
  84.     /**
  85.      * @ORM\Column(type="datetime_immutable")
  86.      */
  87.     private $updatedAt;
  88.     /**
  89.      * @ORM\ManyToOne(targetEntity=ClientContact::class)
  90.      */
  91.     private $clientContact;
  92.     /**
  93.      * @ORM\OneToOne(targetEntity=Reservation::class, inversedBy="htFile", cascade={"persist", "remove"})
  94.      */
  95.     private $reservation;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity=HtItem::class, mappedBy="htFile", orphanRemoval=true)
  98.      */
  99.     private $htItems;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=HtVisit::class, mappedBy="reservation")
  102.      */
  103.     private $htVisits;
  104.     /**
  105.      * @ORM\Column(type="string", length=100, nullable=true)
  106.      */
  107.     private $clientType;
  108.     public function __construct()
  109.     {
  110.         $this->htItems = new ArrayCollection();
  111.         $this->htVisits = new ArrayCollection();
  112.     }
  113.     public function getId(): ?int
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function getClient(): ?Client
  118.     {
  119.         return $this->client;
  120.     }
  121.     public function setClient(?Client $client): self
  122.     {
  123.         $this->client $client;
  124.         return $this;
  125.     }
  126.     public function getCreatedId(): ?User
  127.     {
  128.         return $this->createdId;
  129.     }
  130.     public function setCreatedId(?User $createdId): self
  131.     {
  132.         $this->createdId $createdId;
  133.         return $this;
  134.     }
  135.     public function getUpdatedId(): ?User
  136.     {
  137.         return $this->updatedId;
  138.     }
  139.     public function setUpdatedId(?User $updatedId): self
  140.     {
  141.         $this->updatedId $updatedId;
  142.         return $this;
  143.     }
  144.     public function getTitle(): ?string
  145.     {
  146.         return $this->title;
  147.     }
  148.     public function setTitle(string $title): self
  149.     {
  150.         $this->title $title;
  151.         return $this;
  152.     }
  153.     public function getStatus(): ?string
  154.     {
  155.         return $this->status;
  156.     }
  157.     public function setStatus(?string $status): self
  158.     {
  159.         $this->status $status;
  160.         return $this;
  161.     }
  162.     public function getDaysBlock(): ?int
  163.     {
  164.         return $this->daysBlock;
  165.     }
  166.     public function setDaysBlock(?int $daysBlock): self
  167.     {
  168.         $this->daysBlock $daysBlock;
  169.         return $this;
  170.     }
  171.     public function getPax(): ?int
  172.     {
  173.         return $this->pax;
  174.     }
  175.     public function setPax(?int $pax): self
  176.     {
  177.         $this->pax $pax;
  178.         return $this;
  179.     }
  180.     public function getDescription(): ?string
  181.     {
  182.         return $this->description;
  183.     }
  184.     public function setDescription(?string $description): self
  185.     {
  186.         $this->description $description;
  187.         return $this;
  188.     }
  189.     public function getDescriptionTwo(): ?string
  190.     {
  191.         return $this->descriptionTwo;
  192.     }
  193.     public function setDescriptionTwo(?string $descriptionTwo): self
  194.     {
  195.         $this->descriptionTwo $descriptionTwo;
  196.         return $this;
  197.     }
  198.     public function getContactUnregistered(): ?string
  199.     {
  200.         return $this->contactUnregistered;
  201.     }
  202.     public function setContactUnregistered(?string $contactUnregistered): self
  203.     {
  204.         $this->contactUnregistered $contactUnregistered;
  205.         return $this;
  206.     }
  207.     public function getNameContactUnregistered(): ?string
  208.     {
  209.         return $this->nameContactUnregistered;
  210.     }
  211.     public function setNameContactUnregistered(?string $nameContactUnregistered): self
  212.     {
  213.         $this->nameContactUnregistered $nameContactUnregistered;
  214.         return $this;
  215.     }
  216.     public function getPhoneContactUnregistered(): ?string
  217.     {
  218.         return $this->phoneContactUnregistered;
  219.     }
  220.     public function setPhoneContactUnregistered(?string $phoneContactUnregistered): self
  221.     {
  222.         $this->phoneContactUnregistered $phoneContactUnregistered;
  223.         return $this;
  224.     }
  225.     public function getDateStart(): ?\DateTime
  226.     {
  227.         return $this->dateStart;
  228.     }
  229.     public function setDateStart(?\DateTime $dateStart): self
  230.     {
  231.         $this->dateStart $dateStart;
  232.         return $this;
  233.     }
  234.     public function getDateEnd(): ?\DateTime
  235.     {
  236.         return $this->dateEnd;
  237.     }
  238.     public function setDateEnd(?\DateTime $dateEnd): self
  239.     {
  240.         $this->dateEnd $dateEnd;
  241.         return $this;
  242.     }
  243.     public function getCreatedAt(): ?\DateTimeImmutable
  244.     {
  245.         return $this->createdAt;
  246.     }
  247.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  248.     {
  249.         $this->createdAt $createdAt;
  250.         return $this;
  251.     }
  252.     public function getUpdatedAt(): ?\DateTimeImmutable
  253.     {
  254.         return $this->updatedAt;
  255.     }
  256.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  257.     {
  258.         $this->updatedAt $updatedAt;
  259.         return $this;
  260.     }
  261.     /**
  262.      * @ORM\PrePersist
  263.      */
  264.     public function setCreatedAtValue()
  265.     {
  266.         $this->createdAt = new \DateTimeImmutable();
  267.     }
  268.     /**
  269.      * @ORM\PrePersist
  270.      * @ORM\PreUpdate
  271.      */
  272.     public function setUpdatedAtValue()
  273.     {
  274.         $this->updatedAt = new \DateTimeImmutable();
  275.     }
  276.     public function getClientContact(): ?ClientContact
  277.     {
  278.         return $this->clientContact;
  279.     }
  280.     public function setClientContact(?ClientContact $clientContact): self
  281.     {
  282.         $this->clientContact $clientContact;
  283.         return $this;
  284.     }
  285.     public function getReservation(): ?Reservation
  286.     {
  287.         return $this->reservation;
  288.     }
  289.     public function setReservation(?Reservation $reservation): self
  290.     {
  291.         $this->reservation $reservation;
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection<int, HtItem>
  296.      */
  297.     public function getHtItems(): Collection
  298.     {
  299.         return $this->htItems;
  300.     }
  301.     public function addHtItem(HtItem $htItem): self
  302.     {
  303.         if (!$this->htItems->contains($htItem)) {
  304.             $this->htItems[] = $htItem;
  305.             $htItem->setHtFile($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeHtItem(HtItem $htItem): self
  310.     {
  311.         if ($this->htItems->removeElement($htItem)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($htItem->getHtFile() === $this) {
  314.                 $htItem->setHtFile(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return Collection<int, HtVisit>
  321.      */
  322.     public function getHtVisits(): Collection
  323.     {
  324.         return $this->htVisits;
  325.     }
  326.     public function addHtVisit(HtVisit $htVisit): self
  327.     {
  328.         if (!$this->htVisits->contains($htVisit)) {
  329.             $this->htVisits[] = $htVisit;
  330.             $htVisit->setReservation($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeHtVisit(HtVisit $htVisit): self
  335.     {
  336.         if ($this->htVisits->removeElement($htVisit)) {
  337.             // set the owning side to null (unless already changed)
  338.             if ($htVisit->getReservation() === $this) {
  339.                 $htVisit->setReservation(null);
  340.             }
  341.         }
  342.         return $this;
  343.     }
  344.     public function getClientType(): ?string
  345.     {
  346.         return $this->clientType;
  347.     }
  348.     public function setClientType(?string $clientType): self
  349.     {
  350.         $this->clientType $clientType;
  351.         return $this;
  352.     }
  353.     /**
  354.      * @Assert\Callback
  355.      */
  356.     public function validateDates(ExecutionContextInterface $context$payload): void
  357.     {
  358.         // Comprobamos que ambas fechas tengan valor antes de comparar
  359.         if ($this->getDateStart() !== null && $this->getDateEnd() !== null) {
  360.             
  361.             // Si la fecha de inicio es mayor que la de fin
  362.             if ($this->getDateStart() > $this->getDateEnd()) {
  363.                 $context->buildViolation('La fecha de fin no puede ser anterior a la de inicio.')
  364.                     ->atPath('dateEnd'// Esto hace que el error salga debajo del campo 'dateEnd'
  365.                     ->addViolation();
  366.             }
  367.         }
  368.     }
  369. }