<?php
namespace App\Entity\Ajustes;
use App\Repository\Ajustes\UsuarioRepository;
use App\Traits\ChangesAtTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
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 Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=UsuarioRepository::class)
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields="email", message="Ya existe otro usuario con este E-mail.")
*/
class Usuario implements UserInterface, PasswordAuthenticatedUserInterface
{
use ChangesAtTrait;
public const BASEDIR = '/pages/privado/ajustes/usuarios';
public const BaseDirPerfil = 'pages/privado/miperfil';
public const ICON_CLASS = 'fas fa-users-cog';
public const ICON_CLASS_PASS = 'fas fa-key';
public const ICON = '<i class="'.self::ICON_CLASS.'"></i>';
public const ROLES = [
'ADMINISTRADOR' => 'ROLE_SUPERADMIN',
'CLIENTE' => 'ROLE_CLIENTE',
'PROFESIONAL' => 'ROLE_PROFESIONAL',
'EMPLEADO' => 'ROLE_EMPLEADO'
];
public const ESTADOS = [
'user.estados.activo' => 1,
'user.estados.inactivo' => 0,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"Simple"})
*/
private $id;
/**
* @Groups({"Simple"})
*/
private $text;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="array")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $enabled;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLoginAt;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $lastLoginIp;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $passwordChangedAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $passwordRecoverToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $passwordRecoverRequestedAt;
/**
* @ORM\Column(type="string", length=40, nullable=true)
*/
private $passwordRecoverResquestIp;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLoginTryAt;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $lastLoginTryIp;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $observaciones;
/**
* @ORM\OneToMany(targetEntity=HistoricoPedido::class, mappedBy="HistCretedBy")
*/
private $HistoricoPedidos;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $surname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $company;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $language;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phonePre;
/**
* @ORM\OneToMany(targetEntity=Gradeada::class, mappedBy="GradCliente")
*/
private $UsuGradeada;
/**
* @ORM\OneToMany(targetEntity=Direccion::class, mappedBy="DirUser", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $direcciones;
/**
* @ORM\OneToMany(targetEntity=UsuarioValidacionEmail::class, mappedBy="idUser", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $UsuEmailValidation;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $correoVerificado;
private $FullName;
private $FullPhone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $UsuDni;
/**
* @ORM\OneToMany(targetEntity=Pedido::class, mappedBy="PedUsuario", cascade={"persist", "remove"})
*/
private $UsuPedidos;
/**
* @ORM\OneToMany(targetEntity=Descuento::class, mappedBy="DesUsuario")
*/
private $UsuCodDescuentos;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $UsuComentarioDescuento;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $UsuAlbumToken;
/**
* @ORM\OneToMany(targetEntity=HistComisiones::class, mappedBy="HistComPedUsuario")
*/
private $UsuPedidoHistComisiones;
/**
* @ORM\OneToMany(targetEntity=HistComisiones::class, mappedBy="HistComUsuario", cascade={"persist","remove"} )
*/
private $UsuHistComisiones;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $UsuOldId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $UsuOldPassword;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $UsuDesServicios;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $UsuDesProductos;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $UsuDesEnvio;
/**
* @ORM\OneToMany(targetEntity=Gradeada::class, mappedBy="GradLotesRecBy")
*/
private $UsuGradLotesRecCartas;
/**
* @ORM\OneToMany(targetEntity=Gradeada::class, mappedBy="GradLotesEnvBy")
*/
private $UsuGradLotesEnvCartas;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->enabled = true;
$this->correoVerificado = false;
$this->HistoricoPedidos = new ArrayCollection();
$this->UsuGradeada = new ArrayCollection();
$this->direcciones = new ArrayCollection();
$this->UsuEmailValidation = new ArrayCollection();
$this->UsuPedidos = new ArrayCollection();
$this->UsuCodDescuentos = new ArrayCollection();
$this->UsuPedidoHistComisiones = new ArrayCollection();
$this->UsuHistComisiones = new ArrayCollection();
$this->UsuGradLotesRecCartas = new ArrayCollection();
$this->UsuGradLotesEnvCartas = new ArrayCollection();
}
public function __toString(): string
{
return (string) $this->email;
}
public function getFullName(): string
{
return (string) ($this->getName() ? $this->getName() : '').' '.($this->getSurname() ? $this->getSurname() : '');
}
public function getFullPhone(): string
{
if (str_starts_with($this->getPhonePre(), '+')){
return (string) ($this->getPhonePre() ? $this->getPhonePre() : '').' '.($this->getPhone() ? $this->getPhone() : '');
}else{
return (string) '+'.($this->getPhonePre() ? $this->getPhonePre() : '').' '.($this->getPhone() ? $this->getPhone() : '');
}
}
/**
* @ORM\PreUpdate
*/
public function onUpdateEntity()
{
$this->updatedAt = new \DateTime();
}
public function reset(): self
{
$this->createdAt = new \DateTime();
$this->updatedAt = null;
$this->email = null;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getText(): string
{
return (string) $this->__toString();
}
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 getEnabled(): ?bool
{
return $this->enabled;
}
public function getEnabledTag(string $text = ''): string
{
return $this->enabled ?
'<span class="badge badge-light-success">'.$text.'</span>' :
'<span class="badge badge-light-danger">'.$text.'</span>'
;
}
public function getEnabledText(): string
{
return false === array_search($this->enabled, self::ESTADOS) ? 'user.estados.none' : array_search($this->enabled, self::ESTADOS);
}
public function isEnabled(): bool
{
return true == (bool) $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getLastLoginAt(): ?\DateTimeInterface
{
return $this->lastLoginAt;
}
public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self
{
$this->lastLoginAt = $lastLoginAt;
return $this;
}
public function getLastLoginIp(): ?string
{
return $this->lastLoginIp;
}
public function setLastLoginIp(?string $lastLoginIp): self
{
$this->lastLoginIp = $lastLoginIp;
return $this;
}
public function getPasswordChangedAt(): ?\DateTimeInterface
{
return $this->passwordChangedAt;
}
public function setPasswordChangedAt(?\DateTimeInterface $passwordChangedAt): self
{
$this->passwordChangedAt = $passwordChangedAt;
return $this;
}
public function getPasswordRecoverToken(): ?string
{
return $this->passwordRecoverToken;
}
public function setPasswordRecoverToken(?string $passwordRecoverToken): self
{
$this->passwordRecoverToken = $passwordRecoverToken;
return $this;
}
public function getPasswordRecoverRequestedAt(): ?\DateTimeInterface
{
return $this->passwordRecoverRequestedAt;
}
public function setPasswordRecoverRequestedAt(?\DateTimeInterface $passwordRecoverRequestedAt): self
{
$this->passwordRecoverRequestedAt = $passwordRecoverRequestedAt;
return $this;
}
public function getPasswordRecoverResquestIp(): ?string
{
return $this->passwordRecoverResquestIp;
}
public function setPasswordRecoverResquestIp(?string $passwordRecoverResquestIp): self
{
$this->passwordRecoverResquestIp = $passwordRecoverResquestIp;
return $this;
}
public function getLastLoginTryAt(): ?\DateTimeInterface
{
return $this->lastLoginTryAt;
}
public function setLastLoginTryAt(?\DateTimeInterface $lastLoginTryAt): self
{
$this->lastLoginTryAt = $lastLoginTryAt;
return $this;
}
public function getLastLoginTryIp(): ?string
{
return $this->lastLoginTryIp;
}
public function setLastLoginTryIp(?string $lastLoginTryIp): self
{
$this->lastLoginTryIp = $lastLoginTryIp;
return $this;
}
public function getObservaciones(): ?string
{
return $this->observaciones;
}
public function setObservaciones(?string $observaciones): self
{
$this->observaciones = $observaciones;
return $this;
}
/**
* @return Collection<int, HistoricoPedido>
*/
public function getHistoricoPedidos(): Collection
{
return $this->HistoricoPedidos;
}
public function addHistoricoPedido(HistoricoPedido $historicoPedido): self
{
if (!$this->HistoricoPedidos->contains($historicoPedido)) {
$this->HistoricoPedidos[] = $historicoPedido;
$historicoPedido->setHistCretedBy($this);
}
return $this;
}
public function removeHistoricoPedido(HistoricoPedido $historicoPedido): self
{
if ($this->HistoricoPedidos->removeElement($historicoPedido)) {
// set the owning side to null (unless already changed)
if ($historicoPedido->getHistCretedBy() === $this) {
$historicoPedido->setHistCretedBy(null);
}
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(?string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): self
{
$this->company = $company;
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(?string $language): self
{
$this->language = $language;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getPhonePre(): ?string
{
return $this->phonePre;
}
public function setPhonePre(?string $phonePre): self
{
$this->phonePre = $phonePre;
return $this;
}
/**
* @return Collection<int, Gradeada>
*/
public function getUsuGradeada(): Collection
{
return $this->UsuGradeada;
}
public function addUsuGradeada(Gradeada $usuGradeada): self
{
if (!$this->UsuGradeada->contains($usuGradeada)) {
$this->UsuGradeada[] = $usuGradeada;
$usuGradeada->setGradCliente($this);
}
return $this;
}
public function removeUsuGradeada(Gradeada $usuGradeada): self
{
if ($this->UsuGradeada->removeElement($usuGradeada)) {
// set the owning side to null (unless already changed)
if ($usuGradeada->getGradCliente() === $this) {
$usuGradeada->setGradCliente(null);
}
}
return $this;
}
/**
* @return Collection<int, Direccion>
*/
public function getDirecciones(): Collection
{
return $this->direcciones;
}
public function addDireccione(Direccion $direccione): self
{
if (!$this->direcciones->contains($direccione)) {
$this->direcciones[] = $direccione;
$direccione->setDirUser($this);
}
return $this;
}
public function removeDireccione(Direccion $direccione): self
{
if ($this->direcciones->removeElement($direccione)) {
// set the owning side to null (unless already changed)
if ($direccione->getDirUser() === $this) {
$direccione->setDirUser(null);
}
}
return $this;
}
public function getUsuarioValidacionEmailsFilter(?int $page = 1, ?int $limit = 12, ?array $order = [], ?array $data = []): Collection
{
$criteria = Criteria::create();
$page = (null === $page ? 0 : ($page > 0 ? $page - 1 : $page));
$limit = (null === $limit ? 12 : $limit);
$order = (null === $order ? [] : $order);
$data = (null === $data ? [] : $data);
if (count($data) > 0) {
if (isset($data['horas'])) {
$criteria->where(
Criteria::expr()->gte('created', (new \Datetime(' -'.$data['horas'].'hour')))
);
}
}
if ($page > 0 && $limit > 0) {
$criteria->setFirstResult($page)->setMaxResults($limit);
}
if (count($order) > 0) {
$criteria->orderBy($order);
}
return $this->UsuEmailValidation->matching($criteria);
}
/**
* @return Collection<int, UsuarioValidacionEmail>
*/
public function getUsuEmailValidation(): Collection
{
return $this->UsuEmailValidation;
}
public function addUsuEmailValidation(UsuarioValidacionEmail $usuEmailValidation): self
{
if (!$this->UsuEmailValidation->contains($usuEmailValidation)) {
$this->UsuEmailValidation[] = $usuEmailValidation;
$usuEmailValidation->setIdUser($this);
}
return $this;
}
public function removeUsuEmailValidation(UsuarioValidacionEmail $usuEmailValidation): self
{
if ($this->UsuEmailValidation->removeElement($usuEmailValidation)) {
// set the owning side to null (unless already changed)
if ($usuEmailValidation->getIdUser() === $this) {
$usuEmailValidation->setIdUser(null);
}
}
return $this;
}
public function getCorreoVerificado(): ?bool
{
return $this->correoVerificado;
}
public function setCorreoVerificado(bool $correoVerificado): self
{
$this->correoVerificado = $correoVerificado;
return $this;
}
public function getUsuDni(): ?string
{
return $this->UsuDni;
}
public function setUsuDni(?string $UsuDni): self
{
$this->UsuDni = $UsuDni;
return $this;
}
/**
* @return Collection<int, Pedido>
*/
public function getUsuPedidos(): Collection
{
return $this->UsuPedidos;
}
public function addUsPedido(Pedido $usPedido): self
{
if (!$this->UsuPedidos->contains($usPedido)) {
$this->UsuPedidos[] = $usPedido;
$usPedido->setPedUsuario($this);
}
return $this;
}
public function removeUsPedido(Pedido $usPedido): self
{
if ($this->UsuPedidos->removeElement($usPedido)) {
// set the owning side to null (unless already changed)
if ($usPedido->getPedUsuario() === $this) {
$usPedido->setPedUsuario(null);
}
}
return $this;
}
/**
* @return Collection<int, Descuento>
*/
public function getUsuCodDescuentos(): Collection
{
return $this->UsuCodDescuentos;
}
public function addUsuCodDescuento(Descuento $usuCodDescuento): self
{
if (!$this->UsuCodDescuentos->contains($usuCodDescuento)) {
$this->UsuCodDescuentos[] = $usuCodDescuento;
$usuCodDescuento->setDesUsuario($this);
}
return $this;
}
public function removeUsuCodDescuento(Descuento $usuCodDescuento): self
{
if ($this->UsuCodDescuentos->removeElement($usuCodDescuento)) {
// set the owning side to null (unless already changed)
if ($usuCodDescuento->getDesUsuario() === $this) {
$usuCodDescuento->setDesUsuario(null);
}
}
return $this;
}
public function getUsuComentarioDescuento(): ?string
{
return $this->UsuComentarioDescuento;
}
public function setUsuComentarioDescuento(?string $UsuComentarioDescuento): self
{
$this->UsuComentarioDescuento = $UsuComentarioDescuento;
return $this;
}
public function getUsuAlbumToken(): ?string
{
return $this->UsuAlbumToken;
}
public function setUsuAlbumToken(?string $UsuAlbumToken): self
{
$this->UsuAlbumToken = $UsuAlbumToken;
return $this;
}
/**
* @return Collection<int, HistComisiones>
*/
public function getUsuPedidoHistComisiones(): Collection
{
return $this->UsuPedidoHistComisiones;
}
public function addUsuPedidoHistComisione(HistComisiones $usuPedidoHistComisione): self
{
if (!$this->UsuPedidoHistComisiones->contains($usuPedidoHistComisione)) {
$this->UsuPedidoHistComisiones[] = $usuPedidoHistComisione;
$usuPedidoHistComisione->setHistComPedUsuario($this);
}
return $this;
}
public function removeUsuPedidoHistComisione(HistComisiones $usuPedidoHistComisione): self
{
if ($this->UsuPedidoHistComisiones->removeElement($usuPedidoHistComisione)) {
// set the owning side to null (unless already changed)
if ($usuPedidoHistComisione->getHistComPedUsuario() === $this) {
$usuPedidoHistComisione->setHistComPedUsuario(null);
}
}
return $this;
}
/**
* @return Collection<int, HistComisiones>
*/
public function getUsuHistComisiones(): Collection
{
return $this->UsuHistComisiones;
}
public function addUsuHistComisione(HistComisiones $usuHistComisione): self
{
if (!$this->UsuHistComisiones->contains($usuHistComisione)) {
$this->UsuHistComisiones[] = $usuHistComisione;
$usuHistComisione->setHistComUsuario($this);
}
return $this;
}
public function removeUsuHistComisione(HistComisiones $usuHistComisione): self
{
if ($this->UsuHistComisiones->removeElement($usuHistComisione)) {
// set the owning side to null (unless already changed)
if ($usuHistComisione->getHistComUsuario() === $this) {
$usuHistComisione->setHistComUsuario(null);
}
}
return $this;
}
public function getUsuOldId(): ?string
{
return $this->UsuOldId;
}
public function setUsuOldId(?string $UsuOldId): self
{
$this->UsuOldId = $UsuOldId;
return $this;
}
public function getUsuOldPassword(): ?string
{
return $this->UsuOldPassword;
}
public function setUsuOldPassword(?string $UsuOldPassword): self
{
$this->UsuOldPassword = $UsuOldPassword;
return $this;
}
public function getUsuDesServicios(): ?string
{
return $this->UsuDesServicios;
}
public function setUsuDesServicios(?string $UsuDesServicios): self
{
$this->UsuDesServicios = $UsuDesServicios;
return $this;
}
public function getUsuDesProductos(): ?string
{
return $this->UsuDesProductos;
}
public function setUsuDesProductos(?string $UsuDesProductos): self
{
$this->UsuDesProductos = $UsuDesProductos;
return $this;
}
public function getUsuDesEnvio(): ?string
{
return $this->UsuDesEnvio;
}
public function setUsuDesEnvio(?string $UsuDesEnvio): self
{
$this->UsuDesEnvio = $UsuDesEnvio;
return $this;
}
/**
* @return Collection<int, Gradeada>
*/
public function getUsuGradLotesRecCartas(): Collection
{
return $this->UsuGradLotesRecCartas;
}
public function addUsuGradLotesRecCarta(Gradeada $usuGradLotesRecCarta): self
{
if (!$this->UsuGradLotesRecCartas->contains($usuGradLotesRecCarta)) {
$this->UsuGradLotesRecCartas[] = $usuGradLotesRecCarta;
$usuGradLotesRecCarta->setGradLotesRecBy($this);
}
return $this;
}
public function removeUsuGradLotesRecCarta(Gradeada $usuGradLotesRecCarta): self
{
if ($this->UsuGradLotesRecCartas->removeElement($usuGradLotesRecCarta)) {
// set the owning side to null (unless already changed)
if ($usuGradLotesRecCarta->getGradLotesRecBy() === $this) {
$usuGradLotesRecCarta->setGradLotesRecBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Gradeada>
*/
public function getUsuGradLotesEnvCartas(): Collection
{
return $this->UsuGradLotesEnvCartas;
}
public function addUsuGradLotesEnvCarta(Gradeada $usuGradLotesEnvCarta): self
{
if (!$this->UsuGradLotesEnvCartas->contains($usuGradLotesEnvCarta)) {
$this->UsuGradLotesEnvCartas[] = $usuGradLotesEnvCarta;
$usuGradLotesEnvCarta->setGradLotesEnvBy($this);
}
return $this;
}
public function removeUsuGradLotesEnvCarta(Gradeada $usuGradLotesEnvCarta): self
{
if ($this->UsuGradLotesEnvCartas->removeElement($usuGradLotesEnvCarta)) {
// set the owning side to null (unless already changed)
if ($usuGradLotesEnvCarta->getGradLotesEnvBy() === $this) {
$usuGradLotesEnvCarta->setGradLotesEnvBy(null);
}
}
return $this;
}
}