<?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\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* User
*
* @UniqueEntity("username")
* @UniqueEntity("email")
* @ORM\Entity(repositoryClass=UserRepository::class)
* @Gedmo\Loggable
*/
class User implements UserInterface
{
/**
* @var int
*
* @ORM\Column(name="user_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $userId;
/**
* @var string
* @Gedmo\Versioned
* @ORM\Column(name="username", type="string", length=180, nullable=false, unique=true)
*/
private $username;
/**
* @var string
* @Gedmo\Versioned
*
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* @var string
* @Gedmo\Versioned
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
* @Assert\Email(
* message = "Email '{{ value }}' est invalide.",
* )
*/
private $email;
/**
* @var string
* @Gedmo\Versioned
* @Assert\Length(min = 8, max = 20, minMessage = "Numéro Téléphone invalide !", maxMessage = "Numéro Téléphone invalide !")
* @Assert\Regex(pattern="/(\+212|0)([ \-_]*)(\d[ \-_]*){9}/", message="Numéro Téléphone invalide !")
* @ORM\Column(name="tel", type="string", length=20, nullable=false)
*/
private $tel;
/**
* @var \DateTime
* @Gedmo\Versioned
*
* @ORM\Column(name="date_naissance", type="date", nullable=false)
* @Assert\LessThan("today")
*/
private $dateNaissance;
/**
* @var string
* @Gedmo\Versioned
*
* @ORM\Column(name="first_name", type="string", length=255, nullable=false)
*/
private $firstName;
/**
* @var string
* @Gedmo\Versioned
*
* @ORM\Column(name="last_name", type="string", length=255, nullable=false)
*/
private $lastName;
/**
* @ORM\Column(type="boolean")
* @Gedmo\Versioned
*/
private $isSalarie;
/**
* @Gedmo\Versioned
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $usernameCourt;
/**
* @var integer
*
* @ORM\Column(name="nbr_conncetion", type="integer", nullable=true)
*/
private $nbrConnection;
/**
* @var \DateTime
*
* @ORM\Column(name="last_connection", type="datetime", nullable=true)
*/
private $lastConnection;
/**
* @var \Doctrine\Common\Collections\Collection
* @Assert\Count(
* min = "1",
* minMessage = "Il faut séléctionner au moins un profil"
* )
* @ORM\ManyToMany(targetEntity="Profil", inversedBy="user")
* @ORM\JoinTable(name="lnk_user_profil",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="profil_id", referencedColumnName="profil_id")
* }
* )
*/
private $profil;
/**
* @ORM\OneToMany(targetEntity=TblMouvement::class, mappedBy="consommateur")
*/
private $mouvements;
/**
* @ORM\OneToMany(targetEntity=TblOperationVente::class, mappedBy="vendeur")
*/
private $tblOperationVentes;
public function __construct()
{
$this->profil = new ArrayCollection();
$this->mouvements = new ArrayCollection();
$this->tblOperationVentes = new ArrayCollection();
}
public function __toString()
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
public function getUserId(): ?int
{
return $this->userId;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* @return Collection<int, Profil>
*/
public function getProfil(): Collection
{
return $this->profil;
}
public function addProfil(Profil $profil): self
{
if (!$this->profil->contains($profil)) {
$this->profil[] = $profil;
}
return $this;
}
public function removeProfil(Profil $profil): self
{
$this->profil->removeElement($profil);
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = [];
foreach ($this->profil as $p) {
$roles[] = $p->getProfilSf();
}
return $roles;
}
public function hasRole($profilLib)
{
/** @var Profil $profil */
foreach ($this->profil as $profil) {
if ($profilLib == $profil->getProfilSf()) {
return true;
}
}
return false;
}
public function getProfilLibs()
{
$profilLibs = [];
foreach ($this->getProfil() as $profil) {
$profilLibs[] = (string) $profil;
}
return implode(", ", $profilLibs);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getDateNaissance(): ?\DateTimeInterface
{
return $this->dateNaissance;
}
public function setDateNaissance(\DateTimeInterface $dateNaissance): self
{
$this->dateNaissance = $dateNaissance;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function isisSalarie(): ?bool
{
return $this->isSalarie;
}
public function setisSalarie(bool $isSalarie): self
{
$this->isSalarie = $isSalarie;
return $this;
}
public function getUsernameCourt(): ?string
{
return $this->usernameCourt;
}
public function setUsernameCourt(?string $usernameCourt): self
{
$this->usernameCourt = $usernameCourt;
return $this;
}
public function getNbrConnection(): ?int
{
return $this->nbrConnection;
}
public function setNbrConnection(?int $nbrConnection): self
{
$this->nbrConnection = $nbrConnection;
return $this;
}
public function getLastConnection(): ?\DateTimeInterface
{
return $this->lastConnection;
}
public function setLastConnection(\DateTimeInterface $lastConnection): self
{
$this->lastConnection = $lastConnection;
return $this;
}
/**
* @return Collection<int, TblMouvement>
*/
public function getMouvements(): Collection
{
return $this->mouvements;
}
public function addMouvement(TblMouvement $mouvement): self
{
if (!$this->mouvements->contains($mouvement)) {
$this->mouvements[] = $mouvement;
$mouvement->setConsommateur($this);
}
return $this;
}
public function removeMouvement(TblMouvement $mouvement): self
{
if ($this->mouvements->removeElement($mouvement)) {
// set the owning side to null (unless already changed)
if ($mouvement->getConsommateur() === $this) {
$mouvement->setConsommateur(null);
}
}
return $this;
}
/**
* @return Collection<int, TblOperationVente>
*/
public function getTblOperationVentes(): Collection
{
return $this->tblOperationVentes;
}
public function addTblOperationVente(TblOperationVente $tblOperationVente): self
{
if (!$this->tblOperationVentes->contains($tblOperationVente)) {
$this->tblOperationVentes[] = $tblOperationVente;
$tblOperationVente->setVendeur($this);
}
return $this;
}
public function removeTblOperationVente(TblOperationVente $tblOperationVente): self
{
if ($this->tblOperationVentes->removeElement($tblOperationVente)) {
// set the owning side to null (unless already changed)
if ($tblOperationVente->getVendeur() === $this) {
$tblOperationVente->setVendeur(null);
}
}
return $this;
}
}