<?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 Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
*
* @ORM\Entity(repositoryClass=UserRepository::class)
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use TimestampableEntity;
public const ANONIMIZE_FIELDS = [
'name',
'lastName',
'email',
];
/**
* @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\Column(type="string", length=128, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $lastName;
/**
* @ORM\OneToMany(targetEntity=News::class, mappedBy="author")
*/
private $news;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $lang;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $enabled;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="App\Entity\TokenUser", mappedBy="user",cascade={"persist", "remove"})
*/
private $tokens;
/**
* @ORM\ManyToMany(targetEntity=Player::class, inversedBy="users", cascade={"persist", "remove"})
*/
private $favoritePlayers;
/**
* @ORM\ManyToOne(targetEntity=Country::class, inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $country;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $assistance;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $yearOfBirth;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $gender;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime|null
*/
protected $deletedAt;
/**
* @ORM\OneToMany(targetEntity=Award::class, mappedBy="user")
*/
private $awards;
/**
* @ORM\OneToMany(targetEntity=Ticket::class, mappedBy="user")
*/
private $tickets;
/**
* Set or clear the deleted at timestamp.
*
* @param \DateTime|null $deletedAt
* @return self
*/
public function setDeletedAt(\DateTime $deletedAt = null): User
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Get the deleted at timestamp value. Will return null if
* the entity has not been soft deleted.
*
* @return \DateTime|null
*/
public function getDeletedAt(): ?\DateTime
{
return $this->deletedAt;
}
public function __construct()
{
$this->news = new ArrayCollection();
$this->tokens = new ArrayCollection();
$this->favoritePlayers = new ArrayCollection();
$this->lang = 'es';
$this->awards = new ArrayCollection();
$this->tickets = new ArrayCollection();
}
public function __toString()
{
return $this->email;
}
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;
}
/**
* 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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
/**
* @return Collection
*/
public function getNews(): Collection
{
return $this->news;
}
public function addNews(News $news): self
{
if (!$this->news->contains($news)) {
$this->news[] = $news;
$news->setAuthor($this);
}
return $this;
}
public function removeNews(News $news): self
{
if ($this->news->removeElement($news)) {
// set the owning side to null (unless already changed)
if ($news->getAuthor() === $this) {
$news->setAuthor(null);
}
}
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getLang(): ?string
{
return $this->lang ?? 'es';
}
public function setLang(?string $lang): self
{
$this->lang = $lang;
return $this;
}
public function getUsername(): ?string
{
return $this->getEmail();
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getTokens(): ArrayCollection
{
return $this->tokens;
}
/**
* @return $this
*/
public function addToken(TokenUser $tokenUser): self
{
$tokenUser->setUser($this);
return $this;
}
/**
* @return $this
*/
public function removeTokenUser(TokenUser $tokenUser): self
{
if ($tokenUser->getUser() === $this) {
$tokenUser->setUser(null);
}
return $this;
}
/**
* @return Collection|Player[]
*/
public function getFavoritePlayers(): Collection
{
return $this->favoritePlayers;
}
public function addFavoritePlayer(Player $favoritePlayer): self
{
if (!$this->favoritePlayers->contains($favoritePlayer)) {
$this->favoritePlayers[] = $favoritePlayer;
}
return $this;
}
public function removeFavoritePlayer(Player $favoritePlayer): self
{
$this->favoritePlayers->removeElement($favoritePlayer);
return $this;
}
public function getFullName(): ?string
{
return $this->name . ' ' . $this->lastName;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getAssistance(): ?bool
{
return $this->assistance;
}
public function setAssistance(bool $assistance): self
{
$this->assistance = $assistance;
return $this;
}
public function getYearOfBirth(): ?string
{
return $this->yearOfBirth;
}
public function setYearOfBirth(string $yearOfBirth): self
{
$this->yearOfBirth = $yearOfBirth;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): self
{
$this->gender = $gender;
return $this;
}
/**
* @return Collection|Award[]
*/
public function getAwards(): Collection
{
return $this->awards;
}
public function addAward(Award $award): self
{
if (!$this->awards->contains($award)) {
$this->awards[] = $award;
$award->setUser($this);
}
return $this;
}
public function removeAward(Award $award): self
{
if ($this->awards->removeElement($award)) {
// set the owning side to null (unless already changed)
if ($award->getUser() === $this) {
$award->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Ticket[]
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): self
{
if (!$this->tickets->contains($ticket)) {
$this->tickets[] = $ticket;
$ticket->setUser($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getUser() === $this) {
$ticket->setUser(null);
}
}
return $this;
}
}