<?php
namespace App\Entity;
use App\Entity\CustomExtra;
use App\Entity\Payment\AbstractPayment;
use App\Repository\TokenRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TokenRepository::class)
*/
class Token extends AbstractReservation
{
/**
* @ORM\Column(type="string", length=255)
*/
private $value;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentid;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $attention;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $services;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $prepaymentcode;
/**
* @ORM\OneToMany(targetEntity="LogEmail", mappedBy="token", orphanRemoval=true, cascade={"remove"})
*/
private $logemails;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $templateCarteCadeau;
/**
* @ORM\ManyToOne(targetEntity=Code::class)
*/
private $codeReduction;
/**
* @ORM\OneToMany(targetEntity=AbstractPayment::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
*/
private Collection $payments;
/**
* @ORM\OneToMany(targetEntity=ExtraReservation::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
*/
private $extraReservations;
/**
* @ORM\OneToMany(targetEntity=CustomExtra::class, mappedBy="token", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $customExtras;
/**
* @ORM\OneToMany(targetEntity=Participant::class, mappedBy="token", orphanRemoval=true, cascade={"persist"})
*/
private $participants;
/**
* @ORM\ManyToOne(targetEntity=Reservation::class, inversedBy="tokens", cascade={"persist"})
*/
private $reservation;
/**
* @ORM\ManyToOne(targetEntity=Code::class, inversedBy="token", cascade={"persist", "remove"})
*/
private $codePromo;
/**
* @ORM\ManyToOne(targetEntity=Contact::class, inversedBy="tokens", cascade={"persist"})
*/
private $contact;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $pourQui;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $envoiId;
/**
* @ORM\ManyToOne(targetEntity=Contact::class)
*/
private $carteDestinataire;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $physicalCard;
/**
* @ORM\OneToOne(targetEntity=DeliveryAddress::class, cascade={"persist", "remove"})
*/
private $deliveryAddress;
public function __construct()
{
parent::__construct();
$this->logemails = new ArrayCollection();
$this->value = rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=');
$this->extraReservations = new ArrayCollection();
$this->customExtras = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->participants = new ArrayCollection();
}
public function __clone()
{
$participants = new ArrayCollection();
foreach($this->getParticipants() as $participant) {
$newParticipant = clone $participant;
$participants->add($newParticipant);
$this->removeParticipant($participant);
}
$this->participants = $participants;
$extraReservations = new ArrayCollection();
foreach($this->getExtraReservations() as $extraReservation) {
$newExtraReservation = clone $extraReservation;
$extraReservations->add($newExtraReservation);
$this->removeExtraReservation($extraReservation);
}
$this->extraReservations = $extraReservations;
$customExtras = new ArrayCollection();
foreach($this->getCustomExtras() as $customExtra) {
$newCustomExtra = clone $customExtra;
$newCustomExtra->setToken($this);
$customExtras->add($newCustomExtra);
}
$this->customExtras = $customExtras;
}
public function getValue(): ?string
{
return $this->value;
}
/**
* @return Collection<int, LogEmail>
*/
public function getLogEmails(): Collection
{
return $this->logemails;
}
public function setLogEmails(LogEmail $logemails): self
{
if (!$this->logemails->contains($logemails)) {
$this->logemails[] = $logemails;
$logemails->setToken($this);
}
return $this;
}
public function setValue(string $value): self
{
$this->value = $value;
return $this;
}
public function getCodePromo(): ?Code
{
return $this->codePromo;
}
public function setCodePromo(?Code $codePromo): self
{
$this->codePromo = $codePromo;
return $this;
}
public function getPaymentid(): ?string
{
return $this->paymentid;
}
public function setPaymentid(?string $paymentid): self
{
$this->paymentid = $paymentid;
return $this;
}
public function getAttention(): ?string
{
return $this->attention;
}
public function setAttention(?string $attention): self
{
$this->attention = $attention;
return $this;
}
public function getServices(): ?string
{
return $this->services;
}
public function setServices(?string $services): self
{
$this->services = $services;
return $this;
}
public function getPrepaymentcode(): ?string
{
return $this->prepaymentcode;
}
public function setPrepaymentcode(?string $prepaymentcode): self
{
$this->prepaymentcode = $prepaymentcode;
return $this;
}
public function getTemplateCarteCadeau(): ?string
{
return $this->templateCarteCadeau;
}
public function setTemplateCarteCadeau(?string $templateCarteCadeau): self
{
$this->templateCarteCadeau = $templateCarteCadeau;
return $this;
}
public function getCodeReduction(): ?Code
{
return $this->codeReduction;
}
public function setCodeReduction(?Code $codeReduction): self
{
$this->codeReduction = $codeReduction;
return $this;
}
/**
* @return Collection<int, AbstractPayment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
/**
* @return Collection<int, AbstractPayment>
*/
public function getValidatedPayments(): Collection
{
return $this->payments->filter(function(AbstractPayment $payment) {
return $payment->getDatePayment() !== null;
});
}
public function addPayment(AbstractPayment $payment): static
{
if (!$this->payments->contains($payment)) {
$this->payments->add($payment);
$payment->setToken($this);
}
return $this;
}
/**
* @return Collection<int, ExtraReservation>
*/
public function getExtraReservations(): Collection
{
return $this->extraReservations;
}
/**
* @return Collection<int, ExtraReservation>
*/
public function getActiveExtraReservations(): Collection
{
return $this->extraReservations->filter(function(ExtraReservation $extraReservation) {
return !$extraReservation->isEmpty();
});
}
public function addExtraReservation(ExtraReservation $extraReservation): self
{
if (!$this->extraReservations->contains($extraReservation)) {
$this->extraReservations[] = $extraReservation;
$extraReservation->setToken($this);
}
return $this;
}
public function removeExtraReservation(ExtraReservation $extraReservation): self
{
if ($this->extraReservations->removeElement($extraReservation)) {
// set the owning side to null (unless already changed)
if ($extraReservation->getToken() === $this) {
$extraReservation->setToken(null);
}
}
return $this;
}
/**
* @return Collection<int, CustomExtra>
*/
public function getCustomExtras(): Collection
{
return $this->customExtras;
}
public function addCustomExtra(CustomExtra $customExtra): self
{
if (!$this->customExtras->contains($customExtra)) {
$this->customExtras[] = $customExtra;
$customExtra->setToken($this);
}
return $this;
}
public function removeCustomExtra(CustomExtra $customExtra): self
{
if ($this->customExtras->removeElement($customExtra)) {
if ($customExtra->getToken() === $this) {
$customExtra->setToken(null);
}
}
return $this;
}
/**
* @return Collection<int, Participant>
*/
public function getParticipants(): Collection
{
return $this->participants;
}
public function addParticipant(Participant $participant): self
{
if (!$this->participants->contains($participant)) {
$this->participants[] = $participant;
$participant->setToken($this);
}
return $this;
}
public function removeParticipant(Participant $participant): self
{
if ($this->participants->removeElement($participant)) {
// set the owning side to null (unless already changed)
if ($participant->getToken() === $this) {
$participant->setToken(null);
}
}
return $this;
}
public function getReservation(): ?Reservation
{
return $this->reservation;
}
public function setReservation(?Reservation $reservation): self
{
$this->reservation = $reservation;
return $this;
}
public function getSummary(): array
{
return [
"offre" => $this->getOffer() === "60" ? "tunnel.summary.offer.label_plongeon" : "tunnel.summary.offer.label_grand_plongeon",
"personne" => ( $this->getDuo() * 2 ) + ( $this->getSolo() ),
"bain" => $this->getDuo() + $this->getSolo(),
];
}
public function getContact(): ?Contact
{
return $this->contact;
}
public function setContact(?Contact $contact): self
{
$this->contact = $contact;
return $this;
}
public function getPourQui(): ?string
{
return $this->pourQui;
}
public function setPourQui(?string $pourQui): self
{
$this->pourQui = $pourQui;
return $this;
}
public function getEnvoiId(): ?int
{
return $this->envoiId;
}
public function setEnvoiId(?int $envoiId): self
{
$this->envoiId = $envoiId;
return $this;
}
public function getCarteDestinataire(): ?Contact
{
return $this->carteDestinataire;
}
public function setCarteDestinataire(?Contact $carteDestinataire): self
{
$this->carteDestinataire = $carteDestinataire;
return $this;
}
public function isPhysicalCard(): ?bool
{
return $this->physicalCard;
}
public function setPhysicalCard(?bool $physicalCard): self
{
$this->physicalCard = $physicalCard;
return $this;
}
public function getDeliveryAddress(): ?DeliveryAddress
{
return $this->deliveryAddress;
}
public function setDeliveryAddress(?DeliveryAddress $deliveryAddress): self
{
$this->deliveryAddress = $deliveryAddress;
return $this;
}
public function getNbParticipants(): ?int
{
$this->nbParticipants == 0 ? $this->nbParticipants = $this->getSolo() + $this->getDuo() * 2 : null;
return $this->nbParticipants;
}
public function setNbParticipants(?int $nbParticipants): self
{
$this->nbParticipants = $nbParticipants;
return $this;
}
}