src/Entity/User.php line 24

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