src/Entity/User.php line 15

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. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column]
  21.     private array $roles = [];
  22.     /**
  23.      * @var string The hashed password
  24.      */
  25.     #[ORM\Column]
  26.     private ?string $password null;
  27.     #[ORM\Column(length50)]
  28.     private ?string $fullName null;
  29.     #[ORM\Column]
  30.     private ?\DateTimeImmutable $createdAt null;
  31.     
  32.     #[ORM\OneToMany(mappedBy'utilisateur'targetEntityEntreeStock::class)]
  33.     private Collection $entreeStocks;
  34.     #[ORM\OneToMany(mappedBy'utilisateur'targetEntitySortieStock::class)]
  35.     private Collection $sortieStocks;
  36.     #[ORM\OneToMany(mappedBy'utilisateur'targetEntityProduit::class)]
  37.     private Collection $produits;
  38.     #[ORM\Column(length255)]
  39.     private ?string $telephone null;
  40.     #[ORM\Column(length255)]
  41.     private ?string $adress null;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityActionLog::class)]
  43.     private Collection $actionLogs;
  44.     #[ORM\OneToOne(mappedBy'user'cascade: ['persist''remove'])]
  45.     private ?Livreur $livreur null;
  46.     #[ORM\ManyToOne(inversedBy'users')]
  47.     private ?Boutique $boutique null;
  48.     #[ORM\OneToOne(mappedBy'user'cascade: ['persist''remove'])]
  49.     private ?Employe $employe null;
  50.     public function __construct() {
  51.         $this->createdAt= new \DateTimeImmutable();
  52.         $this->entreeStocks = new ArrayCollection();
  53.         $this->sortieStocks = new ArrayCollection();
  54.         $this->produits = new ArrayCollection();
  55.         $this->actionLogs = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getEmail(): ?string
  62.     {
  63.         return $this->email;
  64.     }
  65.     public function setEmail(string $email): static
  66.     {
  67.         $this->email $email;
  68.         return $this;
  69.     }
  70.     /**
  71.      * A visual identifier that represents this user.
  72.      *
  73.      * @see UserInterface
  74.      */
  75.     public function getUserIdentifier(): string
  76.     {
  77.         return (string) $this->email;
  78.     }
  79.     /**
  80.      * @see UserInterface
  81.      */
  82.     public function getRoles(): array
  83.     {
  84.         $roles $this->roles;
  85.         // Garantir que chaque utilisateur a au moins ROLE_USER
  86.         $roles[] = 'ROLE_USER';
  87.         return array_unique($roles);
  88.     }
  89.     public function setRoles(array $roles): static
  90.     {
  91.         $this->roles $roles;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @see PasswordAuthenticatedUserInterface
  96.      */
  97.     public function getPassword(): string
  98.     {
  99.         return $this->password;
  100.     }
  101.     public function setPassword(string $password): static
  102.     {
  103.         $this->password $password;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @see UserInterface
  108.      */
  109.     public function eraseCredentials(): void
  110.     {
  111.         // If you store any temporary, sensitive data on the user, clear it here
  112.         // $this->plainPassword = null;
  113.     }
  114.     public function getFullName(): ?string
  115.     {
  116.         return $this->fullName;
  117.     }
  118.     public function setFullName(string $fullName): static
  119.     {
  120.         $this->fullName $fullName;
  121.         return $this;
  122.     }
  123.     public function getCreatedAt(): ?\DateTimeImmutable
  124.     {
  125.         return $this->createdAt;
  126.     }
  127.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  128.     {
  129.         $this->createdAt $createdAt;
  130.         return $this;
  131.     }
  132.    
  133.  
  134.     /**
  135.      * @return Collection<int, EntreeStock>
  136.      */
  137.     public function getEntreeStocks(): Collection
  138.     {
  139.         return $this->entreeStocks;
  140.     }
  141.     public function addEntreeStock(EntreeStock $entreeStock): static
  142.     {
  143.         if (!$this->entreeStocks->contains($entreeStock)) {
  144.             $this->entreeStocks->add($entreeStock);
  145.             $entreeStock->setUtilisateur($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeEntreeStock(EntreeStock $entreeStock): static
  150.     {
  151.         if ($this->entreeStocks->removeElement($entreeStock)) {
  152.             // set the owning side to null (unless already changed)
  153.             if ($entreeStock->getUtilisateur() === $this) {
  154.                 $entreeStock->setUtilisateur(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, SortieStock>
  161.      */
  162.     public function getSortieStocks(): Collection
  163.     {
  164.         return $this->sortieStocks;
  165.     }
  166.     public function addSortieStock(SortieStock $sortieStock): static
  167.     {
  168.         if (!$this->sortieStocks->contains($sortieStock)) {
  169.             $this->sortieStocks->add($sortieStock);
  170.             $sortieStock->setUtilisateur($this);
  171.         }
  172.         return $this;
  173.     }
  174.     public function removeSortieStock(SortieStock $sortieStock): static
  175.     {
  176.         if ($this->sortieStocks->removeElement($sortieStock)) {
  177.             // set the owning side to null (unless already changed)
  178.             if ($sortieStock->getUtilisateur() === $this) {
  179.                 $sortieStock->setUtilisateur(null);
  180.             }
  181.         }
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Collection<int, Produit>
  186.      */
  187.     public function getProduits(): Collection
  188.     {
  189.         return $this->produits;
  190.     }
  191.     public function addProduit(Produit $produit): static
  192.     {
  193.         if (!$this->produits->contains($produit)) {
  194.             $this->produits->add($produit);
  195.             $produit->setUtilisateur($this);
  196.         }
  197.         return $this;
  198.     }
  199.     public function removeProduit(Produit $produit): static
  200.     {
  201.         if ($this->produits->removeElement($produit)) {
  202.             // set the owning side to null (unless already changed)
  203.             if ($produit->getUtilisateur() === $this) {
  204.                 $produit->setUtilisateur(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209.   
  210.     public function getTelephone(): ?string
  211.     {
  212.         return $this->telephone;
  213.     }
  214.     public function setTelephone(string $telephone): static
  215.     {
  216.         $this->telephone $telephone;
  217.         return $this;
  218.     }
  219.     public function getAdress(): ?string
  220.     {
  221.         return $this->adress;
  222.     }
  223.     public function setAdress(string $adress): static
  224.     {
  225.         $this->adress $adress;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Collection<int, ActionLog>
  230.      */
  231.     public function getActionLogs(): Collection
  232.     {
  233.         return $this->actionLogs;
  234.     }
  235.     public function addActionLog(ActionLog $actionLog): static
  236.     {
  237.         if (!$this->actionLogs->contains($actionLog)) {
  238.             $this->actionLogs->add($actionLog);
  239.             $actionLog->setUser($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeActionLog(ActionLog $actionLog): static
  244.     {
  245.         if ($this->actionLogs->removeElement($actionLog)) {
  246.             // set the owning side to null (unless already changed)
  247.             if ($actionLog->getUser() === $this) {
  248.                 $actionLog->setUser(null);
  249.             }
  250.         }
  251.         return $this;
  252.     }
  253.     public function getLivreur(): ?Livreur
  254.     {
  255.         return $this->livreur;
  256.     }
  257.     public function setLivreur(Livreur $livreur): static
  258.     {
  259.         // set the owning side of the relation if necessary
  260.         if ($livreur->getUser() !== $this) {
  261.             $livreur->setUser($this);
  262.         }
  263.         $this->livreur $livreur;
  264.         return $this;
  265.     }
  266.     public function getBoutique(): ?Boutique
  267.     {
  268.         return $this->boutique;
  269.     }
  270.     public function setBoutique(?Boutique $boutique): static
  271.     {
  272.         $this->boutique $boutique;
  273.         return $this;
  274.     }
  275.     public function getEmploye(): ?Employe
  276.     {
  277.         return $this->employe;
  278.     }
  279.     public function setEmploye(?Employe $employe): static
  280.     {
  281.         // unset the owning side of the relation if necessary
  282.         if ($employe === null && $this->employe !== null) {
  283.             $this->employe->setUser(null);
  284.         }
  285.         // set the owning side of the relation if necessary
  286.         if ($employe !== null && $employe->getUser() !== $this) {
  287.             $employe->setUser($this);
  288.         }
  289.         $this->employe $employe;
  290.         return $this;
  291.     }
  292. }