207 lines
4.2 KiB
PHP
207 lines
4.2 KiB
PHP
<?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\PasswordAuthenticatedUserInterface;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $email = null;
|
|
|
|
#[ORM\Column(length: 60)]
|
|
private ?string $pseudo = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $password = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $firstName = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $lastName = null;
|
|
|
|
#[ORM\Column(type: "json")]
|
|
private array $roles = [];
|
|
|
|
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Favoris::class)]
|
|
private Collection $favoris;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'id_user', targetEntity: Avis::class)]
|
|
private Collection $avis;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->favoris = new ArrayCollection();
|
|
$this->avis = new ArrayCollection();
|
|
}
|
|
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(string $email): static
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPseudo(): ?string
|
|
{
|
|
return $this->pseudo;
|
|
}
|
|
|
|
public function setPseudo(string $pseudo): static
|
|
{
|
|
$this->pseudo = $pseudo;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword(): ?string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setPassword(string $password): static
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFirstName(): ?string
|
|
{
|
|
return $this->firstName;
|
|
}
|
|
|
|
public function setFirstName(string $firstName): static
|
|
{
|
|
$this->firstName = $firstName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLastName(): ?string
|
|
{
|
|
return $this->lastName;
|
|
}
|
|
|
|
public function setLastName(string $lastName): static
|
|
{
|
|
$this->lastName = $lastName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSalt(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function getRoles(): array
|
|
{
|
|
|
|
$roles = $this->roles;
|
|
|
|
if (empty($roles)) {
|
|
$roles[] = 'ROLE_USER';
|
|
}
|
|
|
|
return $roles;
|
|
|
|
}
|
|
|
|
public function eraseCredentials(): void
|
|
{
|
|
|
|
}
|
|
|
|
public function getUserIdentifier(): string
|
|
{
|
|
|
|
return $this->email; // Ou $this->pseudo si tu préfères utiliser le pseudo
|
|
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Favoris>
|
|
*/
|
|
public function getFavoris(): Collection
|
|
{
|
|
return $this->favoris;
|
|
}
|
|
|
|
public function addFavori(Favoris $favori): static
|
|
{
|
|
if (!$this->favoris->contains($favori)) {
|
|
$this->favoris->add($favori);
|
|
$favori->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeFavori(Favoris $favori): static
|
|
{
|
|
if ($this->favoris->removeElement($favori)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($favori->getUser() === $this) {
|
|
$favori->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Avis>
|
|
*/
|
|
public function getAvis(): Collection
|
|
{
|
|
return $this->avis;
|
|
}
|
|
|
|
public function addAvi(Avis $avi): static
|
|
{
|
|
if (!$this->avis->contains($avi)) {
|
|
$this->avis->add($avi);
|
|
$avi->setIdUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeAvi(Avis $avi): static
|
|
{
|
|
if ($this->avis->removeElement($avi)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($avi->getIdUser() === $this) {
|
|
$avi->setIdUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|