<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection; // pour les relations OneToMany
use Doctrine\Common\Collections\Collection; // pour les relations OneToMany
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use App\Repository\usrRepository;
#[ORM\Entity(repositoryClass: usrRepository::class)]
#[UniqueEntity(fields: ["username"], message: "Cet identifiant (login) ne peut pas être accepté (dbl)")]
#[UniqueEntity(fields: ["usremail"], ignoreNull: "usremail", message: "Cet E-mail ne peut pas être accepté (red)")]
#[ORM\Table(name: "usr", options: ["comment" => "Les utilisateurs"])]
class usr implements UserInterface, PasswordAuthenticatedUserInterface
{
public $daterange; // période dans rec
public $daterangeactif; // prise en compte période dans rec
public $usrpwdajo; // pour saisie pwd ajo
public $usrpwdmaj; // pour saisie pwd maj
public $usrpwdconf; // pour saisie pwd confirmation
public $usracccgu; // pour accept CGU ajo
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: "usrid", type: "integer", options: ["comment" => "Id utilisateur"])]
private ?int $usrid = null;
#[Assert\Length(
min: 10,
max: 20,
minMessage: "Votre identifiant (login) doit être composé de {{ limit }} caractères au minimum",
maxMessage: "Votre identifiant (login) doit être composé de {{ limit }} caractères au maximum"
)
]
#[ORM\Column(name: "username", type: "string", length: 20, unique: false, options: ["comment" => "Login utilisateur"])]
private $username = null;
#[ORM\Column(options: ["comment"=> "Les rôles du user"])]
private array $roles = [];
#[ORM\Column(name: "password", type: "string", length: 255, nullable: true, options: ["comment"=> "Mot de passe"])]
private $password = null;
#[Assert\NotBlank(message: "Le nom doit être obligatoirement renseigné")]
#[Assert\NotNull(message: "Le nom doit être obligatoirement renseigné")]
#[ORM\Column(name: "usrnom", type: "string", length: 50, nullable: false, options: ["comment"=> "Nom"])]
private $usrnom = null;
#[ORM\Column(name: "usrpre", type: "string", length: 30, nullable: false, options: ["comment"=> "Prénom"])]
private $usrpre = null;
#[ORM\Column(name: "usrorg", type: "string", length: 100, nullable: false, options: ["comment"=> "Organisme"])]
private $usrorg = null;
#[Assert\Email(message: "Cet e-mail n'est pas un e-mail valide")]
#[ORM\Column(name: "usremail", type: "string", length: 255, nullable: false, options: ["comment"=> "E-mail unique"])]
private $usremail = null;
#[Assert\Length(
exactly: 5,
exactMessage: "Le code postal doit être composé de {{ limit }} caractères numériques"
)
]
#[ORM\Column(name: "usrcodpos", type: "string", length: 5, nullable: false, options: ["comment"=> "Code postal"])]
private $usrcodpos = null;
#[ORM\Column(name: "usrstatut", type: "smallint", options: ["default" => 0, "comment"=> "Statut (0=attente, 1=validé, 2=bloqué)"])]
private $usrstatut = 0;
#[ORM\Column(name: "usrdatcre", type: "datetime", nullable: true, options: ["comment"=> "Date création du compte"])]
private $usrdatcre;
// ouverture de compte, vérif e-mail
#[ORM\Column(name: "usrmaictltok", type: "string", length: 255, nullable: true, options: ["comment"=> "CSRF token vérification e-mail ok"])]
private $usrmaictltok;
// ouverture de compte, temps (date) limite de vérification e-mail
#[ORM\Column(name: "usrmaictllim", type: "integer", nullable: true, options: ["comment"=> "Timestamp limite de vérification e-mail"])]
private $usrmaictllim;
// suivi login
#[ORM\Column(name: "usrdatlog", type: "datetime", nullable: true, options: ["comment"=> "Date dernière connexion (login)"])]
private $usrdatlog;
#[ORM\Column(name: "usrdatenvlog", type: "datetime", nullable: true, options: ["comment"=> "Date dernier renvoi identifiant (login)"])]
private $usrdatenvlog;
#[ORM\Column(name: "usrnbenvlog", type: "smallint", nullable: false, options: ["default"=>"0","comment"=> "Nb ddes renvoi de l'identifiant (login)"])]
private $usrnbenvlog = "0";
// demande changement de pwd (et création compte)
#[ORM\Column(name: "usrdatchgpwd", type: "datetime", nullable: true, options: ["comment"=> "Date dernier chgt PWD"])]
private $usrdatchgpwd;
#[ORM\Column(name: "usrdatenvchgpwd", type: "datetime", nullable: true, options: ["comment"=> "Date envoi mail dde chgt PWD"])]
private $usrdatenvchgpwd;
#[ORM\Column(name: "usrchgpwdtok", type: "string", length: 255, nullable: true, options: ["comment"=> "CSRF token dde chgt PWD"])]
private $usrchgpwdtok; // ex USRMAICTLTOK
#[ORM\Column(name: "usrdatddechgpwd", type: "integer", nullable: true, options: ["comment"=> "Timestamp dde chgt PWD"])]
private $usrdatddechgpwd;
#[ORM\Column(name: "usrnbenvpwd", type: "smallint", nullable: false, options: ["default"=>"0","comment"=> "Nb ddes changement de PWD"])]
private $usrnbenvpwd = "0";
// MANY TO ONE ======================
/** Catégorie d'appartenance du usr */
#[ORM\ManyToOne(targetEntity:"cat", inversedBy:"usrids", cascade:["persist"])]
#[ORM\JoinColumn(name:"catid", referencedColumnName:"catid", nullable:false)]
private $catid;
/** Profil du usr */
#[ORM\ManyToOne(targetEntity:"prf", inversedBy:"usrids", cascade:["persist"])]
#[ORM\JoinColumn(name:"prfid", referencedColumnName:"prfid", nullable:false)]
private $prfid;
// ONE TO MANY ======================
// PPI de l'utilisateur (version 2022)
#[ORM\OneToMany(mappedBy: 'usrid', targetEntity: PPI::class, orphanRemoval: true)]
private $ppiids;
// les CFPPI de l'utilisateur (version 2024)
#[ORM\OneToMany(mappedBy: 'usrid', targetEntity: CFPPI::class, orphanRemoval: true)]
private $CFPPIIDS;
// les CFPLA de l'utilisateur (Plan ou Programmation pluriannuelle d'investissement)
#[ORM\OneToMany(mappedBy: 'usrid', targetEntity: CFPLA::class, orphanRemoval: true)]
private $PLAIDS;
public function __construct()
{
//parent::__construct();
$this->ppiids = new ArrayCollection();
$this->CFPPIIDS = new ArrayCollection();
$this->PLAIDS = new ArrayCollection();
}
// ============== usr security & so ==========================
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): static
{
$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): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$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(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
// ============== FIN usr ELT ID ==========================
public function getUsrid(): ?int
{
return $this->usrid;
}
public function getUsrnom(): ?string
{
return $this->usrnom;
}
public function setUsrnom(string $usrnom): static
{
$this->usrnom = $usrnom;
return $this;
}
public function getUsrpre(): ?string
{
return $this->usrpre;
}
public function setUsrpre(?string $usrpre): static
{
$this->usrpre = $usrpre;
return $this;
}
public function getUsrorg(): ?string
{
return $this->usrorg;
}
public function setUsrorg(?string $usrorg): static
{
$this->usrorg = $usrorg;
return $this;
}
public function getUsremail(): ?string
{
return $this->usremail;
}
public function setUsremail(?string $usremail): static
{
$this->usremail = $usremail;
return $this;
}
public function getUsrcodpos(): ?string
{
return $this->usrcodpos;
}
public function setUsrcodpos(?string $usrcodpos): static
{
$this->usrcodpos = $usrcodpos;
return $this;
}
public function getUsrstatut(): ?int
{
return $this->usrstatut;
}
public function setUsrstatut(?int $usrstatut): static
{
$this->usrstatut = $usrstatut;
return $this;
}
public function getUsrdatcre(): ?\DateTimeInterface
{
return $this->usrdatcre;
}
public function setUsrdatcre(?\DateTimeInterface $usrdatcre): self
{
$this->usrdatcre = $usrdatcre;
return $this;
}
// lien de vérification e-mail suite ouverture de compte
public function getUsrmaictltok(): ?string
{
return $this->usrmaictltok;
}
public function setUsrmaictltok(?string $usrmaictltok): static
{
$this->usrmaictltok = $usrmaictltok;
return $this;
}
// Temps (timestamp) limite de vérification e-mail suite ouverture de compte
public function getUsrmaictllim(): ?int
{
return $this->usrmaictllim;
}
public function setUsrmaictllim(?int $usrmaictllim): static
{
$this->usrmaictllim = $usrmaictllim;
return $this;
}
// suivi login
public function getUsrdatlog(): ?\DateTimeInterface
{
return $this->usrdatlog;
}
public function setUsrdatlog(?\DateTimeInterface $usrdatlog): self
{
$this->usrdatlog = $usrdatlog;
return $this;
}
public function getUsrdatenvlog(): ?\DateTimeInterface
{
return $this->usrdatenvlog;
}
public function setUsrdatenvlog(?\DateTimeInterface $usrdatenvlog): self
{
$this->usrdatenvlog = $usrdatenvlog;
return $this;
}
public function getUsrnbenvlog(): ?int
{
return $this->usrnbenvlog;
}
public function setUsrnbenvlog(?int $usrnbenvlog): self
{
$this->usrnbenvlog = $usrnbenvlog;
return $this;
}
// demande changement de pwd
public function getUsrdatchgpwd(): ?\DateTimeInterface
{
return $this->usrdatchgpwd;
}
public function setUsrdatchgpwd(?\DateTimeInterface $usrdatchgpwd): self
{
$this->usrdatchgpwd = $usrdatchgpwd;
return $this;
}
public function getUsrdatenvchgpwd(): ?\DateTimeInterface
{
return $this->usrdatenvchgpwd;
}
public function setUsrdatenvchgpwd(?\DateTimeInterface $usrdatenvchgpwd): self
{
$this->usrdatenvchgpwd = $usrdatenvchgpwd;
return $this;
}
public function getUsrchgpwdtok(): ?string
{
return $this->usrchgpwdtok;
}
public function setUsrchgpwdtok(?string $usrchgpwdtok): static
{
$this->usrchgpwdtok = $usrchgpwdtok;
return $this;
}
public function getUsrdatddechgpwd(): ?int
{
return $this->usrdatddechgpwd;
}
public function setUsrdatddechgpwd(?int $usrdatddechgpwd): static
{
$this->usrdatddechgpwd = $usrdatddechgpwd;
return $this;
}
public function getUsrnbenvpwd(): ?int
{
return $this->usrnbenvpwd;
}
public function setUsrnbenvpwd(?int $usrnbenvpwd): static
{
$this->usrnbenvpwd = $usrnbenvpwd;
return $this;
}
/*
ManyToOne catégorie
*/
public function getCatid(): ?cat
{
return $this->catid;
}
public function setCatid(?cat $catid): static
{
$this->catid = $catid;
return $this;
}
/*
ManyToOne profil
*/
public function getPrfid(): ?prf
{
return $this->prfid;
}
public function setPrfid(?prf $prfid): static
{
$this->prfid = $prfid;
return $this;
}
/*
OneToMany ppi (validé!)
*/
public function getPpiids(): Collection
{
return $this->ppiids;
}
public function addPpiid(PPI $ppi): static
{
if(!$this->ppiids->contains($ppi)) {
$this->ppiids->add($ppi);
$ppi->setusrid($this);
}
return $this;
}
public function removePpiid(PPI $ppi): static
{
if ($this->ppiids->removeElement($ppi)) {
$this->ppiids->removeElement($ppi);
}
return $this;
}
/*
OneToMany CFPPI (validé!)
*/
public function getCFPPIIDS(): Collection
{
return $this->CFPPIIDS;
}
public function addCFPPID(CFPPI $cfppi): static
{
if(!$this->CFPPIIDS->contains($cfppi)) {
$this->CFPPIIDS->add($cfppi);
$cfppi->setusrid($this);
}
return $this;
}
public function removeCFPPIID(CFPPI $cfppi): static
{
if ($this->CFPPIIDS->removeElement($cfppi)) {
$this->CFPPIIDS->removeElement($cfppi);
}
return $this;
}
/*
OneToMany CFPLA (validé!)
*/
public function getPLAIDS(): Collection
{
return $this->PLAIDS;
}
public function addPLAID(CFPLA $cfpla): static
{
if(!$this->PLAIDS->contains($cfpla)) {
$this->PLAIDS->add($cfpla);
$cfpla->setusrid($this);
}
return $this;
}
public function removePLAID(CFPLA $cfpla): static
{
if ($this->PLAIDS->removeElement($cfpla)) {
$this->PLAIDS->removeElement($cfpla);
}
return $this;
}
}