<?php
namespace App\Entity;
use App\Repository\UserRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'users')]
#[UniqueEntity(fields: ['email'], message: 'Cet email est déjà utilisé !')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
//---------------------------------- ID ----------------------------------------------------//
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id', type: 'integer', options: ['unsigned' => true])]
private ?int $id = null;
//---------------------------------- EMAIL ----------------------------------------------------//
#[Assert\NotBlank(message: 'L\'email est obligatoire !')]
#[Assert\Regex(
pattern: '/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/',
message: 'Le format de l\'email n\'est pas valide!',)]
#[ORM\Column(name: 'email', type: 'string', length: 180, unique: true)]
private ?string $email = null;
//---------------------------------- SOCIETE ----------------------------------------------------//
#[Assert\NotBlank(message: 'Le nom de la socièté est obligatoire!')]
#[ORM\Column(name: 'societe', type: 'string', length: 100)]
private ?string $societe = null;
//---------------------------------- TELEPHONE (FIXE) -------------------------------------------//
#[Assert\NotBlank(message: 'Le numéro de téléphone est obligatoire !')]
#[Assert\Regex(pattern: '/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
message: 'Le format du numéro de téléphone n\'est pas valide!')]
#[Assert\Length(
max: 20,
maxMessage: 'Le numéro de téléphone doit faire au maximun {{ limit }} caractères ! pas plus'
)]
#[ORM\Column(name: 'telephone', type: 'string', length: 20)]
private ?string $telephone = null;
//---------------------------------- FAX ----------------------------------------------------//
#[Assert\NotBlank(message: 'Le numéro de fax est obligatoire !')]
#[Assert\Regex('/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
message: 'Le format du numéro de fax n\'est pas valide!')]
#[ORM\Column(name: 'fax', type: 'string', length: 20)]
private ?string $fax = null;
//---------------------------------- PORTABLE ----------------------------------------------------//
#[Assert\Regex(pattern: '/\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/',
message: 'Le format du numéro de téléphone portable n\'est pas valide!')]
#[Assert\Length(
max: 20,
maxMessage: 'Le numéro de portable doit faire au maximum {{ limit }} caractères !',
)]
#[ORM\Column(name: 'portable', type: 'integer', length: 15, nullable: true)]
private ?int $telephonePortable = null;
//---------------------------------- PRENOM ----------------------------------------------------//
#[Assert\NotBlank(message: 'Le prénom est obligatoire !')]
#[Assert\Regex(
pattern: '/\d/',
message: 'Votre prénom ne doit pas contenir de chiffres !',
match: false,
)]
#[Assert\Length(
min: 2, max: 100,
minMessage: 'Le prénom doit faire au min {{ limit }} caractères !',
maxMessage: 'Le prénom doit faire au max {{ limit }} caractères !'
)]
#[ORM\Column(name: 'prenom', type: 'string', length: 120)]
private ?string $prenom = null;
//---------------------------------- NOM ----------------------------------------------------//
#[Assert\NotBlank(message: 'Le nom est obligatoire !')]
#[Assert\Regex(
pattern: '/\d/',
message: 'Votre nom ne doit pas contenir de chiffres !',
match: false,
)]
#[Assert\Length(
min: 2, max: 100,
minMessage: 'Le nom doit faire au minimum {{ limit }} caractères !',
maxMessage: 'Le nom doit faire au maximum {{ limit }} caractères !'
)]
#[ORM\Column(name: 'nom', type: 'string', length: 120)]
private ?string $nom = null;
//---------------------------------- FONCTION ----------------------------------------------------//
#[Assert\NotBlank(message: 'Votre fonction est obligatoire !')]
#[ORM\Column(name: 'fonction', type: 'string', length: 120)]
private ?string $profession = null;
//---------------------------------- MOT DE PASSE ----------------------------------------------------//
/**
* @var string The hashed password
*/
#[Assert\NotBlank(message: 'Un mot de passe est obligatoire')]
#[Assert\Regex(
pattern: '/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!"#$%&()*+,-.\/:;<=>?@^_`{|}~]).{8,}$/',
message: 'Le mot de passe doit contenir au moins 8 caractères et être composé d\'au moins :
un chiffre, une minuscule, une majuscule et d\'un caractère spécial " !"#$%&()*+,-.\/:;<=>?@^_`{|}~ "!')]
#[ORM\Column(name: 'mot_passe',type: 'string')]
private string $password;
// Champs suplementaire (non visible sur le formulaire)
//---------------------------------- ROLES (GESTION DES ACCES) ----------------------------------------------------//
#[ORM\Column]
private array $roles = [];
//---------------------------------- COMPTE ACTIF ----------------------------------------------------//
#[ORM\Column (name: 'compte_active', type: 'boolean')]
private ?bool $compteActive = null;
//---------------------------------- DATE D'INSCRIPTION ----------------------------------------------------//
#[ORM\Column(name: 'date_inscription', type: 'datetime')]
private ?datetime $dateInscription = null;
//---------------------------------- DATE DE DERNIERE CONNEXION --------------------------------------------//
#[ORM\Column(name: 'date_der_connexion',type: 'datetime')]
private ?datetime $dateDerConnexion = null;
///---------------------------------- COMPTE VERIFIE (MAIL) --------------------------------------------//
#[ORM\Column(type: 'boolean')]
private bool $isVerified = false;
//-----------------------------------------------------------------------------------------//
//---------------------------------------- RELATIONS --------------------------------------//
//---- type d'adherent----//
#[ORM\ManyToOne(inversedBy: 'users')]
private ?TypeAdherent $typeAdherent = null;
//---- adresse----//
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?Adresse $adresse = null;
//---- groupes ----//
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Groupe::class)]
private Collection $groupes;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Vehicule::class)]
private Collection $vehicules;
public function __construct()
{
$this->groupes = new ArrayCollection();
$this->vehicules = new ArrayCollection();
}
public function __toString(): string
{
return $this->societe;
}
//------------------------------------------------------------------------------------------------------------//
//------------------------------------------ GETTER SETTER----------------------------------------------------//
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getSociete(): ?string
{
return $this->societe;
}
/**
* @param string|null $societe
*/
public function setSociete(?string $societe): void
{
$this->societe = $societe;
}
/**
* @return string|null
*/
public function getTelephone(): ?string
{
return $this->telephone;
}
/**
* @param string|null $telephone
*/
public function setTelephone(?string $telephone): void
{
$this->telephone = $telephone;
}
/**
* @return string|null
*/
public function getFax(): ?string
{
return $this->fax;
}
/**
* @param string|null $fax
*/
public function setFax(?string $fax): void
{
$this->fax = $fax;
}
/**
* @return string|null
*/
public function getTelephonePortable(): ?string
{
return $this->telephonePortable;
}
/**
* @param string|null $telephonePortable
*/
public function setTelephonePortable(?string $telephonePortable): void
{
$this->telephonePortable = $telephonePortable;
}
/**
* @return string|null
*/
public function getPrenom(): ?string
{
return $this->prenom;
}
/**
* @param string|null $prenom
*/
public function setPrenom(?string $prenom): void
{
$this->prenom = $prenom;
}
/**
* @return string|null
*/
public function getNom(): ?string
{
return $this->nom;
}
/**
* @param string|null $nom
*/
public function setNom(?string $nom): void
{
$this->nom = $nom;
}
/**
* @return string|null
*/
public function getProfession(): ?string
{
return $this->profession;
}
/**
* @param string|null $profession
*/
public function setProfession(?string $profession): void
{
$this->profession = $profession;
}
/**
* @return bool|null
*/
public function getCompteActive(): ?bool
{
return $this->compteActive;
}
/**
* @param bool|null $compteActive
*/
public function setCompteActive(?bool $compteActive): void
{
$this->compteActive = $compteActive;
}
/**
* @return DateTime|null
*/
public function getDateInscription(): ?DateTime
{
return $this->dateInscription;
}
/**
* @param DateTime|null $dateInscription
*/
public function setDateInscription(?DateTime $dateInscription): void
{
$this->dateInscription = $dateInscription;
}
/**
* @return DateTime|null
*/
public function getDateDerConnexion(): ?DateTime
{
return $this->dateDerConnexion;
}
/**
* @param DateTime|null $dateDerConnexion
*/
public function setDateDerConnexion(?DateTime $dateDerConnexion): void
{
$this->dateDerConnexion = $dateDerConnexion;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @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): void
{
$this->roles = $roles;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): void
{
$this->isVerified = $isVerified;
}
public function getTypeAdherent(): ?TypeAdherent
{
return $this->typeAdherent;
}
public function setTypeAdherent(?TypeAdherent $typeAdherent): void
{
$this->typeAdherent = $typeAdherent;
}
public function getAdresse(): ?Adresse
{
return $this->adresse;
}
public function setAdresse(Adresse $adresse): void
{
$this->adresse = $adresse;
}
/**
* @return Collection<int, Groupe>
*/
public function getGroupes(): Collection
{
return $this->groupes;
}
public function addGroupe(Groupe $groupe): self
{
if (!$this->groupes->contains($groupe)) {
$this->groupes->add($groupe);
$groupe->setUser($this);
}
return $this;
}
public function removeGroupe(Groupe $groupe): self
{
if ($this->groupes->removeElement($groupe)) {
// set the owning side to null (unless already changed)
if ($groupe->getUser() === $this) {
$groupe->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Vehicule>
*/
public function getVehicules(): Collection
{
return $this->vehicules;
}
public function addVehicule(Vehicule $vehicule): self
{
if (!$this->vehicules->contains($vehicule)) {
$this->vehicules->add($vehicule);
$vehicule->setUser($this);
}
return $this;
}
public function removeVehicule(Vehicule $vehicule): self
{
if ($this->vehicules->removeElement($vehicule)) {
// set the owning side to null (unless already changed)
if ($vehicule->getUser() === $this) {
$vehicule->setUser(null);
}
}
return $this;
}
}