src/Entity/User.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @method string getUserIdentifier()
  15.  * @UniqueEntity(fields={"email"}, message="Il semble que vous ayez déjà un compte")
  16.  * @UniqueEntity(fields={"Cin"}, message="Il semble que vous ayez déjà un compte avec ce CIN.")
  17.  */
  18. class User implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     const ROLE_CLIENT 'ROLE_CLIENT';
  21.     const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  22.     const ROLE_ADMIN 'ROLE_ADMIN';
  23.     /**
  24.      * @ORM\Id()
  25.      * @ORM\GeneratedValue()
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, unique=true  , nullable=true)
  31.      * @Assert\Email()
  32.      */
  33.     private $email;
  34.     /**
  35.      * @ORM\Column(type="json")
  36.      */
  37.     private $roles = [];
  38.     /**
  39.      * @var string The hashed password
  40.      * @ORM\Column(type="string", nullable=true)
  41.      */
  42.     private $password;
  43.     /**
  44.      * @var string The plain password
  45.      *
  46.      * @Assert\Length(
  47.      *     min=6,
  48.      *     allowEmptyString=true,
  49.      * )
  50.      */
  51.     private $plainPassword;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      * @Assert\Length(
  55.      *     max = 25,
  56.      *      maxMessage = "Le prénom ne peut pas dépasser {{ limit }} caractères"
  57.      * )
  58.      * @Assert\Regex(
  59.      *     pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
  60.      *     message="Le prénom doit contenir uniquement des lettres."
  61.      * )
  62.      */
  63.     private $firstName;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      * @Assert\Length(
  67.      *     max = 25,
  68.      *      maxMessage = "Le nom ne peut pas dépasser {{ limit }} caractères"
  69.      * )
  70.      * @Assert\Regex(
  71.      *     pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
  72.      *     message="Le nom doit contenir uniquement des lettres."
  73.      * )
  74.      */
  75.     private $lastName;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      */
  79.     private $mobile;
  80.     /**
  81.      * @ORM\Column(type="boolean", nullable=true)
  82.      */
  83.     private $annuler;
  84.     /**
  85.      * @ORM\Column(type="string", length=255 , unique=true )
  86.      */
  87.     private $Cin;
  88.     /**
  89.      * @ORM\Column(type="string", nullable=true)
  90.      * @Assert\Regex(
  91.      *     pattern="/^\d{24}$/",
  92.      *     message="Le RIB doit être composé de 24 chiffres.",
  93.      * )
  94.      */
  95.     private $rib;
  96.     /**
  97.      * @ORM\Column(type="string", length=255, nullable=true)
  98.      * @Assert\Length(
  99.      *     max = 25,
  100.      *      maxMessage = "La Banque  ne peut pas dépasser {{ limit }} caractères"
  101.      * )
  102.      * @Assert\Regex(
  103.      *     pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
  104.      *     message="Le Banque doit contenir uniquement des lettres."
  105.      * )
  106.      */
  107.     private $banque;
  108.     /**
  109.      * @ORM\Column(type="string", length=255, nullable=true)
  110.      * @Assert\Length(
  111.      *     max = 25,
  112.      *      maxMessage = "La Ville  ne peut pas dépasser {{ limit }} caractères"
  113.      * )
  114.      * @Assert\Regex(
  115.      *     pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
  116.      *     message="Le Ville doit contenir uniquement des lettres."
  117.      * )
  118.      */
  119.     private $ville;
  120.     /**
  121.      * @ORM\Column(type="string", length=10, nullable=true)
  122.      */
  123.     private $gendre;
  124.     /**
  125.      * @ORM\Column(type="date", nullable=true)
  126.      */
  127.     private $datenaissance;
  128.     /**
  129.      * @ORM\Column(type="string", length=255, nullable=true)
  130.      */
  131.     private $adresse;
  132.     /**
  133.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="users")
  134.      */
  135.     private $referral;
  136.     /**
  137.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="referral")
  138.      */
  139.     private $users;
  140.     /**
  141.      * @ORM\Column(type="string", length=255, nullable=true)
  142.      */
  143.     private $matrecul;
  144.     /**
  145.      * @ORM\Column(type="datetime",nullable=true))
  146.      */
  147.     private $dateaffiliate;
  148.     /**
  149.      * @ORM\Column(type="string", length=255,  nullable=true))
  150.      */
  151.     private $status;
  152.     /**
  153.      * @ORM\Column(type="string", length=255, nullable=true)
  154.      */
  155.     private $picture;
  156.     /**
  157.      * @ORM\OneToMany(targetEntity=Orders::class, mappedBy="user")
  158.      */
  159.     private $orders;
  160.     /**
  161.      * @ORM\OneToMany(targetEntity=Commission::class, mappedBy="user")
  162.      */
  163.     private $commissions;
  164.     /**
  165.      * @ORM\OneToMany(targetEntity=Bonus::class, mappedBy="user")
  166.      */
  167.     private $bonuses;
  168.     /**
  169.      * @ORM\OneToMany(targetEntity=Paiement::class, mappedBy="user")
  170.      */
  171.     private $paiements;
  172.     /**
  173.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  174.      */
  175.     private $Balance;
  176.     /**
  177.      * @ORM\OneToMany(targetEntity=UserGift::class, mappedBy="user")
  178.      */
  179.     private $userGifts;
  180.     /**
  181.      * @ORM\Column(type="string", length=255, nullable=true)
  182.      */
  183.     private $resetPasswordToken;
  184.     /**
  185.      * @ORM\Column(type="datetime", nullable=true)
  186.      */
  187.     private $resetPasswordTokenExpiresAt;
  188.     /**
  189.      * @ORM\OneToMany(targetEntity=PasswordResetRequest::class, mappedBy="user")
  190.      */
  191.     private $passwordResetRequests;
  192.     public function __construct()
  193.     {
  194.         $this->users = new ArrayCollection();
  195.         $this->orders = new ArrayCollection();
  196.         $this->commissions = new ArrayCollection();
  197.         $this->bonuses = new ArrayCollection();
  198.         $this->paiements = new ArrayCollection();
  199.         $this->userGifts = new ArrayCollection();
  200.         $this->passwordResetRequests = 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 getRoles(): array
  228.     {
  229.         $roles $this->roles;
  230.         // guarantee every user at least has ROLE_USER
  231.         $roles[] = self::ROLE_CLIENT;
  232.         return array_unique($roles);
  233.     }
  234.     public function setRoles(array $roles): self
  235.     {
  236.         $this->roles $roles;
  237.         return $this;
  238.     }
  239.     public function addRole(string $role): self
  240.     {
  241.         if (array_search($role$this->getRoles()) === FALSE)
  242.             $this->roles[] = $role;
  243.         return $this;
  244.     }
  245.     public function hasRole(string $role): bool
  246.     {
  247.         return array_search($role$this->getRoles()) !== FALSE;
  248.     }
  249.     /**
  250.      * @see UserInterface
  251.      */
  252.     public function getPassword(): string
  253.     {
  254.         return (string)$this->password;
  255.     }
  256.     public function setPassword(string $password): self
  257.     {
  258.         $this->password $password;
  259.         return $this;
  260.     }
  261.     public function getPlainPassword(): ?string
  262.     {
  263.         return $this->plainPassword;
  264.     }
  265.     public function setPlainPassword(string $plainPassword): self
  266.     {
  267.         $this->plainPassword $plainPassword;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @see UserInterface
  272.      */
  273.     public function getSalt()
  274.     {
  275.         // not needed when using the "bcrypt" algorithm in security.yaml
  276.     }
  277.     /**
  278.      * @see UserInterface
  279.      */
  280.     public function eraseCredentials()
  281.     {
  282.         // If you store any temporary, sensitive data on the user, clear it here
  283.         $this->plainPassword null;
  284.     }
  285.     public function getFirstName(): ?string
  286.     {
  287.         return $this->firstName;
  288.     }
  289.     public function setFirstName(string $firstName): self
  290.     {
  291.         $this->firstName $firstName;
  292.         return $this;
  293.     }
  294.     public function getLastName(): ?string
  295.     {
  296.         return $this->lastName;
  297.     }
  298.     public function setLastName(string $lastName): self
  299.     {
  300.         $this->lastName $lastName;
  301.         return $this;
  302.     }
  303.     public function getMobile(): ?string
  304.     {
  305.         return $this->mobile;
  306.     }
  307.     public function setMobile(?string $mobile): self
  308.     {
  309.         $this->mobile $mobile;
  310.         return $this;
  311.     }
  312.     public function stringRole()
  313.     {
  314.         $role 'Client';
  315.         if ($this->hasRole(self::ROLE_ADMIN)) {
  316.             $role 'Admin';
  317.         }elseif ($this->hasRole(self::ROLE_SUPER_ADMIN)) {
  318.             $role 'Super Admin';
  319.         }
  320.         return $role;
  321.     }
  322.     public function getStringRole(): string
  323. {
  324.     if ($this->hasRole(self::ROLE_ADMIN)) {
  325.         return 'Admin';
  326.     } elseif ($this->hasRole(self::ROLE_SUPER_ADMIN)) {
  327.         return 'Super Admin';
  328.     } elseif ($this->hasRole(self::ROLE_CLIENT)) {
  329.         return 'Client';
  330.     }
  331.     // Retour par défaut si aucun rôle ne correspond
  332.     return 'Unknown Role';
  333. }
  334.     public function getAnnuler(): ?bool
  335.     {
  336.         return $this->annuler;
  337.     }
  338.     public function setAnnuler(?bool $annuler): self
  339.     {
  340.         $this->annuler $annuler;
  341.         return $this;
  342.     }
  343.     public function isAnnuler(): ?bool
  344.     {
  345.         return $this->annuler;
  346.     }
  347.     public function getCin(): ?string
  348.     {
  349.         return $this->Cin;
  350.     }
  351.     public function setCin(string $Cin): self
  352.     {
  353.         $this->Cin $Cin;
  354.         return $this;
  355.     }
  356.     public function getBanque(): ?string
  357.     {
  358.         return $this->banque;
  359.     }
  360.     public function setBanque(?string $banque): self
  361.     {
  362.         $this->banque $banque;
  363.         return $this;
  364.     }
  365.     public function getVille(): ?string
  366.     {
  367.         return $this->ville;
  368.     }
  369.     public function setVille(?string $ville): self
  370.     {
  371.         $this->ville $ville;
  372.         return $this;
  373.     }
  374.     public function getGendre(): ?string
  375.     {
  376.         return $this->gendre;
  377.     }
  378.     public function setGendre(?string $gendre): self
  379.     {
  380.         $this->gendre $gendre;
  381.         return $this;
  382.     }
  383.     public function getDatenaissance(): ?\DateTimeInterface
  384.     {
  385.         return $this->datenaissance;
  386.     }
  387.     public function setDatenaissance(?\DateTimeInterface $datenaissance): self
  388.     {
  389.         $this->datenaissance $datenaissance;
  390.         return $this;
  391.     }
  392.     public function getAdresse(): ?string
  393.     {
  394.         return $this->adresse;
  395.     }
  396.     public function setAdresse(?string $adresse): self
  397.     {
  398.         $this->adresse $adresse;
  399.         return $this;
  400.     }
  401.     public function getReferral(): ?self
  402.     {
  403.         return $this->referral;
  404.     }
  405.     public function setReferral(?self $referral): self
  406.     {
  407.         $this->referral $referral;
  408.         return $this;
  409.     }
  410.     /**
  411.      * @return Collection<int, self>
  412.      */
  413.     public function getUsers(): Collection
  414.     {
  415.         return $this->users;
  416.     }
  417.     public function addUser(self $user): self
  418.     {
  419.         if (!$this->users->contains($user)) {
  420.             $this->users[] = $user;
  421.             $user->setReferral($this);
  422.         }
  423.         return $this;
  424.     }
  425.     public function removeUser(self $user): self
  426.     {
  427.         if ($this->users->removeElement($user)) {
  428.             // set the owning side to null (unless already changed)
  429.             if ($user->getReferral() === $this) {
  430.                 $user->setReferral(null);
  431.             }
  432.         }
  433.         return $this;
  434.     }
  435.     public function getMatrecul(): ?string
  436.     {
  437.         return $this->matrecul;
  438.     }
  439.     public function setMatrecul(?string $matrecul): self
  440.     {
  441.         $this->matrecul $matrecul;
  442.         return $this;
  443.     }
  444.     public function getDateaffiliate(): ?\DateTimeInterface
  445.     {
  446.         return $this->dateaffiliate;
  447.     }
  448.     public function setDateaffiliate(\DateTimeInterface $dateaffiliate): self
  449.     {
  450.         $this->dateaffiliate $dateaffiliate;
  451.         return $this;
  452.     }
  453.     public function getStatus(): ?string
  454.     {
  455.         return $this->status;
  456.     }
  457.     public function setStatus(string $status): self
  458.     {
  459.         $this->status $status;
  460.         return $this;
  461.     }
  462.     public function getPicture(): ?string
  463.     {
  464.         return $this->picture;
  465.     }
  466.     public function setPicture(?string $picture): self
  467.     {
  468.         $this->picture $picture;
  469.         return $this;
  470.     }
  471.     /**
  472.      * @return mixed
  473.      */
  474.     public function getRib()
  475.     {
  476.         return $this->rib;
  477.     }
  478.     /**
  479.      * @param mixed $rib
  480.      */
  481.     public function setRib($rib): void
  482.     {
  483.         $this->rib $rib;
  484.     }
  485.     /**
  486.      * @return Collection<int, Orders>
  487.      */
  488.     public function getOrders(): Collection
  489.     {
  490.         return $this->orders;
  491.     }
  492.     public function addOrder(Orders $order): self
  493.     {
  494.         if (!$this->orders->contains($order)) {
  495.             $this->orders[] = $order;
  496.             $order->setUser($this);
  497.         }
  498.         return $this;
  499.     }
  500.     public function removeOrder(Orders $order): self
  501.     {
  502.         if ($this->orders->removeElement($order)) {
  503.             // set the owning side to null (unless already changed)
  504.             if ($order->getUser() === $this) {
  505.                 $order->setUser(null);
  506.             }
  507.         }
  508.         return $this;
  509.     }
  510.     /**
  511.      * @return Collection<int, Commission>
  512.      */
  513.     public function getCommissions(): Collection
  514.     {
  515.         return $this->commissions;
  516.     }
  517.     public function addCommission(Commission $commission): self
  518.     {
  519.         if (!$this->commissions->contains($commission)) {
  520.             $this->commissions[] = $commission;
  521.             $commission->setUser($this);
  522.         }
  523.         return $this;
  524.     }
  525.     public function removeCommission(Commission $commission): self
  526.     {
  527.         if ($this->commissions->removeElement($commission)) {
  528.             // set the owning side to null (unless already changed)
  529.             if ($commission->getUser() === $this) {
  530.                 $commission->setUser(null);
  531.             }
  532.         }
  533.         return $this;
  534.     }
  535.     /**
  536.      * @return Collection<int, Bonus>
  537.      */
  538.     public function getBonuses(): Collection
  539.     {
  540.         return $this->bonuses;
  541.     }
  542.     public function addBonus(Bonus $bonus): self
  543.     {
  544.         if (!$this->bonuses->contains($bonus)) {
  545.             $this->bonuses[] = $bonus;
  546.             $bonus->setUser($this);
  547.         }
  548.         return $this;
  549.     }
  550.     public function removeBonus(Bonus $bonus): self
  551.     {
  552.         if ($this->bonuses->removeElement($bonus)) {
  553.             // set the owning side to null (unless already changed)
  554.             if ($bonus->getUser() === $this) {
  555.                 $bonus->setUser(null);
  556.             }
  557.         }
  558.         return $this;
  559.     }
  560.     /**
  561.      * @return Collection<int, Paiement>
  562.      */
  563.     public function getPaiements(): Collection
  564.     {
  565.         return $this->paiements;
  566.     }
  567.     public function addPaiement(Paiement $paiement): self
  568.     {
  569.         if (!$this->paiements->contains($paiement)) {
  570.             $this->paiements[] = $paiement;
  571.             $paiement->setUser($this);
  572.         }
  573.         return $this;
  574.     }
  575.     public function removePaiement(Paiement $paiement): self
  576.     {
  577.         if ($this->paiements->removeElement($paiement)) {
  578.             // set the owning side to null (unless already changed)
  579.             if ($paiement->getUser() === $this) {
  580.                 $paiement->setUser(null);
  581.             }
  582.         }
  583.         return $this;
  584.     }
  585.     public function getBalance(): ?string
  586.     {
  587.         return $this->Balance;
  588.     }
  589.     public function setBalance(?string $Balance): self
  590.     {
  591.         $this->Balance $Balance;
  592.         return $this;
  593.     }
  594.     /**
  595.      * @return Collection<int, UserGift>
  596.      */
  597.     public function getUserGifts(): Collection
  598.     {
  599.         return $this->userGifts;
  600.     }
  601.     public function addUserGift(UserGift $userGift): self
  602.     {
  603.         if (!$this->userGifts->contains($userGift)) {
  604.             $this->userGifts[] = $userGift;
  605.             $userGift->setUser($this);
  606.         }
  607.         return $this;
  608.     }
  609.     public function removeUserGift(UserGift $userGift): self
  610.     {
  611.         if ($this->userGifts->removeElement($userGift)) {
  612.             // set the owning side to null (unless already changed)
  613.             if ($userGift->getUser() === $this) {
  614.                 $userGift->setUser(null);
  615.             }
  616.         }
  617.         return $this;
  618.     }
  619.     public function getResetPasswordToken(): ?string
  620.     {
  621.         return $this->resetPasswordToken;
  622.     }
  623.     public function setResetPasswordToken(?string $resetPasswordToken): self
  624.     {
  625.         $this->resetPasswordToken $resetPasswordToken;
  626.         return $this;
  627.     }
  628.     public function getResetPasswordTokenExpiresAt(): ?\DateTimeInterface
  629.     {
  630.         return $this->resetPasswordTokenExpiresAt;
  631.     }
  632.     public function setResetPasswordTokenExpiresAt(?\DateTimeInterface $resetPasswordTokenExpiresAt): self
  633.     {
  634.         $this->resetPasswordTokenExpiresAt $resetPasswordTokenExpiresAt;
  635.         return $this;
  636.     }
  637.     /**
  638.      * @return Collection<int, PasswordResetRequest>
  639.      */
  640.     public function getPasswordResetRequests(): Collection
  641.     {
  642.         return $this->passwordResetRequests;
  643.     }
  644.     public function addPasswordResetRequest(PasswordResetRequest $passwordResetRequest): self
  645.     {
  646.         if (!$this->passwordResetRequests->contains($passwordResetRequest)) {
  647.             $this->passwordResetRequests[] = $passwordResetRequest;
  648.             $passwordResetRequest->setUser($this);
  649.         }
  650.         return $this;
  651.     }
  652.     public function removePasswordResetRequest(PasswordResetRequest $passwordResetRequest): self
  653.     {
  654.         if ($this->passwordResetRequests->removeElement($passwordResetRequest)) {
  655.             // set the owning side to null (unless already changed)
  656.             if ($passwordResetRequest->getUser() === $this) {
  657.                 $passwordResetRequest->setUser(null);
  658.             }
  659.         }
  660.         return $this;
  661.     }
  662. }