src/Entity/Contact.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use App\Entity\Payment\AbstractPayment;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=ContactRepository::class)
  12.  * @UniqueEntity("email")
  13.  */
  14. class Contact
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=100, unique=true)
  24.      * @Assert\Email(message="L'email {{ value }} n'est pas un email valide.")
  25.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $nom;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $prenom;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $adresse;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $ville;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $codePostal;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $pays;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $telephone;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $company;
  59.     /**
  60.      * @ORM\Column(type="boolean", nullable=true)
  61.      */
  62.     protected $newsletter;
  63.     /**
  64.      * @ORM\Column(type="boolean", nullable=false, options={"default": false})
  65.      */
  66.     private $isLoyal false;
  67.     /**
  68.      * @ORM\Column(type="string", length=1, nullable=true)
  69.      */
  70.     private $gender;
  71.     /**
  72.      * @ORM\OneToMany(targetEntity=Reservation::class, mappedBy="contact")
  73.      */
  74.     private $reservations;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity=Privatisation::class, mappedBy="contact")
  77.      */
  78.     private $privatisations;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity=Token::class, mappedBy="contact")
  81.      */
  82.     private $tokens;
  83.     /**
  84.      * @ORM\Column(type="text", nullable=true)
  85.      */
  86.     private $commentaire;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity=AbstractPayment::class, mappedBy="reservation")
  89.      */
  90.     private $abstractPayments;
  91.     public function __construct()
  92.     {
  93.         $this->reservations = new ArrayCollection();
  94.         $this->privatisations = new ArrayCollection();
  95.         $this->tokens = new ArrayCollection();
  96.         $this->abstractPayments = new ArrayCollection();
  97.     }
  98.     public function getId(): ?int
  99.     {
  100.         return $this->id;
  101.     }
  102.     public function getEmail(): ?string
  103.     {
  104.         return $this->email;
  105.     }
  106.     public function setEmail(string $email): self
  107.     {
  108.         $this->email $email;
  109.         return $this;
  110.     }
  111.     public function getNom(): ?string
  112.     {
  113.         return ucfirst(strtolower($this->nom));
  114.     }
  115.     public function setNom(?string $nom): self
  116.     {
  117.         $this->nom $nom;
  118.         return $this;
  119.     }
  120.     public function getPrenom(): ?string
  121.     {
  122.         return ucfirst(strtolower($this->prenom));
  123.     }
  124.     public function setPrenom(?string $prenom): self
  125.     {
  126.         $this->prenom $prenom;
  127.         return $this;
  128.     }
  129.     public function getFullName(): string
  130.     {
  131.         return $this->getPrenom() . ' ' $this->getNom();
  132.     }
  133.     public function getAdresse(): ?string
  134.     {
  135.         return $this->adresse;
  136.     }
  137.     public function setAdresse(?string $adresse): self
  138.     {
  139.         $this->adresse $adresse;
  140.         return $this;
  141.     }
  142.     public function getVille(): ?string
  143.     {
  144.         return $this->ville;
  145.     }
  146.     public function setVille(?string $ville): self
  147.     {
  148.         $this->ville $ville;
  149.         return $this;
  150.     }
  151.     public function getCodePostal(): ?string
  152.     {
  153.         return $this->codePostal;
  154.     }
  155.     public function setCodePostal(?string $codePostal): self
  156.     {
  157.         $this->codePostal $codePostal;
  158.         return $this;
  159.     }
  160.     public function getPays(): ?string
  161.     {
  162.         return $this->pays;
  163.     }
  164.     public function setPays(?string $pays): self
  165.     {
  166.         $this->pays $pays;
  167.         return $this;
  168.     }
  169.     public function getTelephone(): ?string
  170.     {
  171.         return $this->telephone;
  172.     }
  173.     public function setTelephone(?string $telephone): self
  174.     {
  175.         $this->telephone $telephone;
  176.         return $this;
  177.     }
  178.     public function getCompany(): ?string
  179.     {
  180.         return $this->company;
  181.     }
  182.     public function setCompany(?string $company): self
  183.     {
  184.         $this->company $company;
  185.         return $this;
  186.     }
  187.     public function getNewsletter(): ?bool
  188.     {
  189.         return $this->newsletter;
  190.     }
  191.     public function setNewsletter(?bool $newsletter): self
  192.     {
  193.         $this->newsletter $newsletter;
  194.         return $this;
  195.     }
  196.     public function getIsLoyal(): bool
  197.     {
  198.         return $this->isLoyal;
  199.     }
  200.     public function setIsLoyal(bool $isLoyal): self
  201.     {
  202.         $this->isLoyal $isLoyal;
  203.         return $this;
  204.     }
  205.     public function getGender(): ?string
  206.     {
  207.         return $this->gender;
  208.     }
  209.     public function setGender(?string $gender): self
  210.     {
  211.         $this->gender $gender;
  212.         return $this;
  213.     }
  214.     /**
  215.      * @return Collection<int, Reservation>
  216.      */
  217.     public function getReservations(): Collection
  218.     {
  219.         return $this->reservations;
  220.     }
  221.     public function getConfirmedReservations(): Collection
  222.     {
  223.         return $this->reservations->filter(function (Reservation $reservation) {
  224.             return $reservation->getConfirmed() && !$reservation->getDeleted();
  225.         });
  226.     }
  227.     public function addReservation(Reservation $reservation): self
  228.     {
  229.         if (!$this->reservations->contains($reservation)) {
  230.             $this->reservations[] = $reservation;
  231.             $reservation->setContact($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeReservation(Reservation $reservation): self
  236.     {
  237.         if ($this->reservations->removeElement($reservation)) {
  238.             // set the owning side to null (unless already changed)
  239.             if ($reservation->getContact() === $this) {
  240.                 $reservation->setContact(null);
  241.             }
  242.         }
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return Collection<int, Privatisation>
  247.      */
  248.     public function getPrivatisations(): Collection
  249.     {
  250.         return $this->privatisations;
  251.     }
  252.     public function addPrivatisation(Privatisation $privatisation): self
  253.     {
  254.         if (!$this->privatisations->contains($privatisation)) {
  255.             $this->privatisations[] = $privatisation;
  256.             $privatisation->setContact($this);
  257.         }
  258.         return $this;
  259.     }
  260.     public function removePrivatisation(Privatisation $privatisation): self
  261.     {
  262.         if ($this->privatisations->removeElement($privatisation)) {
  263.             // set the owning side to null (unless already changed)
  264.             if ($privatisation->getContact() === $this) {
  265.                 $privatisation->setContact(null);
  266.             }
  267.         }
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return Collection<int, Token>
  272.      */
  273.     public function getTokens(): Collection
  274.     {
  275.         return $this->tokens;
  276.     }
  277.     public function addToken(Token $token): self
  278.     {
  279.         if (!$this->tokens->contains($token)) {
  280.             $this->tokens[] = $token;
  281.             $token->setContact($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeToken(Token $token): self
  286.     {
  287.         if ($this->tokens->removeElement($token)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($token->getContact() === $this) {
  290.                 $token->setContact(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     public function getCommentaire(): ?string
  296.     {
  297.         return $this->commentaire;
  298.     }
  299.     public function setCommentaire(?string $commentaire): self
  300.     {
  301.         $this->commentaire $commentaire;
  302.         return $this;
  303.     }
  304.     public function calculateIsLoyal(): bool
  305.     {
  306.         // Count confirmed and non-deleted reservations
  307.         $confirmedReservations $this->reservations->filter(function (Reservation $reservation) {
  308.             return $reservation->getConfirmed() && !$reservation->getDeleted();
  309.         });
  310.         $reservationCount $confirmedReservations->count();
  311.         // Count purchased carte cadeau (exclude tokens generated from a reservation)
  312.         $carteCadeauCount 0;
  313.         foreach ($this->tokens as $token) {
  314.             if ($token->getReservation()) {
  315.                 continue;
  316.             }
  317.             if ($token->getCodePromo() && ($token->getCodePromo()->getResteAPayer() == || $token->getCodePromo()->getResteAPayer() === null)) {
  318.                 $carteCadeauCount++;
  319.             }
  320.         }
  321.         // Return true if at least 2 items total (reservations + carte cadeau)
  322.         return ($reservationCount $carteCadeauCount) >= 2;
  323.     }
  324.     public function isLoyal(): bool
  325.     {
  326.         return $this->getIsLoyal();
  327.     }
  328.     /**
  329.      * @return Collection<int, AbstractPayment>
  330.      */
  331.     public function getAbstractPayments(): Collection
  332.     {
  333.         return $this->abstractPayments;
  334.     }
  335.     public function addAbstractPayment(AbstractPayment $abstractPayment): self
  336.     {
  337.         if (!$this->abstractPayments->contains($abstractPayment)) {
  338.             $this->abstractPayments[] = $abstractPayment;
  339.             $abstractPayment->setContact($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeAbstractPayment(AbstractPayment $abstractPayment): self
  344.     {
  345.         if ($this->abstractPayments->removeElement($abstractPayment)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($abstractPayment->getContact() === $this) {
  348.                 $abstractPayment->setContact(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353. }