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, cascade={"persist"})
  98.      * @ORM\OrderBy({"dateStart" = "ASC"})
  99.      */
  100.     private $htItems;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity=HtVisit::class, mappedBy="reservation")
  103.      */
  104.     private $htVisits;
  105.     /**
  106.      * @ORM\Column(type="string", length=100, nullable=true)
  107.      */
  108.     private $clientType;
  109.     public function __construct()
  110.     {
  111.         $this->htItems = new ArrayCollection();
  112.         $this->htVisits = new ArrayCollection();
  113.     }
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getClient(): ?Client
  119.     {
  120.         return $this->client;
  121.     }
  122.     public function setClient(?Client $client): self
  123.     {
  124.         $this->client = $client;
  125.         return $this;
  126.     }
  127.     public function getCreatedId(): ?User
  128.     {
  129.         return $this->createdId;
  130.     }
  131.     public function setCreatedId(?User $createdId): self
  132.     {
  133.         $this->createdId = $createdId;
  134.         return $this;
  135.     }
  136.     public function getUpdatedId(): ?User
  137.     {
  138.         return $this->updatedId;
  139.     }
  140.     public function setUpdatedId(?User $updatedId): self
  141.     {
  142.         $this->updatedId = $updatedId;
  143.         return $this;
  144.     }
  145.     public function getTitle(): ?string
  146.     {
  147.         return $this->title;
  148.     }
  149.     public function setTitle(string $title): self
  150.     {
  151.         $this->title = $title;
  152.         return $this;
  153.     }
  154.     public function getStatus(): ?string
  155.     {
  156.         return $this->status;
  157.     }
  158.     public function setStatus(?string $status): self
  159.     {
  160.         $this->status = $status;
  161.         return $this;
  162.     }
  163.     public function getDaysBlock(): ?int
  164.     {
  165.         return $this->daysBlock;
  166.     }
  167.     public function setDaysBlock(?int $daysBlock): self
  168.     {
  169.         $this->daysBlock = $daysBlock;
  170.         return $this;
  171.     }
  172.     public function getPax(): ?int
  173.     {
  174.         return $this->pax;
  175.     }
  176.     public function setPax(?int $pax): self
  177.     {
  178.         $this->pax = $pax;
  179.         return $this;
  180.     }
  181.     public function getDescription(): ?string
  182.     {
  183.         return $this->description;
  184.     }
  185.     public function setDescription(?string $description): self
  186.     {
  187.         $this->description = $description;
  188.         return $this;
  189.     }
  190.     public function getDescriptionTwo(): ?string
  191.     {
  192.         return $this->descriptionTwo;
  193.     }
  194.     public function setDescriptionTwo(?string $descriptionTwo): self
  195.     {
  196.         $this->descriptionTwo = $descriptionTwo;
  197.         return $this;
  198.     }
  199.     public function getContactUnregistered(): ?string
  200.     {
  201.         return $this->contactUnregistered;
  202.     }
  203.     public function setContactUnregistered(?string $contactUnregistered): self
  204.     {
  205.         $this->contactUnregistered = $contactUnregistered;
  206.         return $this;
  207.     }
  208.     public function getNameContactUnregistered(): ?string
  209.     {
  210.         return $this->nameContactUnregistered;
  211.     }
  212.     public function setNameContactUnregistered(?string $nameContactUnregistered): self
  213.     {
  214.         $this->nameContactUnregistered = $nameContactUnregistered;
  215.         return $this;
  216.     }
  217.     public function getPhoneContactUnregistered(): ?string
  218.     {
  219.         return $this->phoneContactUnregistered;
  220.     }
  221.     public function setPhoneContactUnregistered(?string $phoneContactUnregistered): self
  222.     {
  223.         $this->phoneContactUnregistered = $phoneContactUnregistered;
  224.         return $this;
  225.     }
  226.     public function getDateStart(): ?\DateTime
  227.     {
  228.         return $this->dateStart;
  229.     }
  230.     public function setDateStart(?\DateTime $dateStart): self
  231.     {
  232.         $this->dateStart = $dateStart;
  233.         return $this;
  234.     }
  235.     public function getDateEnd(): ?\DateTime
  236.     {
  237.         return $this->dateEnd;
  238.     }
  239.     public function setDateEnd(?\DateTime $dateEnd): self
  240.     {
  241.         $this->dateEnd = $dateEnd;
  242.         return $this;
  243.     }
  244.     public function getCreatedAt(): ?\DateTimeImmutable
  245.     {
  246.         return $this->createdAt;
  247.     }
  248.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  249.     {
  250.         $this->createdAt = $createdAt;
  251.         return $this;
  252.     }
  253.     public function getUpdatedAt(): ?\DateTimeImmutable
  254.     {
  255.         return $this->updatedAt;
  256.     }
  257.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  258.     {
  259.         $this->updatedAt = $updatedAt;
  260.         return $this;
  261.     }
  262.     /**
  263.      * @ORM\PrePersist
  264.      */
  265.     public function setCreatedAtValue()
  266.     {
  267.         $this->createdAt = new \DateTimeImmutable();
  268.     }
  269.     /**
  270.      * @ORM\PrePersist
  271.      * @ORM\PreUpdate
  272.      */
  273.     public function setUpdatedAtValue()
  274.     {
  275.         $this->updatedAt = new \DateTimeImmutable();
  276.     }
  277.     public function getClientContact(): ?ClientContact
  278.     {
  279.         return $this->clientContact;
  280.     }
  281.     public function setClientContact(?ClientContact $clientContact): self
  282.     {
  283.         $this->clientContact = $clientContact;
  284.         return $this;
  285.     }
  286.     public function getReservation(): ?Reservation
  287.     {
  288.         return $this->reservation;
  289.     }
  290.     public function setReservation(?Reservation $reservation): self
  291.     {
  292.         $this->reservation = $reservation;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection<int, HtItem>
  297.      */
  298.     public function getHtItems(): Collection
  299.     {
  300.         return $this->htItems;
  301.     }
  302.     public function addHtItem(HtItem $htItem): self
  303.     {
  304.         if (!$this->htItems->contains($htItem)) {
  305.             $this->htItems[] = $htItem;
  306.             $htItem->setHtFile($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeHtItem(HtItem $htItem): self
  311.     {
  312.         if ($this->htItems->removeElement($htItem)) {
  313.             // set the owning side to null (unless already changed)
  314.             if ($htItem->getHtFile() === $this) {
  315.                 $htItem->setHtFile(null);
  316.             }
  317.         }
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return Collection<int, HtVisit>
  322.      */
  323.     public function getHtVisits(): Collection
  324.     {
  325.         return $this->htVisits;
  326.     }
  327.     public function addHtVisit(HtVisit $htVisit): self
  328.     {
  329.         if (!$this->htVisits->contains($htVisit)) {
  330.             $this->htVisits[] = $htVisit;
  331.             $htVisit->setReservation($this);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeHtVisit(HtVisit $htVisit): self
  336.     {
  337.         if ($this->htVisits->removeElement($htVisit)) {
  338.             // set the owning side to null (unless already changed)
  339.             if ($htVisit->getReservation() === $this) {
  340.                 $htVisit->setReservation(null);
  341.             }
  342.         }
  343.         return $this;
  344.     }
  345.     public function getClientType(): ?string
  346.     {
  347.         return $this->clientType;
  348.     }
  349.     public function setClientType(?string $clientType): self
  350.     {
  351.         $this->clientType = $clientType;
  352.         return $this;
  353.     }
  354.     /**
  355.      * @Assert\Callback
  356.      */
  357.     public function validateDates(ExecutionContextInterface $context, $payload): void
  358.     {
  359.         // Comprobamos que ambas fechas tengan valor antes de comparar
  360.         if ($this->getDateStart() !== null && $this->getDateEnd() !== null) {
  361.             
  362.             // Si la fecha de inicio es mayor que la de fin
  363.             if ($this->getDateStart() > $this->getDateEnd()) {
  364.                 $context->buildViolation('La fecha de fin no puede ser anterior a la de inicio.')
  365.                     ->atPath('dateEnd') // Esto hace que el error salga debajo del campo 'dateEnd'
  366.                     ->addViolation();
  367.             }
  368.         }
  369.     }
  370. }