<?php
namespace App\Entity;
use App\Entity\Restaurante;
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="Ya existe una cuenta con ese 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=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleID;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleAccessToken;
/**
* @ORM\OneToMany(targetEntity="Restaurante", mappedBy="user")
*/
protected $restaurantes;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isVerified = false;
public function __construct() {
$this->restaurantes = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
public function setId(?int $id): self
{
$this->id = $id;
return $this;
}
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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string {
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array {
$roles = $this->roles;
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 setIsVerified(bool $isVerified): self {
$this->isVerified = $isVerified;
return $this;
}
public function __toString(): string {
return $this->email;
}
public function getIsVerified(): ?bool {
return $this->isVerified;
}
/**
* @return Collection|Restaurante[]
*/
public function getRestaurantes(): Collection {
return $this->restaurantes;
}
public function addRestaurante(Restaurante $restaurante): self {
if (!$this->restaurantes->contains($restaurante)) {
$this->restaurantes[] = $restaurante;
$restaurante->setUser($this);
}
return $this;
}
public function removeRestaurante(Restaurante $restaurante): self {
if ($this->restaurantes->removeElement($restaurante)) {
// set the owning side to null (unless already changed)
if ($restaurante->getUser() === $this) {
$restaurante->setUser(null);
}
}
return $this;
}
public function getGoogleID(): ?string
{
return $this->googleID;
}
public function setGoogleID(?string $googleID): self
{
$this->googleID = $googleID;
return $this;
}
public function getGoogleAccessToken(): ?string
{
return $this->googleAccessToken;
}
public function setGoogleAccessToken(?string $googleAccessToken): self
{
$this->googleAccessToken = $googleAccessToken;
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
}