<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @UniqueEntity(fields={"username"}, message="There is already an account with this username")
*/
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $username;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255)]
private $prenom;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $email;
#[ORM\Column(type: 'string', length: 255)]
private $mobile;
#[ORM\ManyToOne(targetEntity: Roles::class, inversedBy: 'users')]
#[ORM\JoinColumn(nullable: true)]
private $role;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Departement::class)]
private Collection $departements;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Departement $Departement = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'users')]
private ?self $Creepar = null;
#[ORM\OneToMany(mappedBy: 'Creepar', targetEntity: self::class)]
private Collection $users;
#[ORM\Column(nullable: true)]
private ?bool $Status = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Commande::class)]
private Collection $commandes;
#[ORM\Column(length: 255, nullable: true)]
private ?string $Service = null;
#[ORM\OneToMany(mappedBy: 'creePar', targetEntity: ReglementAchat::class)]
private Collection $reglementAchats;
#[ORM\OneToMany(mappedBy: 'creePar', targetEntity: ReglementCommande::class)]
private Collection $reglementCommandes;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: ReglementTransit::class)]
private Collection $reglementTransits;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Achat::class)]
private Collection $achats;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: DepenseCommande::class)]
private Collection $depenseCommandes;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Produit::class)]
private Collection $produits;
#[ORM\OneToMany(mappedBy: 'User', targetEntity: Client::class)]
private Collection $clients;
public function __construct()
{
$this->departements = new ArrayCollection();
$this->users = new ArrayCollection();
$this->commandes = new ArrayCollection();
$this->reglementAchats = new ArrayCollection();
$this->reglementCommandes = new ArrayCollection();
$this->reglementTransits = new ArrayCollection();
$this->achats = new ArrayCollection();
$this->depenseCommandes = new ArrayCollection();
$this->produits = new ArrayCollection();
$this->clients = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string)$this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->username;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getRole(): ?Roles
{
return $this->role;
}
public function setRole(?Roles $role): self
{
$this->role = $role;
return $this;
}
/**
* @return Collection<int, Departement>
*/
public function getDepartements(): Collection
{
return $this->departements;
}
public function addDepartement(Departement $departement): self
{
if (!$this->departements->contains($departement)) {
$this->departements->add($departement);
$departement->setUser($this);
}
return $this;
}
public function removeDepartement(Departement $departement): self
{
if ($this->departements->removeElement($departement)) {
// set the owning side to null (unless already changed)
if ($departement->getUser() === $this) {
$departement->setUser(null);
}
}
return $this;
}
public function getDepartement(): ?Departement
{
return $this->Departement;
}
public function setDepartement(?Departement $Departement): self
{
$this->Departement = $Departement;
return $this;
}
public function getCreepar(): ?self
{
return $this->Creepar;
}
public function setCreepar(?self $Creepar): self
{
$this->Creepar = $Creepar;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setCreepar($this);
}
return $this;
}
public function removeUser(self $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getCreepar() === $this) {
$user->setCreepar(null);
}
}
return $this;
}
public function isStatus(): ?bool
{
return $this->Status;
}
public function setStatus(?bool $Status): self
{
$this->Status = $Status;
return $this;
}
/**
* @return Collection<int, Commande>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commande $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes->add($commande);
$commande->setUser($this);
}
return $this;
}
public function removeCommande(Commande $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getUser() === $this) {
$commande->setUser(null);
}
}
return $this;
}
public function getService(): ?string
{
return $this->Service;
}
public function setService(?string $Service): self
{
$this->Service = $Service;
return $this;
}
/**
* @return Collection<int, ReglementAchat>
*/
public function getReglementAchats(): Collection
{
return $this->reglementAchats;
}
public function addReglementAchat(ReglementAchat $reglementAchat): self
{
if (!$this->reglementAchats->contains($reglementAchat)) {
$this->reglementAchats->add($reglementAchat);
$reglementAchat->setCreePar($this);
}
return $this;
}
public function removeReglementAchat(ReglementAchat $reglementAchat): self
{
if ($this->reglementAchats->removeElement($reglementAchat)) {
// set the owning side to null (unless already changed)
if ($reglementAchat->getCreePar() === $this) {
$reglementAchat->setCreePar(null);
}
}
return $this;
}
/**
* @return Collection<int, ReglementCommande>
*/
public function getReglementCommandes(): Collection
{
return $this->reglementCommandes;
}
public function addReglementCommande(ReglementCommande $reglementCommande): self
{
if (!$this->reglementCommandes->contains($reglementCommande)) {
$this->reglementCommandes->add($reglementCommande);
$reglementCommande->setCreePar($this);
}
return $this;
}
public function removeReglementCommande(ReglementCommande $reglementCommande): self
{
if ($this->reglementCommandes->removeElement($reglementCommande)) {
// set the owning side to null (unless already changed)
if ($reglementCommande->getCreePar() === $this) {
$reglementCommande->setCreePar(null);
}
}
return $this;
}
/**
* @return Collection<int, ReglementTransit>
*/
public function getReglementTransits(): Collection
{
return $this->reglementTransits;
}
public function addReglementTransit(ReglementTransit $reglementTransit): self
{
if (!$this->reglementTransits->contains($reglementTransit)) {
$this->reglementTransits->add($reglementTransit);
$reglementTransit->setUser($this);
}
return $this;
}
public function removeReglementTransit(ReglementTransit $reglementTransit): self
{
if ($this->reglementTransits->removeElement($reglementTransit)) {
// set the owning side to null (unless already changed)
if ($reglementTransit->getUser() === $this) {
$reglementTransit->setUser(null);
}
}
return $this;
}
public function getPermissionsList(): array
{
$permissions = [];
if ($this->getRole()) {
foreach ($this->getRole()->getRolePermissions() as $perm) {
$permissions[] = $perm->getPermission(); // Assure-toi que le nom correspond à ton entité
}
}
return $permissions;
}
public function getModulePermissions(): array
{
$modulePermissions = [];
if ($this->getRole()) {
foreach ($this->getRole()->getRolePermissions() as $perm) {
$module = $perm->getModule() ? strtoupper($perm->getModule()) : 'GENERAL';
$permission = strtoupper($perm->getPermission());
if (!isset($modulePermissions[$module])) {
$modulePermissions[$module] = [];
}
if (!in_array($permission, $modulePermissions[$module], true)) {
$modulePermissions[$module][] = $permission;
}
}
}
return $modulePermissions;
}
/**
* @return Collection<int, Achat>
*/
public function getAchats(): Collection
{
return $this->achats;
}
public function addAchat(Achat $achat): self
{
if (!$this->achats->contains($achat)) {
$this->achats->add($achat);
$achat->setUser($this);
}
return $this;
}
public function removeAchat(Achat $achat): self
{
if ($this->achats->removeElement($achat)) {
// set the owning side to null (unless already changed)
if ($achat->getUser() === $this) {
$achat->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, DepenseCommande>
*/
public function getDepenseCommandes(): Collection
{
return $this->depenseCommandes;
}
public function addDepenseCommande(DepenseCommande $depenseCommande): self
{
if (!$this->depenseCommandes->contains($depenseCommande)) {
$this->depenseCommandes->add($depenseCommande);
$depenseCommande->setUser($this);
}
return $this;
}
public function removeDepenseCommande(DepenseCommande $depenseCommande): self
{
if ($this->depenseCommandes->removeElement($depenseCommande)) {
// set the owning side to null (unless already changed)
if ($depenseCommande->getUser() === $this) {
$depenseCommande->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Produit>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produit $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits->add($produit);
$produit->setUser($this);
}
return $this;
}
public function removeProduit(Produit $produit): self
{
if ($this->produits->removeElement($produit)) {
// set the owning side to null (unless already changed)
if ($produit->getUser() === $this) {
$produit->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): self
{
if (!$this->clients->contains($client)) {
$this->clients->add($client);
$client->setUser($this);
}
return $this;
}
public function removeClient(Client $client): self
{
if ($this->clients->removeElement($client)) {
// set the owning side to null (unless already changed)
if ($client->getUser() === $this) {
$client->setUser(null);
}
}
return $this;
}
}