<?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(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\OneToOne(targetEntity=Personne::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $personne;
/**
* @ORM\OneToOne(targetEntity=Membre::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $membre;
/**
* @ORM\OneToOne(targetEntity=Province::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $province;
/**
* @ORM\OneToOne(targetEntity=Federation::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $federation;
/**
* @ORM\OneToOne(targetEntity=Demande::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $demande;
/**
* @ORM\OneToMany(targetEntity=ForumSujet::class, mappedBy="auteur")
*/
private $forumSujets;
/**
* @ORM\OneToMany(targetEntity=ForumMessage::class, mappedBy="auteur")
*/
private $forumMessages;
public function __construct()
{
$this->forumSujets = new ArrayCollection();
$this->forumMessages = 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 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 getPersonne(): ?Personne
{
return $this->personne;
}
public function setPersonne(?Personne $personne): self
{
$this->personne = $personne;
return $this;
}
public function getProvince(): ?Province
{
return $this->province;
}
public function getMembre(): ?Membre
{
return $this->membre;
}
public function setMembre(?Membre $membre): self
{
// unset the owning side of the relation if necessary
if ($membre === null && $this->membre !== null) {
$this->membre->setUser(null);
}
// set the owning side of the relation if necessary
if ($membre !== null && $membre->getUser() !== $this) {
$membre->setUser($this);
}
$this->membre = $membre;
return $this;
}
public function getFederation(): ?Federation
{
return $this->federation;
}
public function setFederation(?Federation $federation): self
{
// unset the owning side of the relation if necessary
if ($federation === null && $this->federation !== null) {
$this->federation->setUser(null);
}
// set the owning side of the relation if necessary
if ($federation !== null && $federation->getUser() !== $this) {
$federation->setUser($this);
}
$this->federation = $federation;
return $this;
}
public function getDemande(): ?Demande
{
return $this->demande;
}
public function setDemande(Demande $demande): self
{
// set the owning side of the relation if necessary
if ($demande->getUser() !== $this) {
$demande->setUser($this);
}
$this->demande = $demande;
return $this;
}
/**
* @return Collection<int, ForumSujet>
*/
public function getForumSujets(): Collection
{
return $this->forumSujets;
}
public function addForumSujet(ForumSujet $forumSujet): self
{
if (!$this->forumSujets->contains($forumSujet)) {
$this->forumSujets[] = $forumSujet;
$forumSujet->setAuteur($this);
}
return $this;
}
public function removeForumSujet(ForumSujet $forumSujet): self
{
if ($this->forumSujets->removeElement($forumSujet)) {
// set the owning side to null (unless already changed)
if ($forumSujet->getAuteur() === $this) {
$forumSujet->setAuteur(null);
}
}
return $this;
}
/**
* @return Collection<int, ForumMessage>
*/
public function getForumMessages(): Collection
{
return $this->forumMessages;
}
public function addForumMessage(ForumMessage $forumMessage): self
{
if (!$this->forumMessages->contains($forumMessage)) {
$this->forumMessages[] = $forumMessage;
$forumMessage->setAuteur($this);
}
return $this;
}
public function removeForumMessage(ForumMessage $forumMessage): self
{
if ($this->forumMessages->removeElement($forumMessage)) {
// set the owning side to null (unless already changed)
if ($forumMessage->getAuteur() === $this) {
$forumMessage->setAuteur(null);
}
}
return $this;
}
}