<?php
namespace App\Entity;
use App\Repository\UserRepository;
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;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"username"}, message="El nombre de usuario ya está en uso.")
* @UniqueEntity(fields={"email"}, message="El correo electrónico ya está en uso.")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\Email
* @Assert\NotBlank
*/
private $email;
/**
* @ORM\Column(type="integer")
*/
private $creditos;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\Column(type="string", length=255)
*/
private $token;
/**
* @ORM\Column(type="integer")
*/
private $pelo;
/**
* @ORM\Column(type="integer")
*/
private $camisa;
/**
* @ORM\Column(type="integer")
*/
private $pants;
/**
* @ORM\Column(type="string", length=3, nullable=true)
*/
private $placa;
/**
* @ORM\OneToMany(targetEntity=Categoria::class, mappedBy="user")
*/
private $categorias;
/**
* @ORM\OneToMany(targetEntity=HistorialCompra::class, mappedBy="user", orphanRemoval=true)
*/
private $historialCompras;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $vipExpirationDate;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $resetToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $resetTokenExpiresAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $ipLastLogin;
/**
* @ORM\OneToOne(targetEntity=BannedUsers::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $userBan;
/**
* @ORM\OneToMany(targetEntity=BannedUsers::class, mappedBy="moderator")
*/
private $bannedUsers;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaRegistro;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $zapatos;
public function __construct() {
$this->categorias = new ArrayCollection();
$this->historialCompras = new ArrayCollection();
$this->bannedUsers = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string {
return (string) $this->username;
}
public function setUsername(string $username): self {
$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_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;
}
public function getEmail(): ?string {
return $this->email;
}
public function setEmail(?string $email): self {
$this->email = $email;
return $this;
}
public function getCreditos(): ?int {
return $this->creditos;
}
public function setCreditos(int $creditos): self {
$this->creditos = $creditos;
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 isVerified(): bool {
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self {
$this->isVerified = $isVerified;
return $this;
}
public function getToken(): ?string {
return $this->token;
}
public function setToken(string $token): self {
$this->token = $token;
return $this;
}
public function getPelo(): ?int {
return $this->pelo;
}
public function setPelo(int $pelo): self {
$this->pelo = $pelo;
return $this;
}
public function getCamisa(): ?int {
return $this->camisa;
}
public function setCamisa(int $camisa): self {
$this->camisa = $camisa;
return $this;
}
public function getPants(): ?int {
return $this->pants;
}
public function setPants(int $pants): self {
$this->pants = $pants;
return $this;
}
public function getPlaca(): ?string {
return $this->placa;
}
public function setPlaca(?string $placa): self {
$this->placa = $placa;
return $this;
}
/**
* @return Collection|Categoria[]
*/
public function getCategorias(): Collection {
return $this->categorias;
}
public function addCategoria(Categoria $categoria): self {
if (!$this->categorias->contains($categoria)) {
$this->categorias[] = $categoria;
$categoria->setUser($this);
}
return $this;
}
public function removeCategoria(Categoria $categoria): self {
if ($this->categorias->removeElement($categoria)) {
// set the owning side to null (unless already changed)
if ($categoria->getUser() === $this) {
$categoria->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, HistorialCompra>
*/
public function getHistorialCompras(): Collection
{
return $this->historialCompras;
}
public function addHistorialCompra(HistorialCompra $historialCompra): self
{
if (!$this->historialCompras->contains($historialCompra)) {
$this->historialCompras[] = $historialCompra;
$historialCompra->setUser($this);
}
return $this;
}
public function removeHistorialCompra(HistorialCompra $historialCompra): self
{
if ($this->historialCompras->removeElement($historialCompra)) {
// set the owning side to null (unless already changed)
if ($historialCompra->getUser() === $this) {
$historialCompra->setUser(null);
}
}
return $this;
}
public function getVipExpirationDate(): ?\DateTimeInterface
{
return $this->vipExpirationDate;
}
public function setVipExpirationDate(?\DateTimeInterface $vipExpirationDate): self
{
$this->vipExpirationDate = $vipExpirationDate;
return $this;
}
public function getResetToken(): ?string
{
return $this->resetToken;
}
public function setResetToken(?string $resetToken): self
{
$this->resetToken = $resetToken;
return $this;
}
public function getResetTokenExpiresAt(): ?\DateTimeInterface
{
return $this->resetTokenExpiresAt;
}
public function setResetTokenExpiresAt(?\DateTimeInterface $resetTokenExpiresAt): self
{
$this->resetTokenExpiresAt = $resetTokenExpiresAt;
return $this;
}
public function getIpLastLogin(): ?string
{
return $this->ipLastLogin;
}
public function setIpLastLogin(?string $ipLastLogin): self
{
$this->ipLastLogin = $ipLastLogin;
return $this;
}
public function getUserBan(): ?BannedUsers
{
return $this->userBan;
}
public function setUserBan(BannedUsers $userBan): self
{
// set the owning side of the relation if necessary
if ($userBan->getUser() !== $this) {
$userBan->setUser($this);
}
$this->userBan = $userBan;
return $this;
}
/**
* @return Collection<int, BannedUsers>
*/
public function getBannedUsers(): Collection
{
return $this->bannedUsers;
}
public function addBannedUser(BannedUsers $bannedUser): self
{
if (!$this->bannedUsers->contains($bannedUser)) {
$this->bannedUsers[] = $bannedUser;
$bannedUser->setModerator($this);
}
return $this;
}
public function removeBannedUser(BannedUsers $bannedUser): self
{
if ($this->bannedUsers->removeElement($bannedUser)) {
// set the owning side to null (unless already changed)
if ($bannedUser->getModerator() === $this) {
$bannedUser->setModerator(null);
}
}
return $this;
}
public function getFechaRegistro(): ?\DateTimeInterface
{
return $this->fechaRegistro;
}
public function setFechaRegistro(?\DateTimeInterface $fechaRegistro): self
{
$this->fechaRegistro = $fechaRegistro;
return $this;
}
public function getZapatos(): ?int
{
return $this->zapatos;
}
public function setZapatos(?int $zapatos): self
{
$this->zapatos = $zapatos;
return $this;
}
}