<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'mstopeuser')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected ?int $id = null;
#[ORM\Column(name: 'passwordChangedAt',type: 'datetime', nullable: true)]
private ?\DateTimeInterface $passwordChangedAt = null;
// --- Champs de base FOSUserBundle (conservés pour la migration) ---
#[ORM\Column(length: 180, unique: true)]
protected ?string $username = null;
#[ORM\Column(length: 180, unique: true)]
protected ?string $usernameCanonical = null;
#[ORM\Column(length: 180, unique: true)]
protected ?string $email = null;
#[ORM\Column(length: 180, unique: true)]
protected ?string $emailCanonical = null;
#[ORM\Column(type: 'boolean')]
protected ?bool $enabled = null;
#[ORM\Column(length: 255)]
protected ?string $salt = null;
#[ORM\Column(length: 255)]
protected ?string $password = null;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTimeInterface $lastLogin = null;
#[ORM\Column(length: 255, nullable: true)]
protected ?string $confirmationToken = null;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTimeInterface $passwordRequestedAt = null;
#[ORM\Column(type: 'boolean')]
protected ?bool $locked = null;
#[ORM\Column(type: 'boolean')]
protected ?bool $expired = null;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTimeInterface $expiresAt = null;
#[ORM\Column(type: 'json')]
protected array $roles = [];
#[ORM\Column(type: 'boolean')]
protected ?bool $credentialsExpired = null;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTimeInterface $credentialsExpireAt = null;
// --- Tes champs personnalisés ---
#[ORM\ManyToOne(targetEntity: SupH::class)]
#[ORM\JoinColumn(name: 'supH_id',nullable: true)]
private ?SupH $supH = null;
#[ORM\OneToOne(targetEntity: ImageS::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'images_id',nullable: true)]
private ?ImageS $images = null;
#[ORM\ManyToOne(targetEntity: ReviewTec::class)]
#[ORM\JoinColumn(name: 'reviewtec_id',nullable: true)]
private ?ReviewTec $reviewtec = null;
#[ORM\ManyToOne(targetEntity: Approb::class)]
#[ORM\JoinColumn(name: 'approb_id',nullable: true)]
private ?Approb $approb = null;
#[ORM\Column(name: 'nom', length: 255)]
private ?string $nom = null;
#[ORM\Column(name: 'idsup', type: 'integer')]
private ?int $idsup = null;
#[ORM\Column(name: 'equipe', length: 255, nullable: true)]
private ?string $equipe = null;
#[ORM\Column(name: 'prenom', length: 255)]
private ?string $prenom = null;
#[ORM\Column(name: 'poste', length: 255, nullable: true)]
private ?string $poste = null;
#[ORM\Column(name: 'service', length: 255, nullable: true)]
private ?string $service = null;
#[ORM\Column(name: 'tel', nullable: true)]
private ?string $tel = null;
#[ORM\Column(name: 'zone', length: 50, nullable: true)]
private ?string $zone = null;
// --- Constructeur ---
public function __construct()
{
$this->enabled = false;
$this->locked = false;
$this->expired = false;
$this->roles = [];
$this->credentialsExpired = false;
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$this->roles = ['ROLE_USER'];
}
// --- Getters et setters ---
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getUserIdentifier(): string
{
return (string) $this->username;
}
public function getUsernameCanonical(): ?string
{
return $this->usernameCanonical;
}
public function setUsernameCanonical(string $usernameCanonical): self
{
$this->usernameCanonical = $usernameCanonical;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getEmailCanonical(): ?string
{
return $this->emailCanonical;
}
public function setEmailCanonical(string $emailCanonical): self
{
$this->emailCanonical = $emailCanonical;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getSalt(): ?string
{
return $this->salt;
}
public function setSalt(string $salt): self
{
$this->salt = $salt;
return $this;
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(?\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function getConfirmationToken(): ?string
{
return $this->confirmationToken;
}
public function setConfirmationToken(?string $confirmationToken): self
{
$this->confirmationToken = $confirmationToken;
return $this;
}
public function getPasswordRequestedAt(): ?\DateTimeInterface
{
return $this->passwordRequestedAt;
}
public function setPasswordRequestedAt(?\DateTimeInterface $passwordRequestedAt): self
{
$this->passwordRequestedAt = $passwordRequestedAt;
return $this;
}
public function isLocked(): ?bool
{
return $this->locked;
}
public function setLocked(bool $locked): self
{
$this->locked = $locked;
return $this;
}
public function isExpired(): ?bool
{
return $this->expired;
}
public function setExpired(bool $expired): self
{
$this->expired = $expired;
return $this;
}
public function getExpiresAt(): ?\DateTimeInterface
{
return $this->expiresAt;
}
public function setExpiresAt(?\DateTimeInterface $expiresAt): self
{
$this->expiresAt = $expiresAt;
return $this;
}
public function getRoles(): array
{
return array_unique(array_merge($this->roles, ['ROLE_USER']));
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function isCredentialsExpired(): ?bool
{
return $this->credentialsExpired;
}
public function setCredentialsExpired(bool $credentialsExpired): self
{
$this->credentialsExpired = $credentialsExpired;
return $this;
}
public function getCredentialsExpireAt(): ?\DateTimeInterface
{
return $this->credentialsExpireAt;
}
public function setCredentialsExpireAt(?\DateTimeInterface $credentialsExpireAt): self
{
$this->credentialsExpireAt = $credentialsExpireAt;
return $this;
}
public function getSupH(): ?SupH
{
return $this->supH;
}
public function setSupH(?SupH $supH): self
{
$this->supH = $supH;
return $this;
}
public function getImages(): ?ImageS
{
return $this->images;
}
public function setImages(?ImageS $images): self
{
$this->images = $images;
return $this;
}
public function getReviewtec(): ?ReviewTec
{
return $this->reviewtec;
}
public function setReviewtec(?ReviewTec $reviewtec): self
{
$this->reviewtec = $reviewtec;
return $this;
}
public function getApprob(): ?Approb
{
return $this->approb;
}
public function setApprob(?Approb $approb): self
{
$this->approb = $approb;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getIdsup(): ?int
{
return $this->idsup;
}
public function setIdsup(int $idsup): self
{
$this->idsup = $idsup;
return $this;
}
public function getEquipe(): ?string
{
return $this->equipe;
}
public function setEquipe(?string $equipe): self
{
$this->equipe = $equipe;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getPoste(): ?string
{
return $this->poste;
}
public function setPoste(?string $poste): self
{
$this->poste = $poste;
return $this;
}
public function getService(): ?string
{
return $this->service;
}
public function setService(?string $service): self
{
$this->service = $service;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(?string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getZone(): ?string
{
return $this->zone;
}
public function setZone(?string $zone): self
{
$this->zone = $zone;
return $this;
}
public function eraseCredentials()
{
// ...
}
public function getPasswordChangedAt(): ?\DateTimeInterface
{
return $this->passwordChangedAt;
}
public function setPasswordChangedAt(\DateTimeInterface $date): self
{
$this->passwordChangedAt = $date;
return $this;
}
#[ORM\Column(type: 'string', length: 5, nullable: true)]
private ?string $locale = 'fr';
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @param string $role
* @param RoleHierarchyInterface|null $roleHierarchy
* @return bool
*/
public function hasRole(string $role, ?RoleHierarchyInterface $roleHierarchy = null): bool
{
$grantedRoles = $this->getRoles();
if ($roleHierarchy) {
$grantedRoles = $roleHierarchy->getReachableRoles($grantedRoles);
}
return in_array($role, $grantedRoles, true);
}
public function removeRole(string $role): self
{
$this->roles = array_values(array_filter(
$this->roles,
fn($r) => $r !== $role
));
return $this;
}
public function __toString(): string
{
return $this->prenom . ' ' . $this->nom;
}
}