src/Entity/User.php line 16
<?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\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column]
private ?bool $isVerified = false;
#[ORM\Column(length: 80)]
private ?string $nom = null;
#[ORM\Column(length: 80)]
private ?string $prenom = null;
#[ORM\Column]
private ?bool $newsletter = null;
#[ORM\Column(length: 255)]
private ?string $profession = null;
#[ORM\OneToMany(mappedBy: 'auteur', targetEntity: Commentaire::class)]
private Collection $commentaires;
#[ORM\ManyToMany(targetEntity: Materiel::class)]
private Collection $materiels;
#[ORM\ManyToMany(targetEntity: Protocole::class)]
private Collection $protocoles;
public function __construct()
{
$this->commentaires = new ArrayCollection();
$this->materiels = new ArrayCollection();
$this->protocoles = new ArrayCollection();
}
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;
}
/**
* 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): self
{
$this->roles = $roles;
return $this;
}
public function hasRole($role)
{
return in_array($role, $this->roles);
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function isNewsletter(): ?bool
{
return $this->newsletter;
}
public function setNewsletter(bool $newsletter): self
{
$this->newsletter = $newsletter;
return $this;
}
public function getProfession(): ?string
{
return $this->profession;
}
public function setProfession(string $profession): self
{
$this->profession = $profession;
return $this;
}
/**
* @return Collection<int, Commentaire>
*/
public function getCommentaires(): Collection
{
return $this->commentaires;
}
public function addCommentaire(Commentaire $commentaire): self
{
if (!$this->commentaires->contains($commentaire)) {
$this->commentaires->add($commentaire);
$commentaire->setAuteur($this);
}
return $this;
}
public function removeCommentaire(Commentaire $commentaire): self
{
if ($this->commentaires->removeElement($commentaire)) {
// set the owning side to null (unless already changed)
if ($commentaire->getAuteur() === $this) {
$commentaire->setAuteur(null);
}
}
return $this;
}
/**
* @return Collection<int, Materiel>
*/
public function getMateriels(): Collection
{
return $this->materiels;
}
public function addMateriel(Materiel $materiel): self
{
if (!$this->materiels->contains($materiel)) {
$this->materiels->add($materiel);
}
return $this;
}
public function removeMateriel(Materiel $materiel): self
{
$this->materiels->removeElement($materiel);
return $this;
}
/**
* @return Collection<int, Protocole>
*/
public function getProtocoles(): Collection
{
return $this->protocoles;
}
public function addProtocole(Protocole $protocole): self
{
if (!$this->protocoles->contains($protocole)) {
$this->protocoles->add($protocole);
}
return $this;
}
public function removeProtocole(Protocole $protocole): self
{
$this->protocoles->removeElement($protocole);
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
}