src/Entity/Token.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\CustomExtra;
  4. use App\Entity\Payment\AbstractPayment;
  5. use App\Repository\TokenRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=TokenRepository::class)
  11.  */
  12. class Token extends AbstractReservation
  13. {
  14.     /**
  15.      * @ORM\Column(type="string", length=255)
  16.      */
  17.     private $value;
  18.     /**
  19.      * @ORM\Column(type="string", length=255, nullable=true)
  20.      */
  21.     private $paymentid;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $attention;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $services;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $prepaymentcode;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity="LogEmail", mappedBy="token", orphanRemoval=true, cascade={"remove"})
  36.      */
  37.     private $logemails;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $templateCarteCadeau;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=Code::class)
  44.      */
  45.     private $codeReduction;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=AbstractPayment::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
  48.      */
  49.     private Collection $payments;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=ExtraReservation::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
  52.      */
  53.     private $extraReservations;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=CustomExtra::class, mappedBy="token", orphanRemoval=true, cascade={"persist", "remove"})
  56.      */
  57.     private $customExtras;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity=Participant::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
  60.      */
  61.     private $participants;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity=Reservation::class, inversedBy="tokens", cascade={"persist"})
  64.      */
  65.     private $reservation;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity=Code::class, inversedBy="token", cascade={"persist", "remove"})
  68.      */
  69.     private $codePromo;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=Contact::class, inversedBy="tokens", cascade={"persist"})
  72.      */
  73.     private $contact;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      */
  77.     private $pourQui;
  78.     /**
  79.      * @ORM\Column(type="integer", nullable=true)
  80.      */
  81.     private $envoiId;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity=Contact::class)
  84.      */
  85.     private $carteDestinataire;
  86.     /**
  87.      * @ORM\Column(type="boolean", nullable=true)
  88.      */
  89.     private $physicalCard;
  90.     /**
  91.      * @ORM\OneToOne(targetEntity=DeliveryAddress::class, cascade={"persist", "remove"})
  92.      */
  93.     private $deliveryAddress;
  94.     public function __construct()
  95.     {
  96.         parent::__construct();
  97.         $this->logemails = new ArrayCollection();
  98.         $this->value rtrim(strtr(base64_encode(random_bytes(32)), '+/''-_'), '=');
  99.         $this->extraReservations = new ArrayCollection();
  100.         $this->customExtras = new ArrayCollection();
  101.         $this->payments = new ArrayCollection();
  102.         $this->participants = new ArrayCollection();
  103.     }
  104.     public function __clone()
  105.     {
  106.         $participants = new ArrayCollection();
  107.         foreach($this->getParticipants() as $participant) {
  108.             $newParticipant = clone $participant;
  109.             $participants->add($newParticipant);
  110.             $this->removeParticipant($participant);
  111.         }
  112.         $this->participants $participants;
  113.         
  114.         $extraReservations = new ArrayCollection();
  115.         foreach($this->getExtraReservations() as $extraReservation) {
  116.             $newExtraReservation = clone $extraReservation;
  117.             $extraReservations->add($newExtraReservation);
  118.             $this->removeExtraReservation($extraReservation);
  119.         }
  120.         $this->extraReservations $extraReservations;
  121.         $customExtras = new ArrayCollection();
  122.         foreach($this->getCustomExtras() as $customExtra) {
  123.             $newCustomExtra = clone $customExtra;
  124.             $newCustomExtra->setToken($this);
  125.             $customExtras->add($newCustomExtra);
  126.         }
  127.         $this->customExtras $customExtras;
  128.     }
  129.     public function getValue(): ?string
  130.     {
  131.         return $this->value;
  132.     }
  133.     /**
  134.      * @return Collection<int, LogEmail>
  135.      */
  136.     public function getLogEmails(): Collection
  137.     {
  138.         return $this->logemails;
  139.     }
  140.     public function setLogEmails(LogEmail $logemails): self
  141.     {
  142.         if (!$this->logemails->contains($logemails)) {
  143.             $this->logemails[] = $logemails;
  144.             $logemails->setToken($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function setValue(string $value): self
  149.     {
  150.         $this->value $value;
  151.         return $this;
  152.     }
  153.     public function getCodePromo(): ?Code
  154.     {
  155.         return $this->codePromo;
  156.     }
  157.     public function setCodePromo(?Code $codePromo): self
  158.     {
  159.         $this->codePromo $codePromo;
  160.         return $this;
  161.     }
  162.     public function getPaymentid(): ?string
  163.     {
  164.         return $this->paymentid;
  165.     }
  166.     public function setPaymentid(?string $paymentid): self
  167.     {
  168.         $this->paymentid $paymentid;
  169.         return $this;
  170.     }
  171.     public function getAttention(): ?string
  172.     {
  173.         return $this->attention;
  174.     }
  175.     public function setAttention(?string $attention): self
  176.     {
  177.         $this->attention $attention;
  178.         return $this;
  179.     }
  180.     public function getServices(): ?string
  181.     {
  182.         return $this->services;
  183.     }
  184.     public function setServices(?string $services): self
  185.     {
  186.         $this->services $services;
  187.         return $this;
  188.     }
  189.     public function getPrepaymentcode(): ?string
  190.     {
  191.         return $this->prepaymentcode;
  192.     }
  193.     public function setPrepaymentcode(?string $prepaymentcode): self
  194.     {
  195.         $this->prepaymentcode $prepaymentcode;
  196.         return $this;
  197.     }
  198.     public function getTemplateCarteCadeau(): ?string
  199.     {
  200.         return $this->templateCarteCadeau;
  201.     }
  202.     public function setTemplateCarteCadeau(?string $templateCarteCadeau): self
  203.     {
  204.         $this->templateCarteCadeau $templateCarteCadeau;
  205.         return $this;
  206.     }
  207.     public function getCodeReduction(): ?Code
  208.     {
  209.         return $this->codeReduction;
  210.     }
  211.     public function setCodeReduction(?Code $codeReduction): self
  212.     {
  213.         $this->codeReduction $codeReduction;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return Collection<int, AbstractPayment>
  218.      */
  219.     public function getPayments(): Collection
  220.     {
  221.         return $this->payments;
  222.     }
  223.     /**
  224.      * @return Collection<int, AbstractPayment>
  225.      */
  226.     public function getValidatedPayments(): Collection
  227.     {
  228.         return $this->payments->filter(function(AbstractPayment $payment) {
  229.             return $payment->getDatePayment() !== null;
  230.         });
  231.     }
  232.     public function addPayment(AbstractPayment $payment): static
  233.     {
  234.         if (!$this->payments->contains($payment)) {
  235.             $this->payments->add($payment);
  236.             $payment->setToken($this);
  237.         }
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return Collection<int, ExtraReservation>
  242.      */
  243.     public function getExtraReservations(): Collection
  244.     {
  245.         return $this->extraReservations;
  246.     }
  247.     /**
  248.      * @return Collection<int, ExtraReservation>
  249.      */
  250.     public function getActiveExtraReservations(): Collection
  251.     {
  252.         return $this->extraReservations->filter(function(ExtraReservation $extraReservation) {
  253.             return !$extraReservation->isEmpty();
  254.         });
  255.     }
  256.     public function addExtraReservation(ExtraReservation $extraReservation): self
  257.     {
  258.         if (!$this->extraReservations->contains($extraReservation)) {
  259.             $this->extraReservations[] = $extraReservation;
  260.             $extraReservation->setToken($this);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeExtraReservation(ExtraReservation $extraReservation): self
  265.     {
  266.         if ($this->extraReservations->removeElement($extraReservation)) {
  267.             // set the owning side to null (unless already changed)
  268.             if ($extraReservation->getToken() === $this) {
  269.                 $extraReservation->setToken(null);
  270.             }
  271.         }
  272.         return $this;
  273.     }
  274.     /**
  275.      * @return Collection<int, CustomExtra>
  276.      */
  277.     public function getCustomExtras(): Collection
  278.     {
  279.         return $this->customExtras;
  280.     }
  281.     public function addCustomExtra(CustomExtra $customExtra): self
  282.     {
  283.         if (!$this->customExtras->contains($customExtra)) {
  284.             $this->customExtras[] = $customExtra;
  285.             $customExtra->setToken($this);
  286.         }
  287.         return $this;
  288.     }
  289.     public function removeCustomExtra(CustomExtra $customExtra): self
  290.     {
  291.         if ($this->customExtras->removeElement($customExtra)) {
  292.             if ($customExtra->getToken() === $this) {
  293.                 $customExtra->setToken(null);
  294.             }
  295.         }
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection<int, Participant>
  300.      */
  301.     public function getParticipants(): Collection
  302.     {
  303.         return $this->participants;
  304.     }
  305.     public function addParticipant(Participant $participant): self
  306.     {
  307.         if (!$this->participants->contains($participant)) {
  308.             $this->participants[] = $participant;
  309.             $participant->setToken($this);
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeParticipant(Participant $participant): self
  314.     {
  315.         if ($this->participants->removeElement($participant)) {
  316.             // set the owning side to null (unless already changed)
  317.             if ($participant->getToken() === $this) {
  318.                 $participant->setToken(null);
  319.             }
  320.         }
  321.         return $this;
  322.     }
  323.     public function getReservation(): ?Reservation
  324.     {
  325.         return $this->reservation;
  326.     }
  327.     public function setReservation(?Reservation $reservation): self
  328.     {
  329.         $this->reservation $reservation;
  330.         return $this;
  331.     }
  332.     
  333.     public function getSummary(): array
  334.     {
  335.         return [
  336.             "offre" => $this->getOffer() === "60" "tunnel.summary.offer.label_plongeon" "tunnel.summary.offer.label_grand_plongeon",
  337.             "personne" => ( $this->getDuo() * ) + ( $this->getSolo() ),
  338.             "bain" => $this->getDuo() + $this->getSolo(),
  339.         ];
  340.     }
  341.     public function getContact(): ?Contact
  342.     {
  343.         return $this->contact;
  344.     }
  345.     public function setContact(?Contact $contact): self
  346.     {
  347.         $this->contact $contact;
  348.         return $this;
  349.     }
  350.     public function getPourQui(): ?string
  351.     {
  352.         return $this->pourQui;
  353.     }
  354.     public function setPourQui(?string $pourQui): self
  355.     {
  356.         $this->pourQui $pourQui;
  357.         return $this;
  358.     }
  359.     public function getEnvoiId(): ?int
  360.     {
  361.         return $this->envoiId;
  362.     }
  363.     public function setEnvoiId(?int $envoiId): self
  364.     {
  365.         $this->envoiId $envoiId;
  366.         return $this;
  367.     }
  368.     public function getCarteDestinataire(): ?Contact
  369.     {
  370.         return $this->carteDestinataire;
  371.     }
  372.     public function setCarteDestinataire(?Contact $carteDestinataire): self
  373.     {
  374.         $this->carteDestinataire $carteDestinataire;
  375.         return $this;
  376.     }
  377.     public function isPhysicalCard(): ?bool
  378.     {
  379.         return $this->physicalCard;
  380.     }
  381.     public function setPhysicalCard(?bool $physicalCard): self
  382.     {
  383.         $this->physicalCard $physicalCard;
  384.         return $this;
  385.     }
  386.     public function getDeliveryAddress(): ?DeliveryAddress
  387.     {
  388.         return $this->deliveryAddress;
  389.     }
  390.     public function setDeliveryAddress(?DeliveryAddress $deliveryAddress): self
  391.     {
  392.         $this->deliveryAddress $deliveryAddress;
  393.         return $this;
  394.     }
  395.     public function getNbParticipants(): ?int
  396.     {
  397.         $this->nbParticipants == $this->nbParticipants $this->getSolo() + $this->getDuo() * null;
  398.         return $this->nbParticipants;
  399.     }
  400.     public function setNbParticipants(?int $nbParticipants): self
  401.     {
  402.         $this->nbParticipants $nbParticipants;
  403.         return $this;
  404.     }
  405. }