<?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;
#[ORM\InheritanceType("JOINED")]
#[ORM\DiscriminatorColumn(name: "type", type: "string")]
#[ORM\DiscriminatorMap(["User" => User::class,"consultant" => Consultants::class, "entreprise" => Entreprises::class, "administrateur" => Administrateurs::class, "comerciaux" => Comerciaux::class])]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'Ce mail appartient déjà à un compte')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(type: 'string', length: 20)]
private $num;
#[ORM\Column(type: 'string', nullable:true)]
private ?string $confirmpassword;
// public function __serialize(): array
// {
// return [
// 'email' => $this->email,
// 'password' => $this->password,
// ];
// }
// public function __unserialize(array $data): void
// {
// $this->email = $data['email'];
// $this->password = $data['password'];
// }
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function __serialize(): array
{
return [
'id' => $this->id,
'email' => $this->email,
'password' => $this->password,
'num' => $this->num, // Inclure num
];
}
public function __unserialize(array $data): void
{
$this->id = $data['id'];
$this->email = $data['email'];
$this->password = $data['password'];
$this->num = $data['num'] ?? null; // Restaurer num
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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): 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 isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getNum(): ?string
{
return $this->num;
}
public function setNum(string $num): self
{
$this->num = $num;
return $this;
}
public function getConfirmpassword(): ?string
{
return $this->confirmpassword;
}
public function setConfirmpassword(string $confirmpassword): static
{
$this->confirmpassword = $confirmpassword;
return $this;
}
}