src/Entity/User.php line 17
<?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;
/**
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
#[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: 255)]
private $nickname;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
const ROLES = array(
'Administrateur' => 'ROLE_FATHER',
'MaƮtre de jeu' => 'ROLE_MASTER',
'Joueur' => 'ROLE_USER'
);
#[ORM\Column(type: 'string')]
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
#[ORM\OneToMany(mappedBy: 'player', targetEntity: PlayableEntity::class)]
private $playableEntities;
#[ORM\OneToOne(inversedBy: 'user', targetEntity: PlayableEntity::class, cascade: ['persist', 'remove'])]
private $character;
#[ORM\Column(length: 255, nullable: true)]
private ?string $avatar = null;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?Image $image = null;
#[ORM\OneToMany(mappedBy: 'sender', targetEntity: UserMessage::class)]
private Collection $sent;
#[ORM\OneToMany(mappedBy: 'recipient', targetEntity: UserMessage::class)]
private Collection $received;
public function __construct()
{
$this->playableEntities = new ArrayCollection();
$this->sent = new ArrayCollection();
$this->received = 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;
}
/**
* @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 getNickname(): ?string
{
return $this->nickname;
}
public function setNickname(string $nickname): self
{
$this->nickname = $nickname;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection|PlayableEntity[]
*/
public function getPlayableEntities(): Collection
{
return $this->playableEntities;
}
public function addPlayableEntity(PlayableEntity $playableEntity): self
{
if (!$this->playableEntities->contains($playableEntity)) {
$this->playableEntities[] = $playableEntity;
$playableEntity->setPlayer($this);
}
return $this;
}
public function removePlayableEntity(PlayableEntity $playableEntity): self
{
if ($this->playableEntities->removeElement($playableEntity)) {
// set the owning side to null (unless already changed)
if ($playableEntity->getPlayer() === $this) {
$playableEntity->setPlayer(null);
}
}
return $this;
}
public function __toString()
{
return (string) $this->nickname;
}
public function getCharacter(): ?PlayableEntity
{
return $this->character;
}
public function setCharacter(?PlayableEntity $character): self
{
$this->character = $character;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function getImage(): ?Image
{
return $this->image;
}
public function setImage(?Image $image): self
{
// unset the owning side of the relation if necessary
if ($image === null && $this->image !== null) {
$this->image->setUser(null);
}
// set the owning side of the relation if necessary
if ($image !== null && $image->getUser() !== $this) {
$image->setUser($this);
}
$this->image = $image;
return $this;
}
/**
* @return Collection<int, UserMessage>
*/
public function getSent(): Collection
{
return $this->sent;
}
public function addSent(UserMessage $sent): self
{
if (!$this->sent->contains($sent)) {
$this->sent->add($sent);
$sent->setSender($this);
}
return $this;
}
public function removeSent(UserMessage $sent): self
{
if ($this->sent->removeElement($sent)) {
// set the owning side to null (unless already changed)
if ($sent->getSender() === $this) {
$sent->setSender(null);
}
}
return $this;
}
/**
* @return Collection<int, UserMessage>
*/
public function getReceived(): Collection
{
return $this->received;
}
public function addReceived(UserMessage $received): self
{
if (!$this->received->contains($received)) {
$this->received->add($received);
$received->setRecipient($this);
}
return $this;
}
public function removeReceived(UserMessage $received): self
{
if ($this->received->removeElement($received)) {
// set the owning side to null (unless already changed)
if ($received->getRecipient() === $this) {
$received->setRecipient(null);
}
}
return $this;
}
}