<?php
namespace App\Entity;
use App\Validator as PerseoAssert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="user", schema="perseo")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
* @PerseoAssert\ContraintsValidarEntidadCp()
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="bigint", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", unique=true, length=180, nullable=false)
*/
protected $username;
/**
* @ORM\Column(type="string", unique=true, length=180, nullable=false)
*/
protected $email;
/**
* @ORM\Column(type="json", nullable=false)
*/
protected $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=false)
*/
protected $password;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $nombre;
/**
* @ORM\Column(type="string", nullable=true, name="primer_apellido")
*/
protected $primerApellido;
/**
* @ORM\Column(type="string", nullable=true, name="segundo_apellido")
*/
protected $segundoApellido;
/**
* @ORM\Column(type="bigint", nullable=true, name="tipo_genero_id", options={"unsigned":true})
*/
protected $tipoGenero;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $direccion;
/**
* @ORM\Column(type="string", length=12, nullable=true)
* @Assert\Length(min = 5, max = 12)
*/
protected $cp;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $region;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $ciudad;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $telefono;
/**
* @ORM\Column(type="datetime", nullable=true, name="deleted_at")
*/
protected $deletedAt;
/**
* @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
* @Gedmo\Timestampable(on="update")
*/
protected $updatedAt;
/**
* @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
* @Gedmo\Timestampable(on="create")
*/
protected $createdAt;
/**
* @ORM\Column(type="string", length=2, nullable=true, name="pais")
*/
protected $pais;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CCAA", inversedBy="user")
* @ORM\JoinColumn(name="ccaa_id", referencedColumnName="id")
*/
protected $ccaa;
/*
* @ORM\ManyToOne(targetEntity="App\Entity\Ciudad", inversedBy="user")
* @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
*/
//protected $ciudad;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Provincia", inversedBy="user")
* @ORM\JoinColumn(name="provincia_id", referencedColumnName="id")
*/
protected $provincia;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Cliente", inversedBy="user", cascade={"persist"})
* @ORM\JoinColumn(name="cliente_id", referencedColumnName="id", nullable=true, unique=true)
*/
protected $cliente;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Usuario", inversedBy="user", cascade={"persist"})
* @ORM\JoinColumn(name="usuario_id", referencedColumnName="id", nullable=true, unique=true)
*/
protected $usuario;
public function __construct()
{
// $this->cliente = new Cliente();
// $this->usuario = new Usuario();
}
public function getNombreCompleto()
{
return $this->getNombre() . ' ' . $this->getPrimerApellido() . ' ' . $this->getSegundoApellido();
}
public function getIniciales()
{
return mb_substr($this->getNombre(), 0, 1) . ' ' . mb_substr($this->getPrimerApellido(), 0, 1) . ' ' . mb_substr($this->getSegundoApellido(), 0, 1);
}
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;
}
/**
* 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 getCliente(): ?Cliente
{
return $this->cliente;
}
public function setCliente(Cliente $cliente): self
{
$this->cliente = $cliente;
return $this;
}
public function getUsuario(): ?Usuario
{
return $this->usuario;
}
public function setUsuario(?Usuario $usuario): self
{
$this->usuario = $usuario;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(?string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function getPrimerApellido(): ?string
{
return $this->primerApellido;
}
public function setPrimerApellido(?string $primerApellido): self
{
$this->primerApellido = $primerApellido;
return $this;
}
public function getSegundoApellido(): ?string
{
return $this->segundoApellido;
}
public function setSegundoApellido(?string $segundoApellido): self
{
$this->segundoApellido = $segundoApellido;
return $this;
}
public function getTipoGenero(): ?string
{
return $this->tipoGenero;
}
public function setTipoGenero(?string $tipoGenero): self
{
$this->tipoGenero = $tipoGenero;
return $this;
}
public function getDireccion(): ?string
{
return $this->direccion;
}
public function setDireccion(?string $direccion): self
{
$this->direccion = $direccion;
return $this;
}
public function getCp(): ?string
{
return $this->cp;
}
public function setCp(?string $cp): self
{
$this->cp = $cp;
return $this;
}
public function getTelefono(): ?string
{
return $this->telefono;
}
public function setTelefono(?string $telefono): self
{
$this->telefono = $telefono;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCcaa(): ?CCAA
{
return $this->ccaa;
}
public function setCcaa(?CCAA $ccaa): self
{
$this->ccaa = $ccaa;
return $this;
}
public function getCiudad(): ?string
{
return $this->ciudad;
}
public function setCiudad(?string $ciudad): self
{
$this->ciudad = $ciudad;
return $this;
}
public function getPais(): ?string
{
return $this->pais;
}
public function setPais(?string $pais): self
{
$this->pais = $pais;
return $this;
}
public function getProvincia(): ?Provincia
{
return $this->provincia;
}
public function setProvincia(?Provincia $provincia): self
{
$this->provincia = $provincia;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getRegion(): ?string
{
return $this->region;
}
public function setRegion(?string $region): static
{
$this->region = $region;
return $this;
}
}