<?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)]
#[ORM\Table(name: '`user`')]
#[ORM\InheritanceType("JOINED")]
#[ORM\DiscriminatorColumn(name: "discr", type: "string")]
#[ORM\DiscriminatorMap(["user" => User::class, "admin" => Admin::class, "contador" => Contador::class])]
#[UniqueEntity(fields: ['email'], message: 'Ya existe una cuenta con este correo.')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $nombre;
#[ORM\Column(type: 'string', length: 255)]
private $apellido;
#[ORM\Column(name: 'email', type: 'string', length: 255, unique:true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'string', nullable: true)]
private $foto = false;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(type: 'boolean')]
private $enabled = false;
#[ORM\Column(type: 'datetime', nullable: true)]
private $registerDate;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Observacion::class)]
private $observacions;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: Observacion::class)]
private $observaciones;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: RegistroAcceso::class)]
private $registroAccesos;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Sucursal::class)]
private $sucursals;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: Empleado::class)]
private $empleado;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: Familiar::class)]
private $familiars;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: Boleta::class)]
private $boletas;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: ContadorMensaje::class)]
private $contadorMensaje;
#[ORM\Column(type: 'integer', nullable: true)]
private $id_viejo;
#[ORM\OneToMany(mappedBy: 'userCargo', targetEntity: EmpleadoEmpresaSucursal::class)]
private Collection $empleadoEmpresaSucursals;
public function __construct()
{
$this->observacions = new ArrayCollection();
$this->registroAccesos = new ArrayCollection();
$this->sucursals = new ArrayCollection();
$this->empleado = new ArrayCollection();
$this->familiars = new ArrayCollection();
$this->boletas = new ArrayCollection();
$this->contadorMensaje = new ArrayCollection();
$this->empleadoEmpresaSucursals = 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;
}
/**
* @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;
// 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;
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->nombre,
$this->email,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->nombre,
$this->email,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized, array('allowed_classes' => false));
}
public function getIsVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* Get the value of nombre
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set the value of nombre
*
* @return self
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get the value of apellido
*/
public function getApellido()
{
return $this->apellido;
}
/**
* Set the value of apellido
*
* @return self
*/
public function setApellido($apellido)
{
$this->apellido = $apellido;
return $this;
}
/**
* Get the value of enabled
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* Set the value of enabled
*/
public function setEnabled($enabled): self
{
$this->enabled = $enabled;
return $this;
}
/**
* Get the value of foto
*/
public function getFoto()
{
return $this->foto;
}
/**
* Set the value of foto
*/
public function setFoto($foto): self
{
$this->foto = $foto;
return $this;
}
public function __toString() {
return $this->getNombre();
}
public function isGranted($role)
{
return in_array($role, $this->getRoles());
}
/**
* @return Collection<int, Observacion>
*/
public function getObservacions(): Collection
{
return $this->observacions;
}
public function addObservacion(Observacion $observacion): self
{
if (!$this->observacions->contains($observacion)) {
$this->observacions[] = $observacion;
$observacion->setUser($this);
}
return $this;
}
public function removeObservacion(Observacion $observacion): self
{
if ($this->observacions->removeElement($observacion)) {
// set the owning side to null (unless already changed)
if ($observacion->getUser() === $this) {
$observacion->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Observacion>
*/
public function getObservaciones(): Collection
{
return $this->observacions;
}
public function addObservaciones(Observacion $observacion): self
{
if (!$this->observacions->contains($observacion)) {
$this->observacions[] = $observacion;
$observacion->setUserCargo($this);
}
return $this;
}
public function removeObservaciones(Observacion $observacion): self
{
if ($this->observacions->removeElement($observacion)) {
// set the owning side to null (unless already changed)
if ($observacion->getUserCargo() === $this) {
$observacion->setUserCargo(null);
}
}
return $this;
}
/**
* @return Collection<int, Empleado>
*/
public function getEmpleado(): Collection
{
return $this->empleado;
}
public function addEmpleado(Empleado $empleado): self
{
if (!$this->empleado->contains($empleado)) {
$this->empleado[] = $empleado;
$empleado->setUserCargo($this);
}
return $this;
}
public function removeEmpleado(Empleado $empleado): self
{
if ($this->empleado->removeElement($empleado)) {
// set the owning side to null (unless already changed)
if ($empleado->getUserCargo() === $this) {
$empleado->setUserCargo(null);
}
}
return $this;
}
public function getRegisterDate(): ?\DateTimeInterface
{
return $this->registerDate;
}
public function setRegisterDate(\DateTimeInterface $registerDate): self
{
$this->registerDate = $registerDate;
return $this;
}
/**
* @return Collection<int, RegistroAcceso>
*/
public function getRegistroAccesos(): Collection
{
return $this->registroAccesos;
}
public function addRegistroAcceso(RegistroAcceso $registroAcceso): self
{
if (!$this->registroAccesos->contains($registroAcceso)) {
$this->registroAccesos[] = $registroAcceso;
$registroAcceso->setUser($this);
}
return $this;
}
public function removeRegistroAcceso(RegistroAcceso $registroAcceso): self
{
if ($this->registroAccesos->removeElement($registroAcceso)) {
// set the owning side to null (unless already changed)
if ($registroAcceso->getUser() === $this) {
$registroAcceso->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Sucursal>
*/
public function getSucursals(): Collection
{
return $this->sucursals;
}
public function addSucursal(Sucursal $sucursal): self
{
if (!$this->sucursals->contains($sucursal)) {
$this->sucursals[] = $sucursal;
$sucursal->setUser($this);
}
return $this;
}
public function removeSucursal(Sucursal $sucursal): self
{
if ($this->sucursals->removeElement($sucursal)) {
// set the owning side to null (unless already changed)
if ($sucursal->getUser() === $this) {
$sucursal->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Familiar>
*/
public function getFamiliars(): Collection
{
return $this->familiars;
}
public function addFamiliar(Familiar $familiar): self
{
if (!$this->familiars->contains($familiar)) {
$this->familiars[] = $familiar;
$familiar->setUserCargo($this);
}
return $this;
}
public function removeFamiliar(Familiar $familiar): self
{
if ($this->familiars->removeElement($familiar)) {
// set the owning side to null (unless already changed)
if ($familiar->getUserCargo() === $this) {
$familiar->setUserCargo(null);
}
}
return $this;
}
/**
* @return Collection<int, Boleta>
*/
public function getBoletas(): Collection
{
return $this->boletas;
}
public function addBoleta(Boleta $boleta): self
{
if (!$this->boletas->contains($boleta)) {
$this->boletas[] = $boleta;
$boleta->setUserCargo($this);
}
return $this;
}
public function removeBoleta(Boleta $boleta): self
{
if ($this->boletas->removeElement($boleta)) {
// set the owning side to null (unless already changed)
if ($boleta->getUserCargo() === $this) {
$boleta->setUserCargo(null);
}
}
return $this;
}
/**
* @return Collection<int, ContadorMensaje>
*/
public function getContadorMensaje(): Collection
{
return $this->contadorMensaje;
}
public function addContadorMensaje(ContadorMensaje $contadorMensaje): self
{
if (!$this->contadorMensaje->contains($contadorMensaje)) {
$this->contadorMensaje[] = $contadorMensaje;
$contadorMensaje->setUserCargo($this);
}
return $this;
}
public function removeContadorMensaje(ContadorMensaje $contadorMensaje): self
{
if ($this->contadorMensaje->removeElement($contadorMensaje)) {
// set the owning side to null (unless already changed)
if ($contadorMensaje->getUserCargo() === $this) {
$contadorMensaje->setUserCargo(null);
}
}
return $this;
}
/**
* Get the value of id_viejo
*/
public function getId_viejo()
{
return $this->id_viejo;
}
/**
* Set the value of id_viejo
*
* @return self
*/
public function setId_viejo($id_viejo)
{
$this->id_viejo = $id_viejo;
return $this;
}
/**
* @return Collection<int, EmpleadoEmpresaSucursal>
*/
public function getEmpleadoEmpresaSucursals(): Collection
{
return $this->empleadoEmpresaSucursals;
}
public function addEmpleadoEmpresaSucursal(EmpleadoEmpresaSucursal $empleadoEmpresaSucursal): self
{
if (!$this->empleadoEmpresaSucursals->contains($empleadoEmpresaSucursal)) {
$this->empleadoEmpresaSucursals->add($empleadoEmpresaSucursal);
$empleadoEmpresaSucursal->setUserCargo($this);
}
return $this;
}
public function removeEmpleadoEmpresaSucursal(EmpleadoEmpresaSucursal $empleadoEmpresaSucursal): self
{
if ($this->empleadoEmpresaSucursals->removeElement($empleadoEmpresaSucursal)) {
// set the owning side to null (unless already changed)
if ($empleadoEmpresaSucursal->getUserCargo() === $this) {
$empleadoEmpresaSucursal->setUserCargo(null);
}
}
return $this;
}
}