src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  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\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. /**
  14.  * @ORM\Entity(repositoryClass=UserRepository::class)
  15.  * @ORM\Table(name="`user`")
  16.  * @UniqueEntity(fields={"telephone"}, message="There is already an account with this telephone")
  17.  * @ApiResource(
  18.  * normalizationContext={"groups"={"user:read"}},
  19.  * denormalizationContext={"groups"={"user:write"}}
  20.  * )
  21.  */
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      * @Groups({"user:read"})
  29.      * @Groups({"commandes:read","produit:read"})
  30.      */
  31.     private $id;
  32.     /**
  33.      * @ORM\Column(type="string", length=180, unique=true)
  34.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  35.      */
  36.     private $telephone;
  37.     /**
  38.      * @ORM\Column(type="json")
  39.      * @Groups({"user:read","commandes:read","produit:read"})
  40.      */
  41.     private $roles = [];
  42.     /**
  43.      * @var string The hashed password
  44.      * @ORM\Column(type="string")
  45.      *
  46.      */
  47.     private $password;
  48.     /**
  49.      * @Groups("user:write")
  50.      * @SerializedName("password")
  51.      */
  52.     protected $plainPassword;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  56.      */
  57.     private $nom;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  61.      */
  62.     private $prenoms;
  63.     /**
  64.      * @ORM\Column(type="string", length=255, nullable=true)
  65.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  66.      */
  67.     private $email;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  71.      */
  72.     private $sexe;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      * @Groups({"user:read","produit:read","user:write"})
  76.      */
  77.     private $adresse;
  78.     /**
  79.      * @ORM\Column(type="string", length=255, nullable=true)
  80.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  81.      */
  82.     private $secteurActivite;
  83.     /**
  84.      * @ORM\Column(type="string", length=255, nullable=true)
  85.      * @Groups({"user:read","commandes:read","produit:read","user:write"})
  86.      */
  87.     private $terminal;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=Produits::class, mappedBy="utilisateur")
  90.      * @Groups({"user:read"})
  91.      */
  92.     private $produits;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Commandes::class, mappedBy="client")
  95.      *
  96.      */
  97.     private $commandes;
  98.     /**
  99.      * @ORM\OneToMany(targetEntity=AdresseLivraison::class, mappedBy="client")
  100.      *
  101.      */
  102.     private $adresseLivraisons;
  103.     /**
  104.      * @ORM\Column(type="boolean")
  105.      * @Groups({"user:read"})
  106.      */
  107.     private $isVerified false;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="utilisateur")
  110.      *
  111.      */
  112.     private $fcm_tokens;
  113.     /**
  114.      * @ORM\ManyToOne(targetEntity=Quartier::class, inversedBy="user")
  115.      * @Groups({"user:read","user:write"})
  116.      *
  117.      */
  118.     private $localite;
  119.     /**
  120.      * @Groups("user:read","user:write")
  121.      *
  122.      *
  123.      */
  124.     protected $localites;
  125.     /**
  126.      * @ORM\Column(type="string", length=255, nullable=true)
  127.      * @Groups({"user:read"})
  128.      */
  129.     private $fcm_token;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity=FavorisProduits::class, mappedBy="utilisateurs")
  132.      * @Groups({"user:read","favoris:read"})
  133.      */
  134.     private $favoris;
  135.     public function __construct()
  136.     {
  137.         $this->produits = new ArrayCollection();
  138.         $this->commandes = new ArrayCollection();
  139.         $this->adresseLivraisons = new ArrayCollection();
  140.         $this->fcm_tokens = new ArrayCollection();
  141.         $this->favoris = new ArrayCollection();
  142.     }
  143.     public function getId(): ?int
  144.     {
  145.         return $this->id;
  146.     }
  147.     public function getTelephone(): ?string
  148.     {
  149.         return $this->telephone;
  150.     }
  151.     public function setTelephone(string $telephone): self
  152.     {
  153.         $this->telephone $telephone;
  154.         return $this;
  155.     }
  156.     /**
  157.      * A visual identifier that represents this user.
  158.      *
  159.      * @see UserInterface
  160.      */
  161.     public function getUserIdentifier(): string
  162.     {
  163.         return (string)$this->nom;
  164.     }
  165.     /**
  166.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  167.      */
  168.     public function getUsername(): string
  169.     {
  170.         return (string)$this->telephone;
  171.     }
  172.     /**
  173.      * @see UserInterface
  174.      */
  175.     public function getRoles(): array
  176.     {
  177.         $roles $this->roles;
  178.         // guarantee every user at least has ROLE_USER
  179.         $roles[] = 'ROLE_USER';
  180.         return array_unique($roles);
  181.     }
  182.     public function setRoles(array $roles): self
  183.     {
  184.         $this->roles $roles;
  185.         return $this;
  186.     }
  187.     /**
  188.      * @see PasswordAuthenticatedUserInterface
  189.      */
  190.     public function getPassword(): string
  191.     {
  192.         return $this->password;
  193.     }
  194.     public function setPassword(string $password): self
  195.     {
  196.         $this->password $password;
  197.         return $this;
  198.     }
  199.     /**
  200.      * Returning a salt is only needed, if you are not using a modern
  201.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  202.      *
  203.      * @see UserInterface
  204.      */
  205.     public function getSalt(): ?string
  206.     {
  207.         return null;
  208.     }
  209.     /**
  210.      * @see UserInterface
  211.      */
  212.     public function eraseCredentials()
  213.     {
  214.         // If you store any temporary, sensitive data on the user, clear it here
  215.         // $this->plainPassword = null;
  216.     }
  217.     public function getNom(): ?string
  218.     {
  219.         return $this->nom;
  220.     }
  221.     public function setNom(?string $nom): self
  222.     {
  223.         $this->nom $nom;
  224.         return $this;
  225.     }
  226.     public function getPrenoms(): ?string
  227.     {
  228.         return $this->prenoms;
  229.     }
  230.     public function setPrenoms(?string $prenoms): self
  231.     {
  232.         $this->prenoms $prenoms;
  233.         return $this;
  234.     }
  235.     public function getEmail(): ?string
  236.     {
  237.         return $this->email;
  238.     }
  239.     public function setEmail(?string $email): self
  240.     {
  241.         $this->email $email;
  242.         return $this;
  243.     }
  244.     public function getSexe(): ?string
  245.     {
  246.         return $this->sexe;
  247.     }
  248.     public function setSexe(?string $sexe): self
  249.     {
  250.         $this->sexe $sexe;
  251.         return $this;
  252.     }
  253.     public function getAdresse(): ?string
  254.     {
  255.         return $this->adresse;
  256.     }
  257.     public function setAdresse(?string $adresse): self
  258.     {
  259.         $this->adresse $adresse;
  260.         return $this;
  261.     }
  262.     public function getSecteurActivite(): ?string
  263.     {
  264.         return $this->secteurActivite;
  265.     }
  266.     public function setSecteurActivite(?string $secteurActivite): self
  267.     {
  268.         $this->secteurActivite $secteurActivite;
  269.         return $this;
  270.     }
  271.     public function getTerminal(): ?string
  272.     {
  273.         return $this->terminal;
  274.     }
  275.     public function setTerminal(?string $terminal): self
  276.     {
  277.         $this->terminal $terminal;
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection<int, Produits>
  282.      */
  283.     public function getProduits(): Collection
  284.     {
  285.         return $this->produits;
  286.     }
  287.     public function addProduit(Produits $produit): self
  288.     {
  289.         if (!$this->produits->contains($produit)) {
  290.             $this->produits[] = $produit;
  291.             $produit->setUtilisateur($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeProduit(Produits $produit): self
  296.     {
  297.         if ($this->produits->removeElement($produit)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($produit->getUtilisateur() === $this) {
  300.                 $produit->setUtilisateur(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     /**
  306.      * @return Collection<int, Commandes>
  307.      */
  308.     public function getCommandes(): Collection
  309.     {
  310.         return $this->commandes;
  311.     }
  312.     public function addCommande(Commandes $commande): self
  313.     {
  314.         if (!$this->commandes->contains($commande)) {
  315.             $this->commandes[] = $commande;
  316.             $commande->setClient($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeCommande(Commandes $commande): self
  321.     {
  322.         if ($this->commandes->removeElement($commande)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($commande->getClient() === $this) {
  325.                 $commande->setClient(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return Collection<int, AdresseLivraison>
  332.      */
  333.     public function getAdresseLivraisons(): Collection
  334.     {
  335.         return $this->adresseLivraisons;
  336.     }
  337.     public function addAdresseLivraison(AdresseLivraison $adresseLivraison): self
  338.     {
  339.         if (!$this->adresseLivraisons->contains($adresseLivraison)) {
  340.             $this->adresseLivraisons[] = $adresseLivraison;
  341.             $adresseLivraison->setClient($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeAdresseLivraison(AdresseLivraison $adresseLivraison): self
  346.     {
  347.         if ($this->adresseLivraisons->removeElement($adresseLivraison)) {
  348.             // set the owning side to null (unless already changed)
  349.             if ($adresseLivraison->getClient() === $this) {
  350.                 $adresseLivraison->setClient(null);
  351.             }
  352.         }
  353.         return $this;
  354.     }
  355.     public function isVerified(): bool
  356.     {
  357.         return $this->isVerified;
  358.     }
  359.     public function setIsVerified(bool $isVerified): self
  360.     {
  361.         $this->isVerified $isVerified;
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection<int, ApiToken>
  366.      */
  367.     public function getFcmTokens(): Collection
  368.     {
  369.         return $this->fcm_tokens;
  370.     }
  371.     public function addFcmTokens(ApiToken $fcmTokens): self
  372.     {
  373.         if (!$this->fcm_tokens->contains($fcmTokens)) {
  374.             $this->fcm_tokens[] = $fcmTokens;
  375.             $fcmTokens->setUtilisateur($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeFcmTokens(ApiToken $fcmTokens): self
  380.     {
  381.         if ($this->fcm_token->removeElement($fcmTokens)) {
  382.             // set the owning side to null (unless already changed)
  383.             if ($fcmTokens->getUtilisateur() === $this) {
  384.                 $fcmTokens->setUtilisateur(null);
  385.             }
  386.         }
  387.         return $this;
  388.     }
  389.     /**
  390.      * @return mixed
  391.      */
  392.     public function getPlainPassword()
  393.     {
  394.         return $this->plainPassword;
  395.     }
  396.     /**
  397.      * @param mixed $plainPassword
  398.      */
  399.     public function setPlainPassword($plainPassword): void
  400.     {
  401.         $this->plainPassword $plainPassword;
  402.     }
  403.     public function isIsVerified(): ?bool
  404.     {
  405.         return $this->isVerified;
  406.     }
  407.     public function getLocalite()
  408.     {
  409.        return $this->localite;
  410.     }
  411. //    /**
  412. //     *  @Groups({"user:read"})
  413. //     */
  414. //    public function getLocalites():?Quartier
  415. //    {
  416. //
  417. //        return $this->localite;
  418. //    }
  419.     public function setLocalite(?Quartier $localite): self
  420.     {
  421.         $this->localite $localite;
  422.         return $this;
  423.     }
  424.     public function getFcmToken(): ?string
  425.     {
  426.         return $this->fcm_token;
  427.     }
  428.     public function setFcmToken(?string $fcm_token): self
  429.     {
  430.         $this->fcm_token $fcm_token;
  431.         return $this;
  432.     }
  433.     /**
  434.      * @return Collection<int, FavorisProduits>
  435.      */
  436.     public function getFavoris(): Collection
  437.     {
  438.         return $this->favoris;
  439.     }
  440.     public function addFavori(FavorisProduits $favori): self
  441.     {
  442.         if (!$this->favoris->contains($favori)) {
  443.             $this->favoris[] = $favori;
  444.             $favori->setUtilisateurs($this);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeFavori(FavorisProduits $favori): self
  449.     {
  450.         if ($this->favoris->removeElement($favori)) {
  451.             // set the owning side to null (unless already changed)
  452.             if ($favori->getUtilisateurs() === $this) {
  453.                 $favori->setUtilisateurs(null);
  454.             }
  455.         }
  456.         return $this;
  457.     }
  458. }