src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Serializable;
  4. use App\Entity\Point;
  5. use App\Entity\Contact;
  6. use App\Entity\Purchase;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  15.  */
  16. class User implements UserInterface
  17. {
  18.     const NEWSLETTER_SUBSCRIBE 1;
  19.     const NEWSLETTER_UNSUBSCRIBE 0;
  20.     const EMAIL_CONFIRM 1;
  21.     const PURCHASE_ACCEPT 1;
  22.     const PURCHASE_DECLINE 2;
  23.     /**
  24.      * @ORM\Id()
  25.      * @ORM\GeneratedValue()
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, nullable=true)
  31.      */
  32.     private $email;
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string")
  36.      * @Assert\Length(
  37.      *      min = 8,
  38.      *      minMessage = "Votre mot de passe doit contenir au moins {{ limit }} caractères.",
  39.      *      allowEmptyString = false
  40.      * )
  41.      */
  42.     private $password;
  43.     /**
  44.      * @ORM\Column(type="smallint", nullable=true)
  45.      */
  46.     private $gender;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $civilite;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $firstName;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $lastName;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $address;
  63.     /**
  64.      * @ORM\Column(type="string", length=255)
  65.      * @Assert\Length(
  66.      *      min = 5,
  67.      *      minMessage = "Le code postal doit comporter 5 chiffres.",
  68.      *      allowEmptyString = false
  69.      * 
  70.      * )
  71.      */
  72.     private $postalCode;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $city;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $phoneNumber;
  81.     /**
  82.      * @Gedmo\Timestampable(on="create")
  83.      * @ORM\Column(type="datetime")
  84.      */
  85.     private $createdAt;
  86.     /**
  87.      * @Gedmo\Timestampable(on="update")
  88.      * @ORM\Column(type="datetime")
  89.      */
  90.     private $updatedAt;
  91.     /**
  92.      * @ORM\Column(type="datetime", nullable=true)
  93.      */
  94.     private $lastDateAction;
  95.     /**
  96.      * @ORM\Column(type="boolean", nullable=true)
  97.      */
  98.     private $isActive true;
  99.     /**
  100.      * @ORM\Column(type="string", length=255, nullable=true)
  101.      */
  102.     private $resetToken;
  103.     /**
  104.      * @ORM\Column(type="date", nullable=true)
  105.      */
  106.     private $birthDate;
  107.     /**
  108.      * @ORM\Column(type="boolean")
  109.      */
  110.     private $isEmailConfirm false;
  111.     /**
  112.      * @var Point[]|ArrayCollection
  113.      *
  114.      * @ORM\OneToMany(targetEntity="App\Entity\Point", mappedBy="author", cascade={"persist", "remove"})
  115.      */
  116.     private $points;
  117.     /**
  118.      * @ORM\Column(type="datetime", nullable=true)
  119.      */
  120.     private $isEmailConfirmDate;
  121.     /**
  122.      * @ORM\Column(type="string", length=255, nullable=true)
  123.      */
  124.     private $address2;
  125.     /**
  126.      * @ORM\Column(type="string", length=255, nullable=true)
  127.      */
  128.     private $country 'France';
  129.     /**
  130.      * @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="author", cascade={"persist"})
  131.      */
  132.     private $purchases;
  133.     /**
  134.      * @Assert\Iban(
  135.      *     message="L'IBAN renseigné est incorrect."
  136.      * )
  137.      * @ORM\Column(type="string", length=255, nullable=true)
  138.      *
  139.      */
  140.     private $iban;
  141.     /**
  142.      * @ORM\Column(type="boolean", nullable=true)
  143.      */
  144.     private $isNewsletter;
  145.     /**
  146.      * @ORM\Column(type="boolean", nullable=true)
  147.      */
  148.     private $isCgu;
  149.     /**
  150.      * @ORM\Column(type="datetime", nullable=true)
  151.      */
  152.     private $isCguDate;
  153.     /**
  154.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="author")
  155.      */
  156.     private $contacts;
  157.     /**
  158.      * @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="createdBy")
  159.      */
  160.     private $purchasesCreatedBy;
  161.     /**
  162.      * @ORM\Column(type="boolean", nullable=true)
  163.      */
  164.     private $isBlocked;
  165.     /**
  166.      * @ORM\Column(type="string", length=255, nullable=true)
  167.      */
  168.     private $doublonFirstNameLastName;
  169.     /**
  170.      * @ORM\Column(type="string", length=255, nullable=true)
  171.      */
  172.     private $allDoublonFirstNameLastName;
  173.     /**
  174.      * @ORM\Column(type="string", length=255, nullable=true)
  175.      */
  176.     private $doublonLastNameZipCode;
  177.     /**
  178.      * @ORM\Column(type="string", length=255, nullable=true)
  179.      */
  180.     private $AllDoublonLastNameZipCode;
  181.     /**
  182.      * @ORM\Column(type="datetime", nullable=true)
  183.      */
  184.     private $isBlockedDate;
  185.     /**
  186.      * @ORM\ManyToOne(targetEntity=Operation::class, inversedBy="users")
  187.      */
  188.     private $isBlockedOperation;
  189.     /**
  190.      * @ORM\Column(type="json")
  191.      */
  192.     private $roles = [];
  193.     
  194.     public function __construct()
  195.     {
  196.         $this->points = new ArrayCollection();
  197.         $this->purchases = new ArrayCollection();
  198.         $this->contacts = new ArrayCollection();
  199.         $this->purchasesCreatedBy = new ArrayCollection();
  200.         $this->purchases = new ArrayCollection();
  201.     }
  202.     public function getId(): ?int
  203.     {
  204.         return $this->id;
  205.     }
  206.     public function getEmail(): ?string
  207.     {
  208.         return $this->email;
  209.     }
  210.     public function setEmail(string $email): self
  211.     {
  212.         $this->email $email;
  213.         return $this;
  214.     }
  215.     /**
  216.      * A visual identifier that represents this user.
  217.      *
  218.      * @see UserInterface
  219.      */
  220.     public function getUsername(): string
  221.     {
  222.         return (string) $this->email;
  223.     }
  224.     /**
  225.      * @see UserInterface
  226.      */
  227.     public function getPassword(): string
  228.     {
  229.         return (string) $this->password;
  230.     }
  231.     public function setPassword(string $password): self
  232.     {
  233.         $this->password $password;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @see UserInterface
  238.      */
  239.     public function getSalt()
  240.     {
  241.         // not needed when using the "bcrypt" algorithm in security.yaml
  242.     }
  243.     /**
  244.      * @see UserInterface
  245.      */
  246.     public function eraseCredentials()
  247.     {
  248.         // If you store any temporary, sensitive data on the user, clear it here
  249.         // $this->plainPassword = null;
  250.     }
  251.     public function getGender(): ?int
  252.     {
  253.         return $this->gender;
  254.     }
  255.     public function setGender(int $gender): self
  256.     {
  257.         $this->gender $gender;
  258.         return $this;
  259.     }
  260.     public function getCivilite(): ?string
  261.     {
  262.         return $this->civilite;
  263.     }
  264.     public function setCivilite(string $civilite): self
  265.     {
  266.         $this->civilite $civilite;
  267.         return $this;
  268.     }
  269.     public function getFirstName(): ?string
  270.     {
  271.         return $this->firstName;
  272.     }
  273.     public function setFirstName(string $firstName): self
  274.     {
  275.         $this->firstName $firstName;
  276.         return $this;
  277.     }
  278.     public function getLastName(): ?string
  279.     {
  280.         return $this->lastName;
  281.     }
  282.     public function setLastName(string $lastName): self
  283.     {
  284.         $this->lastName $lastName;
  285.         return $this;
  286.     }
  287.     public function getAddress(): ?string
  288.     {
  289.         return $this->address;
  290.     }
  291.     public function setAddress(string $address): self
  292.     {
  293.         $this->address $address;
  294.         return $this;
  295.     }
  296.     public function getPostalCode(): ?string
  297.     {
  298.         return $this->postalCode;
  299.     }
  300.     public function setPostalCode(string $postalCode): self
  301.     {
  302.         $this->postalCode $postalCode;
  303.         return $this;
  304.     }
  305.     public function getCity(): ?string
  306.     {
  307.         return $this->city;
  308.     }
  309.     public function setCity(string $city): self
  310.     {
  311.         $this->city $city;
  312.         return $this;
  313.     }
  314.     public function getPhoneNumber(): ?string
  315.     {
  316.         return $this->phoneNumber;
  317.     }
  318.     public function setPhoneNumber(?string $phoneNumber): self
  319.     {
  320.         $this->phoneNumber $phoneNumber;
  321.         return $this;
  322.     }
  323.     public function getIsNewsletter(): ?bool
  324.     {
  325.         return $this->isNewsletter;
  326.     }
  327.     public function setIsNewsletter(bool $isNewsletter): self
  328.     {
  329.         $this->isNewsletter $isNewsletter;
  330.         return $this;
  331.     }
  332.     public function getIsNewsletterDate(): ?\DateTimeInterface
  333.     {
  334.         return $this->isNewsletterDate;
  335.     }
  336.     public function setIsNewsletterDate(?\DateTimeInterface $isNewsletterDate): self
  337.     {
  338.         $this->isNewsletterDate $isNewsletterDate;
  339.         return $this;
  340.     }
  341.     public function getIsCgu(): ?bool
  342.     {
  343.         return $this->isCgu;
  344.     }
  345.     public function setIsCgu(bool $isCgu): self
  346.     {
  347.         $this->isCgu $isCgu;
  348.         return $this;
  349.     }
  350.     public function getIsCguDate(): ?\DateTimeInterface
  351.     {
  352.         return $this->isCguDate;
  353.     }
  354.     public function setIsCguDate(?\DateTimeInterface $isCguDate): self
  355.     {
  356.         $this->isCguDate $isCguDate;
  357.         return $this;
  358.     }
  359.     public function getCreatedAt(): ?\DateTimeInterface
  360.     {
  361.         return $this->createdAt;
  362.     }
  363.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  364.     {
  365.         $this->createdAt $createdAt;
  366.         return $this;
  367.     }
  368.     public function getUpdatedAt(): ?\DateTimeInterface
  369.     {
  370.         return $this->updatedAt;
  371.     }
  372.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  373.     {
  374.         $this->updatedAt $updatedAt;
  375.         return $this;
  376.     }
  377.     public function getLastDateAction(): ?\DateTimeInterface
  378.     {
  379.         return $this->lastDateAction;
  380.     }
  381.     public function setLastDateAction(?\DateTimeInterface $lastDateAction): self
  382.     {
  383.         $this->lastDateAction $lastDateAction;
  384.         return $this;
  385.     }
  386.     public function getIsActive(): ?bool
  387.     {
  388.         return $this->isActive;
  389.     }
  390.     public function setIsActive(bool $isActive): self
  391.     {
  392.         $this->isActive $isActive;
  393.         return $this;
  394.     }
  395.     public function getResetToken(): ?string
  396.     {
  397.         return $this->resetToken;
  398.     }
  399.     public function setResetToken(?string $resetToken): self
  400.     {
  401.         $this->resetToken $resetToken;
  402.         return $this;
  403.     }
  404.     public function getBirthDate(): ?\DateTimeInterface
  405.     {
  406.         return $this->birthDate;
  407.     }
  408.     public function setBirthDate(?\DateTimeInterface $birthDate): self
  409.     {
  410.         $this->birthDate $birthDate;
  411.         return $this;
  412.     }
  413.     public function getIsEmailConfirm(): ?bool
  414.     {
  415.         return $this->isEmailConfirm;
  416.     }
  417.     public function setIsEmailConfirm(bool $isEmailConfirm): self
  418.     {
  419.         $this->isEmailConfirm $isEmailConfirm;
  420.         return $this;
  421.     }
  422.     public function getIsEmailConfirmDate(): ?\DateTimeInterface
  423.     {
  424.         return $this->isEmailConfirmDate;
  425.     }
  426.     public function setIsEmailConfirmDate(?\DateTimeInterface $isEmailConfirmDate): self
  427.     {
  428.         $this->isEmailConfirmDate $isEmailConfirmDate;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection|Point[]
  433.      */
  434.     public function getPoints(): Collection
  435.     {
  436.         return $this->points;
  437.     }
  438.     public function removePoint(Point $point): self
  439.     {
  440.         if ($this->points->contains($point)) {
  441.             $this->points->removeElement($point);
  442.             // set the owning side to null (unless already changed)
  443.             if ($point->getAuthor() === $this) {
  444.                 $point->setAuthor(null);
  445.             }
  446.         }
  447.         return $this;
  448.     }
  449.     public function getTotalPoints()
  450.     {
  451.         $total 0;
  452.         foreach ($this->points as $point) {
  453.             $total += $point->getValue();
  454.         }
  455.         return $total;
  456.     }
  457.     public function getTotalCreditPoints()
  458.     {
  459.         $total 0;
  460.         foreach ($this->points as $point) {
  461.             if ($point->getValue() > 0)
  462.                 $total += $point->getValue();
  463.         }
  464.         return $total;
  465.     }
  466.     public function getTotalDebitPoints()
  467.     {
  468.         $total 0;
  469.         foreach ($this->points as $point) {
  470.             if ($point->getValue() < 0)
  471.                 $total += $point->getValue();
  472.         }
  473.         return $total;
  474.     }
  475.     public function getAddress2(): ?string
  476.     {
  477.         return $this->address2;
  478.     }
  479.     public function setAddress2(?string $address2): self
  480.     {
  481.         $this->address2 $address2;
  482.         return $this;
  483.     }
  484.     public function getCountry(): ?string
  485.     {
  486.         return $this->country;
  487.     }
  488.     public function setCountry(string $country): self
  489.     {
  490.         $this->country $country;
  491.         return $this;
  492.     }
  493.     /**
  494.      * @return Collection|Purchase[]
  495.      */
  496.     public function getPurchases(): Collection
  497.     {
  498.         return $this->purchases;
  499.     }
  500.     public function addPurchase(Purchase $purchase): self
  501.     {
  502.         if (!$this->purchases->contains($purchase)) {
  503.             $this->purchases[] = $purchase;
  504.             //$purchase->setAuthor($this);
  505.         }
  506.         return $this;
  507.     }
  508.     public function removePurchase(Purchase $purchase): self
  509.     {
  510.         if ($this->purchases->contains($purchase)) {
  511.             $this->purchases->removeElement($purchase);
  512.             // set the owning side to null (unless already changed)
  513.             if ($purchase->getAuthor() === $this) {
  514.                 $purchase->setAuthor(null);
  515.             }
  516.         }
  517.         return $this;
  518.     }
  519.     public function getIban(): ?string
  520.     {
  521.         return $this->iban;
  522.     }
  523.     public function setIban(?string $iban): self
  524.     {
  525.         $this->iban $iban;
  526.         return $this;
  527.     }
  528.     /**
  529.      * @return Collection|Contact[]
  530.      */
  531.     public function getContacts(): Collection
  532.     {
  533.         return $this->contacts;
  534.     }
  535.     public function addContact(Contact $contact): self
  536.     {
  537.         if (!$this->contacts->contains($contact)) {
  538.             $this->contacts[] = $contact;
  539.             $contact->setAuthor($this);
  540.         }
  541.         return $this;
  542.     }
  543.     public function removeContact(Contact $contact): self
  544.     {
  545.         if ($this->contacts->removeElement($contact)) {
  546.             // set the owning side to null (unless already changed)
  547.             if ($contact->getAuthor() === $this) {
  548.                 $contact->setAuthor(null);
  549.             }
  550.         }
  551.         return $this;
  552.     }
  553.     /**
  554.      * @return Collection|Purchase[]
  555.      */
  556.     public function getPurchasesCreatedBy(): Collection
  557.     {
  558.         return $this->purchasesCreatedBy;
  559.     }
  560.     public function addPurchasesCreatedBy(Purchase $purchasesCreatedBy): self
  561.     {
  562.         if (!$this->purchasesCreatedBy->contains($purchasesCreatedBy)) {
  563.             $this->purchasesCreatedBy[] = $purchasesCreatedBy;
  564.             $purchasesCreatedBy->setCreatedBy($this);
  565.         }
  566.         return $this;
  567.     }
  568.     public function removePurchasesCreatedBy(Purchase $purchasesCreatedBy): self
  569.     {
  570.         if ($this->purchasesCreatedBy->removeElement($purchasesCreatedBy)) {
  571.             // set the owning side to null (unless already changed)
  572.             if ($purchasesCreatedBy->getCreatedBy() === $this) {
  573.                 $purchasesCreatedBy->setCreatedBy(null);
  574.             }
  575.         }
  576.         return $this;
  577.     }
  578.     public function getIsBlocked(): ?bool
  579.     {
  580.         return $this->isBlocked;
  581.     }
  582.     public function setIsBlocked(?bool $isBlocked): self
  583.     {
  584.         $this->isBlocked $isBlocked;
  585.         return $this;
  586.     }
  587.     /**
  588.      * @return Collection|Doublon[]
  589.      */
  590.     public function getDoublons(): Collection
  591.     {
  592.         return $this->doublons;
  593.     }
  594.     public function addDoublon(Doublon $doublon): self
  595.     {
  596.         if (!$this->doublons->contains($doublon)) {
  597.             $this->doublons[] = $doublon;
  598.             $doublon->setUser($this);
  599.         }
  600.         return $this;
  601.     }
  602.     public function removeDoublon(Doublon $doublon): self
  603.     {
  604.         if ($this->doublons->removeElement($doublon)) {
  605.             // set the owning side to null (unless already changed)
  606.             if ($doublon->getUser() === $this) {
  607.                 $doublon->setUser(null);
  608.             }
  609.         }
  610.         return $this;
  611.     }
  612.     public function getDoublonFirstNameLastName(): ?string
  613.     {
  614.         return $this->doublonFirstNameLastName;
  615.     }
  616.     public function setDoublonFirstNameLastName(?string $doublonFirstNameLastName): self
  617.     {
  618.         $this->doublonFirstNameLastName $doublonFirstNameLastName;
  619.         return $this;
  620.     }
  621.     public function getAllDoublonFirstNameLastName(): ?string
  622.     {
  623.         return $this->allDoublonFirstNameLastName;
  624.     }
  625.     public function setAllDoublonFirstNameLastName(?string $allDoublonFirstNameLastName): self
  626.     {
  627.         $this->allDoublonFirstNameLastName $allDoublonFirstNameLastName;
  628.         return $this;
  629.     }
  630.     public function getDoublonLastNameZipCode(): ?string
  631.     {
  632.         return $this->doublonLastNameZipCode;
  633.     }
  634.     public function setDoublonLastNameZipCode(?string $doublonLastNameZipCode): self
  635.     {
  636.         $this->doublonLastNameZipCode $doublonLastNameZipCode;
  637.         return $this;
  638.     }
  639.     public function getAllDoublonLastNameZipCode(): ?string
  640.     {
  641.         return $this->AllDoublonLastNameZipCode;
  642.     }
  643.     public function setAllDoublonLastNameZipCode(?string $AllDoublonLastNameZipCode): self
  644.     {
  645.         $this->AllDoublonLastNameZipCode $AllDoublonLastNameZipCode;
  646.         return $this;
  647.     }
  648.     public function getIsBlockedDate(): ?\DateTimeInterface
  649.     {
  650.         return $this->isBlockedDate;
  651.     }
  652.     public function setIsBlockedDate(?\DateTimeInterface $isBlockedDate): self
  653.     {
  654.         $this->isBlockedDate $isBlockedDate;
  655.         return $this;
  656.     }
  657.     public function getIsBlockedOperation(): ?Operation
  658.     {
  659.         return $this->isBlockedOperation;
  660.     }
  661.     public function setIsBlockedOperation(?Operation $isBlockedOperation): self
  662.     {
  663.         $this->isBlockedOperation $isBlockedOperation;
  664.         return $this;
  665.     }
  666.     /**
  667.      * The public representation of the user (e.g. a username, an email address, etc.)
  668.      *
  669.      * @see UserInterface
  670.      */
  671.     public function getUserIdentifier(): string
  672.     {
  673.         return (string) $this->email;
  674.     }
  675.     /**
  676.      * @see UserInterface
  677.      */
  678.     public function getRoles(): array
  679.     {
  680.         $roles $this->roles;
  681.         // guarantee every user at least has ROLE_USER
  682.         $roles[] = 'ROLE_USER';
  683.         return array_unique($roles);
  684.     }
  685.     public function setRoles(array $roles): self
  686.     {
  687.         $this->roles $roles;
  688.         return $this;
  689.     }
  690. }