<?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;
use Symfony\Component\Validator\Constraints\Length;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $userName = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: MarchePublic::class)]
private Collection $marchePublics;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Concession::class)]
private Collection $concessions;
#[ORM\Column(length: 255, nullable: true)]
#[Length(
exactly: 14,
exactMessage: 'L\'identifiant SIRET doit comporter exactement 14 chiffres.'
)]
private ?string $siret = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
public function __construct()
{
$this->marchePublics = new ArrayCollection();
$this->concessions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUserName(): ?string
{
return $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_SUPER_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;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, MarchePublic>
*/
public function getMarchePublics(): Collection
{
return $this->marchePublics;
}
public function addMarchePublic(MarchePublic $marchePublic): static
{
if (!$this->marchePublics->contains($marchePublic)) {
$this->marchePublics->add($marchePublic);
$marchePublic->setUser($this);
}
return $this;
}
public function removeMarchePublic(MarchePublic $marchePublic): static
{
if ($this->marchePublics->removeElement($marchePublic)) {
// set the owning side to null (unless already changed)
if ($marchePublic->getUser() === $this) {
$marchePublic->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Concession>
*/
public function getConcessions(): Collection
{
return $this->concessions;
}
public function addConcession(Concession $concession): static
{
if (!$this->concessions->contains($concession)) {
$this->concessions->add($concession);
$concession->setUser($this);
}
return $this;
}
public function removeConcession(Concession $concession): static
{
if ($this->concessions->removeElement($concession)) {
// set the owning side to null (unless already changed)
if ($concession->getUser() === $this) {
$concession->setUser(null);
}
}
return $this;
}
public function getSiret(): ?string
{
return $this->siret;
}
public function setSiret(string $siret): static
{
$this->siret = $siret;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
}