src/Entity/User.php line 19

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. /**
  11.  * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
  12.  */
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private $id;
  20.     #[ORM\Column(type'string'length180uniquetrue)]
  21.     private $username;
  22.     #[ORM\Column(type'json')]
  23.     private $roles = [];
  24.     #[ORM\Column(type'string')]
  25.     private $password;
  26.     #[ORM\Column(type'string'length255)]
  27.     private $name;
  28.     #[ORM\Column(type'string'length255)]
  29.     private $prenom;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     private $email;
  32.     #[ORM\Column(type'string'length255)]
  33.     private $mobile;
  34.     #[ORM\ManyToOne(targetEntityRoles::class, inversedBy'users')]
  35.     #[ORM\JoinColumn(nullabletrue)]
  36.     private $role;
  37.     #[ORM\OneToMany(mappedBy'User'targetEntityDepartement::class)]
  38.     private Collection $departements;
  39.     #[ORM\ManyToOne(inversedBy'users')]
  40.     private ?Departement $Departement null;
  41.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'users')]
  42.     private ?self $Creepar null;
  43.     #[ORM\OneToMany(mappedBy'Creepar'targetEntityself::class)]
  44.     private Collection $users;
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?bool $Status null;
  47.     #[ORM\OneToMany(mappedBy'user'targetEntityCommande::class)]
  48.     private Collection $commandes;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $Service null;
  51.     #[ORM\OneToMany(mappedBy'creePar'targetEntityReglementAchat::class)]
  52.     private Collection $reglementAchats;
  53.     #[ORM\OneToMany(mappedBy'creePar'targetEntityReglementCommande::class)]
  54.     private Collection $reglementCommandes;
  55.     #[ORM\OneToMany(mappedBy'User'targetEntityReglementTransit::class)]
  56.     private Collection $reglementTransits;
  57.     #[ORM\OneToMany(mappedBy'User'targetEntityAchat::class)]
  58.     private Collection $achats;
  59.     #[ORM\OneToMany(mappedBy'User'targetEntityDepenseCommande::class)]
  60.     private Collection $depenseCommandes;
  61.     #[ORM\OneToMany(mappedBy'User'targetEntityProduit::class)]
  62.     private Collection $produits;
  63.     #[ORM\OneToMany(mappedBy'User'targetEntityClient::class)]
  64.     private Collection $clients;
  65.     public function __construct()
  66.     {
  67.         $this->departements = new ArrayCollection();
  68.         $this->users = new ArrayCollection();
  69.         $this->commandes = new ArrayCollection();
  70.         $this->reglementAchats = new ArrayCollection();
  71.         $this->reglementCommandes = new ArrayCollection();
  72.         $this->reglementTransits = new ArrayCollection();
  73.         $this->achats = new ArrayCollection();
  74.         $this->depenseCommandes = new ArrayCollection();
  75.         $this->produits = new ArrayCollection();
  76.         $this->clients = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     /**
  83.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  84.      */
  85.     public function getUsername(): string
  86.     {
  87.         return (string)$this->username;
  88.     }
  89.     public function setUsername(string $username): self
  90.     {
  91.         $this->username $username;
  92.         return $this;
  93.     }
  94.     /**
  95.      * A visual identifier that represents this user.
  96.      *
  97.      * @see UserInterface
  98.      */
  99.     public function getUserIdentifier(): string
  100.     {
  101.         return (string)$this->username;
  102.     }
  103.     /**
  104.      * @see UserInterface
  105.      */
  106.     public function getRoles(): array
  107.     {
  108.         $roles $this->roles;
  109.         // guarantee every user at least has ROLE_USER
  110.         $roles[] = 'ROLE_USER';
  111.         return array_unique($roles);
  112.     }
  113.     public function setRoles(array $roles): self
  114.     {
  115.         $this->roles $roles;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @see PasswordAuthenticatedUserInterface
  120.      */
  121.     public function getPassword(): string
  122.     {
  123.         return $this->password;
  124.     }
  125.     public function setPassword(string $password): self
  126.     {
  127.         $this->password $password;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Returning a salt is only needed, if you are not using a modern
  132.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  133.      *
  134.      * @see UserInterface
  135.      */
  136.     public function getSalt(): ?string
  137.     {
  138.         return null;
  139.     }
  140.     /**
  141.      * @see UserInterface
  142.      */
  143.     public function eraseCredentials()
  144.     {
  145.         // If you store any temporary, sensitive data on the user, clear it here
  146.         // $this->plainPassword = null;
  147.     }
  148.     public function getName(): ?string
  149.     {
  150.         return $this->name;
  151.     }
  152.     public function setName(string $name): self
  153.     {
  154.         $this->name $name;
  155.         return $this;
  156.     }
  157.     public function getPrenom(): ?string
  158.     {
  159.         return $this->prenom;
  160.     }
  161.     public function setPrenom(string $prenom): self
  162.     {
  163.         $this->prenom $prenom;
  164.         return $this;
  165.     }
  166.     public function getEmail(): ?string
  167.     {
  168.         return $this->email;
  169.     }
  170.     public function setEmail(string $email): self
  171.     {
  172.         $this->email $email;
  173.         return $this;
  174.     }
  175.     public function getMobile(): ?string
  176.     {
  177.         return $this->mobile;
  178.     }
  179.     public function setMobile(string $mobile): self
  180.     {
  181.         $this->mobile $mobile;
  182.         return $this;
  183.     }
  184.     public function getRole(): ?Roles
  185.     {
  186.         return $this->role;
  187.     }
  188.     public function setRole(?Roles $role): self
  189.     {
  190.         $this->role $role;
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, Departement>
  195.      */
  196.     public function getDepartements(): Collection
  197.     {
  198.         return $this->departements;
  199.     }
  200.     public function addDepartement(Departement $departement): self
  201.     {
  202.         if (!$this->departements->contains($departement)) {
  203.             $this->departements->add($departement);
  204.             $departement->setUser($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeDepartement(Departement $departement): self
  209.     {
  210.         if ($this->departements->removeElement($departement)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($departement->getUser() === $this) {
  213.                 $departement->setUser(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getDepartement(): ?Departement
  219.     {
  220.         return $this->Departement;
  221.     }
  222.     public function setDepartement(?Departement $Departement): self
  223.     {
  224.         $this->Departement $Departement;
  225.         return $this;
  226.     }
  227.     public function getCreepar(): ?self
  228.     {
  229.         return $this->Creepar;
  230.     }
  231.     public function setCreepar(?self $Creepar): self
  232.     {
  233.         $this->Creepar $Creepar;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, self>
  238.      */
  239.     public function getUsers(): Collection
  240.     {
  241.         return $this->users;
  242.     }
  243.     public function addUser(self $user): self
  244.     {
  245.         if (!$this->users->contains($user)) {
  246.             $this->users->add($user);
  247.             $user->setCreepar($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeUser(self $user): self
  252.     {
  253.         if ($this->users->removeElement($user)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($user->getCreepar() === $this) {
  256.                 $user->setCreepar(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     public function isStatus(): ?bool
  262.     {
  263.         return $this->Status;
  264.     }
  265.     public function setStatus(?bool $Status): self
  266.     {
  267.         $this->Status $Status;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return Collection<int, Commande>
  272.      */
  273.     public function getCommandes(): Collection
  274.     {
  275.         return $this->commandes;
  276.     }
  277.     public function addCommande(Commande $commande): self
  278.     {
  279.         if (!$this->commandes->contains($commande)) {
  280.             $this->commandes->add($commande);
  281.             $commande->setUser($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeCommande(Commande $commande): self
  286.     {
  287.         if ($this->commandes->removeElement($commande)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($commande->getUser() === $this) {
  290.                 $commande->setUser(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     public function getService(): ?string
  296.     {
  297.         return $this->Service;
  298.     }
  299.     public function setService(?string $Service): self
  300.     {
  301.         $this->Service $Service;
  302.         return $this;
  303.     }
  304.     /**
  305.      * @return Collection<int, ReglementAchat>
  306.      */
  307.     public function getReglementAchats(): Collection
  308.     {
  309.         return $this->reglementAchats;
  310.     }
  311.     public function addReglementAchat(ReglementAchat $reglementAchat): self
  312.     {
  313.         if (!$this->reglementAchats->contains($reglementAchat)) {
  314.             $this->reglementAchats->add($reglementAchat);
  315.             $reglementAchat->setCreePar($this);
  316.         }
  317.         return $this;
  318.     }
  319.     public function removeReglementAchat(ReglementAchat $reglementAchat): self
  320.     {
  321.         if ($this->reglementAchats->removeElement($reglementAchat)) {
  322.             // set the owning side to null (unless already changed)
  323.             if ($reglementAchat->getCreePar() === $this) {
  324.                 $reglementAchat->setCreePar(null);
  325.             }
  326.         }
  327.         return $this;
  328.     }
  329.     /**
  330.      * @return Collection<int, ReglementCommande>
  331.      */
  332.     public function getReglementCommandes(): Collection
  333.     {
  334.         return $this->reglementCommandes;
  335.     }
  336.     public function addReglementCommande(ReglementCommande $reglementCommande): self
  337.     {
  338.         if (!$this->reglementCommandes->contains($reglementCommande)) {
  339.             $this->reglementCommandes->add($reglementCommande);
  340.             $reglementCommande->setCreePar($this);
  341.         }
  342.         return $this;
  343.     }
  344.     public function removeReglementCommande(ReglementCommande $reglementCommande): self
  345.     {
  346.         if ($this->reglementCommandes->removeElement($reglementCommande)) {
  347.             // set the owning side to null (unless already changed)
  348.             if ($reglementCommande->getCreePar() === $this) {
  349.                 $reglementCommande->setCreePar(null);
  350.             }
  351.         }
  352.         return $this;
  353.     }
  354.     /**
  355.      * @return Collection<int, ReglementTransit>
  356.      */
  357.     public function getReglementTransits(): Collection
  358.     {
  359.         return $this->reglementTransits;
  360.     }
  361.     public function addReglementTransit(ReglementTransit $reglementTransit): self
  362.     {
  363.         if (!$this->reglementTransits->contains($reglementTransit)) {
  364.             $this->reglementTransits->add($reglementTransit);
  365.             $reglementTransit->setUser($this);
  366.         }
  367.         return $this;
  368.     }
  369.     public function removeReglementTransit(ReglementTransit $reglementTransit): self
  370.     {
  371.         if ($this->reglementTransits->removeElement($reglementTransit)) {
  372.             // set the owning side to null (unless already changed)
  373.             if ($reglementTransit->getUser() === $this) {
  374.                 $reglementTransit->setUser(null);
  375.             }
  376.         }
  377.         return $this;
  378.     }
  379.     public function getPermissionsList(): array
  380. {
  381.     $permissions = [];
  382.     if ($this->getRole()) {
  383.         foreach ($this->getRole()->getRolePermissions() as $perm) {
  384.             $permissions[] = $perm->getPermission(); // Assure-toi que le nom correspond à ton entité
  385.         }
  386.     }
  387.     return $permissions;
  388. }
  389.     public function getModulePermissions(): array
  390. {
  391.     $modulePermissions = [];
  392.     if ($this->getRole()) {
  393.         foreach ($this->getRole()->getRolePermissions() as $perm) {
  394.             $module $perm->getModule() ? strtoupper($perm->getModule()) : 'GENERAL';
  395.             $permission strtoupper($perm->getPermission());
  396.             
  397.             if (!isset($modulePermissions[$module])) {
  398.                 $modulePermissions[$module] = [];
  399.             }
  400.             
  401.             if (!in_array($permission$modulePermissions[$module], true)) {
  402.                 $modulePermissions[$module][] = $permission;
  403.             }
  404.         }
  405.     }
  406.     return $modulePermissions;
  407. }
  408.     /**
  409.      * @return Collection<int, Achat>
  410.      */
  411.     public function getAchats(): Collection
  412.     {
  413.         return $this->achats;
  414.     }
  415.     public function addAchat(Achat $achat): self
  416.     {
  417.         if (!$this->achats->contains($achat)) {
  418.             $this->achats->add($achat);
  419.             $achat->setUser($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removeAchat(Achat $achat): self
  424.     {
  425.         if ($this->achats->removeElement($achat)) {
  426.             // set the owning side to null (unless already changed)
  427.             if ($achat->getUser() === $this) {
  428.                 $achat->setUser(null);
  429.             }
  430.         }
  431.         return $this;
  432.     }
  433.     /**
  434.      * @return Collection<int, DepenseCommande>
  435.      */
  436.     public function getDepenseCommandes(): Collection
  437.     {
  438.         return $this->depenseCommandes;
  439.     }
  440.     public function addDepenseCommande(DepenseCommande $depenseCommande): self
  441.     {
  442.         if (!$this->depenseCommandes->contains($depenseCommande)) {
  443.             $this->depenseCommandes->add($depenseCommande);
  444.             $depenseCommande->setUser($this);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeDepenseCommande(DepenseCommande $depenseCommande): self
  449.     {
  450.         if ($this->depenseCommandes->removeElement($depenseCommande)) {
  451.             // set the owning side to null (unless already changed)
  452.             if ($depenseCommande->getUser() === $this) {
  453.                 $depenseCommande->setUser(null);
  454.             }
  455.         }
  456.         return $this;
  457.     }
  458.     /**
  459.      * @return Collection<int, Produit>
  460.      */
  461.     public function getProduits(): Collection
  462.     {
  463.         return $this->produits;
  464.     }
  465.     public function addProduit(Produit $produit): self
  466.     {
  467.         if (!$this->produits->contains($produit)) {
  468.             $this->produits->add($produit);
  469.             $produit->setUser($this);
  470.         }
  471.         return $this;
  472.     }
  473.     public function removeProduit(Produit $produit): self
  474.     {
  475.         if ($this->produits->removeElement($produit)) {
  476.             // set the owning side to null (unless already changed)
  477.             if ($produit->getUser() === $this) {
  478.                 $produit->setUser(null);
  479.             }
  480.         }
  481.         return $this;
  482.     }
  483.     /**
  484.      * @return Collection<int, Client>
  485.      */
  486.     public function getClients(): Collection
  487.     {
  488.         return $this->clients;
  489.     }
  490.     public function addClient(Client $client): self
  491.     {
  492.         if (!$this->clients->contains($client)) {
  493.             $this->clients->add($client);
  494.             $client->setUser($this);
  495.         }
  496.         return $this;
  497.     }
  498.     public function removeClient(Client $client): self
  499.     {
  500.         if ($this->clients->removeElement($client)) {
  501.             // set the owning side to null (unless already changed)
  502.             if ($client->getUser() === $this) {
  503.                 $client->setUser(null);
  504.             }
  505.         }
  506.         return $this;
  507.     }
  508. }