src/Entity/User.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\MagasinUser;
  4. use ApiPlatform\Metadata\Get;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\UserRepository;
  7. use ApiPlatform\Metadata\ApiResource;
  8. // use ApiPlatform\Metadata\ApiResource;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. // use Symfony\Component\Serializer\Annotation\Groups;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  17. #[ORM\Entity(repositoryClassUserRepository::class)]
  18. #[ORM\Table(name'`user`')]
  19. #[ApiResource(security"is_granted('ROLE_USER')")]
  20. #[Get (normalizationContext: ['groups' => 'user:item'],security"is_granted('ROLE_USER')")]
  21. #[GetCollection(normalizationContext: ['groups' => 'user:list'])]
  22. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  23. // #[Put(security: "is_granted('ROLE_ADMIN') or object.owner == user")]
  24. // #[Post(security: "is_granted('ROLE_ADMIN')")]
  25.     
  26.     // operations: [
  27.     //     new Get(normalizationContext: ['groups' => 'user:item']),
  28.     //     new GetCollection(normalizationContext: ['groups' => 'user:list'])
  29.     // ],
  30.     // order: ['email' => 'DESC', 'role' => 'ASC'],
  31.     // paginationEnabled: false,
  32. class User implements UserInterfacePasswordAuthenticatedUserInterface
  33. {
  34.     #[ORM\Id]
  35.     #[ORM\GeneratedValue]
  36.     #[ORM\Column]
  37.     #[Groups(['user:list''user:item'])]
  38.     private ?int $id null;
  39.     #[ORM\Column(length180uniquetrue)]
  40.     #[Groups(['user:list''user:item'])]
  41.     private ?string $email null;
  42.     
  43.     #[ORM\Column]
  44.     #[Groups(['user:list''user:item'])]
  45.     private array $roles = [];
  46.     
  47.     /**
  48.      * @var string The hashed password
  49.      */
  50.     #[ORM\Column]
  51.     private ?string $password null;
  52.     #[ORM\Column(type'boolean')]
  53.     private $isVerified false;
  54.     #[ORM\Column(length50)]
  55.     private ?string $pseudo null;
  56.     // #[ORM\Column]
  57.     // private ?int $accept_cgv = null;
  58.     #[ORM\Column(type'boolean')]
  59.     private $accept_cgv false;
  60.     #[ORM\Column]
  61.     private ?int $accept_publication_promotion null;
  62.     #[ORM\Column(length500nullabletrue)]
  63.     private ?string $addresse null;
  64.     #[ORM\Column(length14nullabletrue)]
  65.     private ?string $num_telephone null;
  66.     #[ORM\Column(length255nullabletrue)]
  67.     private ?string $nomm null;
  68.     #[ORM\Column(length255nullabletrue)]
  69.     private ?string $prenom null;
  70.     #[ORM\OneToMany(mappedBy'user'targetEntityProduit::class, orphanRemovaltrue)]
  71.     private Collection $produits;
  72.     #[ORM\OneToMany(mappedBy'user'targetEntityCommande::class)]
  73.     private Collection $commandes;
  74.     #[ORM\OneToMany(mappedBy'user'targetEntityAddresse::class)]
  75.     private Collection $addresses;
  76.     #[ORM\ManyToOne(inversedBy'users')]
  77.     #[ORM\JoinColumn(nullablefalse)]
  78.     private ?PaymentT $paymentT null;
  79.     
  80.     #[ORM\OneToMany(mappedBy'created_by'targetEntityMagasinUser::class)]
  81.     private Collection $superadminlinkedmagasins;
  82.     #[ORM\OneToMany(mappedBy'user'targetEntityMagasinUser::class)]
  83.     private Collection $magasinsuser;
  84.     
  85.     public function __construct()
  86.     {
  87.         $this->produits = new ArrayCollection();
  88.         $this->commandes = new ArrayCollection();
  89.         $this->addresses = new ArrayCollection();
  90.         //$this->magasins magasins= new ArrayCollection();
  91.         $this->superadminlinkedmagasins = new ArrayCollection();
  92.         $this->magasinsuser = new ArrayCollection();
  93.     }
  94.     
  95.     public function getId(): ?int
  96.     {
  97.         return $this->id;
  98.     }
  99.     
  100.     public function getEmail(): ?string
  101.     {
  102.         return $this->email;
  103.     }
  104.     
  105.     public function setEmail(string $email): self
  106.     {
  107.         $this->email $email;
  108.         return $this;
  109.     }
  110.     /**
  111.      * A visual identifier that represents this user.
  112.      *
  113.      * @see UserInterface
  114.      */
  115.     public function getUserIdentifier(): string
  116.     {
  117.         return (string) $this->email;
  118.     }
  119.     /**
  120.      * @see UserInterface
  121.      */
  122.     public function getRoles(): array
  123.     {
  124.         $roles $this->roles;
  125.         // guarantee every user at least has ROLE_USER
  126.         $roles[] = 'ROLE_USER';
  127.         return array_unique($roles);
  128.     }
  129.     public function setRoles(array $roles): self
  130.     {
  131.         $this->roles $roles;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @see PasswordAuthenticatedUserInterface
  136.      */
  137.     public function getPassword(): string
  138.     {
  139.         return $this->password;
  140.     }
  141.     public function setPassword(string $password): self
  142.     {
  143.         $this->password $password;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @see UserInterface
  148.      */
  149.     public function eraseCredentials()
  150.     {
  151.         // If you store any temporary, sensitive data on the user, clear it here
  152.         // $this->plainPassword = null;
  153.     }
  154.     public function isVerified(): bool
  155.     {
  156.         return $this->isVerified;
  157.     }
  158.     public function setIsVerified(bool $isVerified): self
  159.     {
  160.         $this->isVerified $isVerified;
  161.         return $this;
  162.     }
  163.     public function getPseudo(): ?string
  164.     {
  165.         return $this->pseudo;
  166.     }
  167.     public function setPseudo(string $pseudo): self
  168.     {
  169.         $this->pseudo $pseudo;
  170.         return $this;
  171.     }
  172.     public function getAcceptCgv(): ?bool
  173.     {
  174.         return $this->accept_cgv;
  175.     }
  176.     public function setAcceptCgv(bool $accept_cgv): self
  177.     {
  178.         $this->accept_cgv $accept_cgv;
  179.         return $this;
  180.     }
  181.     public function getAcceptPublicationPromotion(): ?bool
  182.     {
  183.         return $this->accept_publication_promotion;
  184.     }
  185.     public function setAcceptPublicationPromotion(bool $accept_publication_promotion): self
  186.     {
  187.         $this->accept_publication_promotion $accept_publication_promotion;
  188.         return $this;
  189.     }
  190.     public function getAddresse(): ?string
  191.     {
  192.         return $this->addresse;
  193.     }
  194.     public function setAddresse(?string $addresse): self
  195.     {
  196.         $this->addresse $addresse;
  197.         return $this;
  198.     }
  199.     public function getNumTelephone(): ?string
  200.     {
  201.         return $this->num_telephone;
  202.     }
  203.     public function setNumTelephone(?string $num_telephone): self
  204.     {
  205.         $this->num_telephone $num_telephone;
  206.         return $this;
  207.     }
  208.     public function getNomm(): ?string
  209.     {
  210.         return $this->nomm;
  211.     }
  212.     public function setNomm(?string $nomm): self
  213.     {
  214.         $this->nomm $nomm;
  215.         return $this;
  216.     }
  217.     public function getPrenom(): ?string
  218.     {
  219.         return $this->prenom;
  220.     }
  221.     public function setPrenom(?string $prenom): self
  222.     {
  223.         $this->prenom $prenom;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection<int, Produit>
  228.      */
  229.     public function getProduits(): Collection
  230.     {
  231.         return $this->produits;
  232.     }
  233.     public function addProduit(Produit $produit): self
  234.     {
  235.         if (!$this->produits->contains($produit)) {
  236.             $this->produits->add($produit);
  237.             $produit->setUser($this);
  238.         }
  239.         return $this;
  240.     }
  241.     //orphane remove 
  242.     public function removeProduit(Produit $produit): self
  243.     {
  244.         if ($this->produits->removeElement($produit)) {
  245.             // set the owning side to null (unless already changed)
  246.             if ($produit->getUser() === $this) {
  247.                 $produit->setUser(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252.     /**
  253.      * @return Collection<int, Commande>
  254.      */
  255.     public function getCommandes(): Collection
  256.     {
  257.         return $this->commandes;
  258.     }
  259.     public function addCommande(Commande $commande): self
  260.     {
  261.         if (!$this->commandes->contains($commande)) {
  262.             $this->commandes->add($commande);
  263.             $commande->setUser($this);
  264.         }
  265.         return $this;
  266.     }
  267.     public function removeCommande(Commande $commande): self
  268.     {
  269.         if ($this->commandes->removeElement($commande)) {
  270.             // set the owning side to null (unless already changed)
  271.             if ($commande->getUser() === $this) {
  272.                 $commande->setUser(null);
  273.             }
  274.         }
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return Collection<int, addresse>
  279.      */
  280.     public function getAddresses(): Collection
  281.     {
  282.         return $this->addresses;
  283.     }
  284.     public function addAddress(Addresse $address): self
  285.     {
  286.         if (!$this->addresses->contains($address)) {
  287.             $this->addresses->add($address);
  288.             $address->setUser($this);
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeAddress(Addresse $address): self
  293.     {
  294.         if ($this->addresses->removeElement($address)) {
  295.             // set the owning side to null (unless already changed)
  296.             if ($address->getUser() === $this) {
  297.                 $address->setUser(null);
  298.             }
  299.         }
  300.         return $this;
  301.     }
  302.     public function getPaymentT(): ?PaymentT
  303.     {
  304.         return $this->paymentT;
  305.     }
  306.     public function setPaymentT(?PaymentT $paymentT): self
  307.     {
  308.         $this->paymentT $paymentT;
  309.         return $this;
  310.     }
  311.    
  312.     /**
  313.      * @return Collection<int, MagasinUser>
  314.      */
  315.     public function getSuperadminlinkedmagasins(): Collection
  316.     {
  317.         return $this->superadminlinkedmagasins;
  318.     }
  319.     public function addSuperadminlinkedmagasin(MagasinUser $superadminlinkedmagasin): static
  320.     {
  321.         if (!$this->superadminlinkedmagasins->contains($superadminlinkedmagasin)) {
  322.             $this->superadminlinkedmagasins->add($superadminlinkedmagasin);
  323.             $superadminlinkedmagasin->setCreatedBy($this);
  324.         }
  325.         return $this;
  326.     }
  327.     public function removeSuperadminlinkedmagasin(MagasinUser $superadminlinkedmagasin): static
  328.     {
  329.         if ($this->superadminlinkedmagasins->removeElement($superadminlinkedmagasin)) {
  330.             // set the owning side to null (unless already changed)
  331.             if ($superadminlinkedmagasin->getCreatedBy() === $this) {
  332.                 $superadminlinkedmagasin->setCreatedBy(null);
  333.             }
  334.         }
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return Collection<int, MagasinUser>
  339.      */
  340.     public function getMagasinsuser(): Collection
  341.     {
  342.         return $this->magasinsuser;
  343.     }
  344.     public function addMagasinsuser(MagasinUser $magasinsuser): static
  345.     {
  346.         if (!$this->magasinsuser->contains($magasinsuser)) {
  347.             $this->magasinsuser->add($magasinsuser);
  348.             $magasinsuser->setUser($this);
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeMagasinsuser(MagasinUser $magasinsuser): static
  353.     {
  354.         if ($this->magasinsuser->removeElement($magasinsuser)) {
  355.             // set the owning side to null (unless already changed)
  356.             if ($magasinsuser->getUser() === $this) {
  357.                 $magasinsuser->setUser(null);
  358.             }
  359.         }
  360.         return $this;
  361.     }
  362.     public function getLinkedMagasins(): array
  363.     {
  364.         return $this->magasinsuser
  365.             ->map(fn(MagasinUser $link) => $link->getMagasin())
  366.             ->filter(fn($magasin) => $magasin !== null)
  367.             ->toArray();
  368.     }
  369. }