<?php
namespace App\Entity;
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\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"username"})
* @UniqueEntity(fields={"email"})
* @Vich\Uploadable
*/
class User implements UserInterface, EquatableInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank( message="No puede estar vacio")
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=50)
* @Assert\NotBlank(message="No puede estar vacio")
*/
private $nomComplet;
/**
* @ORM\Column(type="string", length=100, unique=true)
* @Assert\NotBlank(message="No puede estar vacio")
* @Assert\Email(message="Email inválido")
*/
private $email;
/**
* @ORM\Column(type="boolean")
*/
private $valid;
/**
* @ORM\Column(type="boolean")
*/
private $deleted;
/**
* @ORM\Column(type="string", length=255))
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $admin;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaActualizacion;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $documentoName;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Assert\File(
* maxSize = "200Mi",
* mimeTypes={ "image/*" }
* )
* @Vich\UploadableField(mapping="usuarios_perfil", fileNameProperty="documentoName")
* @var File
*/
private $documentoFile;
/**
* @ORM\ManyToOne(targetEntity=Conductor::class)
*/
private $conductor;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $verInformeGestionRuta;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $gestionarDesviaciones;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $solicitudRetiro;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $cerrarOrdenes;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaCreacion;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaUltimoLogin;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaCambioClave;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaBloqueoClave;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $contadorLoginFallido;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaLoginFallido;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaExpiracionClave;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaNotificacionExpiracionClave;
/**
* @ORM\ManyToMany(targetEntity=Cliente::class, inversedBy="usuarios")
*/
private $clientes;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $esSoporteProgramador;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $esSoporteAutorizador;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $puedeCorregirOrdenes;
/**
* @ORM\ManyToMany(targetEntity=ClienteFinal::class)
*/
private $clientesFinales;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $esEjecutiva;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $puedeAccederAdministracion;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $carteraClientes;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $puedeEliminarOrdenes;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $tieneAccesoSoporte;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $tieneAccesoComercial;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $tieneAccesoDesviacionProveedor;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $puedeCrearDirecciones;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $tieneAccesoLogisticaReversa;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $modificarOrden = false;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $reactivarOrden = false;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $accesoTemperatura = false;
/**
* @ORM\ManyToOne(targetEntity=Agencia::class)
*/
private $agencia;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $administrarEstadosOrden;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $gopeSiemensDedicado;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $puedeActualizarOrdenes;
public function isModificarOrden(): ?bool
{
return $this->modificarOrden;
}
public function setModificarOrden(?bool $modificarOrden): self
{
$this->modificarOrden = $modificarOrden;
return $this;
}
public function isReactivarOrden(): ?bool
{
return $this->reactivarOrden;
}
public function setReactivarOrden(?bool $reactivarOrden): self
{
$this->reactivarOrden = $reactivarOrden;
return $this;
}
public function isCarteraClientes(): ?bool
{
return $this->carteraClientes;
}
public function setCarteraClientes(?bool $carteraClientes): self
{
$this->carteraClientes = $carteraClientes;
return $this;
}
public function isAccesoTemperatura(): ?bool
{
return $this->accesoTemperatura;
}
public function setAccesoTemperatura(?bool $accesoTemperatura): self
{
$this->accesoTemperatura = $accesoTemperatura;
return $this;
}
public function getDocumentoNameOriginal()
{
$docName = $this->getDocumentoName();
if($docName)
{
$posName = strrpos($docName, '-');
$posExt = strrpos($docName, '.');
if($posName && $posExt)
{
$name = substr($docName, 0, $posName);
$ext = substr($docName, $posExt);
return $name.$ext;
}
}
return $docName;
}
public function __construct()
{
$this->clientes = new ArrayCollection();
$this->clientesFinales = new ArrayCollection();
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $documento
*
* @return Product
*/
public function setDocumentoFile(?File $documento = null): void
{
$this->documentoFile = $documento;
if ($documento) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->fechaActualizacion = new \DateTimeImmutable(null);
}
}
/**
* @return File|null
*/
public function getDocumentoFile(): ?File
{
return $this->documentoFile;
}
public function getDocumentoName(): ?string
{
return $this->documentoName;
}
public function setDocumentoName(?string $documentoName = ""): self
{
$this->documentoName = $documentoName;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername($username): self
{
$this->username = $username;
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
if (in_array('ROLE_CLIENTE', $roles)) {
foreach($this->getClientes() as $cliente)
{
if($cliente->getPuedeAgregarOrdenes())
{
$roles[] = 'ROLE_CLIENTE_ORDEN';
}
if($cliente->getMostrarMatrizTransito())
{
$roles[] = 'ROLE_CLIENTE_MATRIZ_TRANSITO';
}
if($cliente->isIntegracionCaribean())
{
$roles[] = 'ROLE_CARIBEAN';
}
if($cliente->isIntegracionDhl())
{
$roles[] = 'ROLE_DHL';
}
if($cliente->isGrifolsDedicado())
{
$roles[] = 'ROLE_GRIFOLS_DEDICADO';
}
if($this->isGopeSiemensDedicado())
{
$roles[] = 'ROLE_GRIFOLS_DEDICADO';
$roles[] = 'ROLE_GOPE_SIEMENS_DEDICADO';
}
}
}
if($this->getVerInformeGestionRuta())
{
$roles[] = 'ROLE_INFORME_GESTION_RUTA';
}
if($this->getGestionarDesviaciones())
{
$roles[] = 'ROLE_GESTIONAR_DESVIACIONES';
}
if($this->isEsSoporteProgramador())
{
$roles[] = 'ROLE_SOPORTE_PROGRAMADOR';
}
if($this->isEsSoporteAutorizador())
{
$roles[] = 'ROLE_SOPORTE_AUTORIZADOR';
}
if($this->isPuedeCorregirOrdenes())
{
$roles[] = 'ROLE_CORREGIR_ORDENES';
}
elseif($this->isPuedeActualizarOrdenes())
{
$roles[] = 'ROLE_ACTUALIZAR_ORDENES';
}
if($this->getSolicitudRetiro())
{
$roles[] = 'ROLE_EJECUTIVA_TRANSFARMA';
}
if($this->isPuedeAccederAdministracion())
{
$roles[] = 'ROLE_MODULO_ADMINISTRACION';
}
if($this->isPuedeEliminarOrdenes())
{
$roles[] = 'ROLE_ELIMINAR_ORDENES';
}
if($this->isTieneAccesoSoporte())
{
$roles[] = 'ROLE_ACCESO_SOPORTE';
}
if($this->isTieneAccesoComercial())
{
$roles[] = 'ROLE_ACCESO_COMERCIAL';
}
if($this->isTieneAccesoDesviacionProveedor())
{
$roles[] = 'ROLE_ACCESO_DESVIACION_PROVEEDOR';
}
if($this->isPuedeCrearDirecciones())
{
$roles[] = 'ROLE_CREAR_DIRECCIONES';
}
if($this->isTieneAccesoLogisticaReversa())
{
$roles[] = 'ROLE_ACCESO_LOGISTICA_REVERSA';
}
if($this->isAdministrarEstadosOrden())
{
$roles[] = 'ROLE_ADMINISTRAR_ESTADO_ORDEN';
}
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword()
{
return $this->password;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed for apps that do not check user passwords
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getNomComplet(): ?string
{
return $this->nomComplet;
}
public function setNomComplet( $nomComplet): self
{
$this->nomComplet = $nomComplet;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail( $email): self
{
$this->email = $email;
return $this;
}
public function isValid(): ?bool
{
return $this->valid;
}
public function setValid(bool $valid): self
{
$this->valid = $valid;
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function setPassword($password): self
{
$this->password = $password;
return $this;
}
function getColorCode() {
$code = dechex(crc32($this->getUsername()));
$code = substr($code, 0, 6);
return "#".$code;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
/*if (strlen($this->password)< 3){
$context->buildViolation('Mot de passe trop court')
->atPath('justpassword')
->addViolation();
}*/
}
public function __toString()
{
return $this->nomComplet;
}
public function isAdmin(): ?bool
{
return $this->admin;
}
public function setAdmin(bool $admin): self
{
$this->admin = $admin;
return $this;
}
public function isEqualTo(UserInterface $user)
{
if ($user instanceof User)
return $this->isValid() && !$this->isDeleted() && $this->getPassword() == $user->getPassword() && $this->getUsername() == $user->getUsername()
&& $this->getEmail() == $user->getEmail() ;
}
public function getConductor(): ?Conductor
{
return $this->conductor;
}
public function setConductor(?Conductor $conductor): self
{
$this->conductor = $conductor;
return $this;
}
public function isEsEjecutiva(): ?bool
{
return $this->esEjecutiva;
}
public function setEsEjecutiva(?bool $esEjecutiva): self
{
$this->esEjecutiva = $esEjecutiva;
return $this;
}
public function getVerInformeGestionRuta(): ?bool
{
return $this->verInformeGestionRuta;
}
public function setVerInformeGestionRuta(?bool $verInformeGestionRuta): self
{
$this->verInformeGestionRuta = $verInformeGestionRuta;
return $this;
}
public function getGestionarDesviaciones(): ?bool
{
return $this->gestionarDesviaciones;
}
public function setGestionarDesviaciones(?bool $gestionarDesviaciones): self
{
$this->gestionarDesviaciones = $gestionarDesviaciones;
return $this;
}
public function getSolicitudRetiro(): ?bool
{
return $this->solicitudRetiro;
}
public function setSolicitudRetiro(?bool $solicitudRetiro): self
{
$this->solicitudRetiro = $solicitudRetiro;
return $this;
}
public function getCerrarOrdenes(): ?bool
{
return $this->cerrarOrdenes;
}
public function setCerrarOrdenes(?bool $cerrarOrdenes): self
{
$this->cerrarOrdenes = $cerrarOrdenes;
return $this;
}
public function getFechaCreacion(): ?\DateTimeInterface
{
return $this->fechaCreacion;
}
public function setFechaCreacion(?\DateTimeInterface $fechaCreacion): self
{
$this->fechaCreacion = $fechaCreacion;
return $this;
}
public function getFechaUltimoLogin(): ?\DateTimeInterface
{
return $this->fechaUltimoLogin;
}
public function setFechaUltimoLogin(?\DateTimeInterface $fechaUltimoLogin): self
{
$this->fechaUltimoLogin = $fechaUltimoLogin;
return $this;
}
public function getFechaCambioClave(): ?\DateTimeInterface
{
return $this->fechaCambioClave;
}
public function setFechaCambioClave(?\DateTimeInterface $fechaCambioClave): self
{
$this->fechaCambioClave = $fechaCambioClave;
return $this;
}
public function getFechaBloqueoClave(): ?\DateTimeInterface
{
return $this->fechaBloqueoClave;
}
public function setFechaBloqueoClave(?\DateTimeInterface $fechaBloqueoClave): self
{
$this->fechaBloqueoClave = $fechaBloqueoClave;
return $this;
}
public function getContadorLoginFallido(): ?int
{
return $this->contadorLoginFallido;
}
public function setContadorLoginFallido(?int $contadorLoginFallido): self
{
$this->contadorLoginFallido = $contadorLoginFallido;
return $this;
}
public function getFechaLoginFallido(): ?\DateTimeInterface
{
return $this->fechaLoginFallido;
}
public function setFechaLoginFallido(?\DateTimeInterface $fechaLoginFallido): self
{
$this->fechaLoginFallido = $fechaLoginFallido;
return $this;
}
public function getFechaExpiracionClave(): ?\DateTimeInterface
{
return $this->fechaExpiracionClave;
}
public function setFechaExpiracionClave(?\DateTimeInterface $fechaExpiracionClave): self
{
$this->fechaExpiracionClave = $fechaExpiracionClave;
return $this;
}
public function getFechaNotificacionExpiracionClave(): ?\DateTimeInterface
{
return $this->fechaNotificacionExpiracionClave;
}
public function setFechaNotificacionExpiracionClave(?\DateTimeInterface $fechaNotificacionExpiracionClave): self
{
$this->fechaNotificacionExpiracionClave = $fechaNotificacionExpiracionClave;
return $this;
}
/**
* @return Collection<int, Cliente>
*/
public function getClientes(): Collection
{
return $this->clientes;
}
public function addCliente(Cliente $cliente): self
{
if (!$this->clientes->contains($cliente)) {
$this->clientes[] = $cliente;
}
return $this;
}
public function removeCliente(Cliente $cliente): self
{
$this->clientes->removeElement($cliente);
return $this;
}
public function isEsSoporteProgramador(): ?bool
{
return $this->esSoporteProgramador;
}
public function setEsSoporteProgramador(?bool $esSoporteProgramador): self
{
$this->esSoporteProgramador = $esSoporteProgramador;
return $this;
}
public function isEsSoporteAutorizador(): ?bool
{
return $this->esSoporteAutorizador;
}
public function setEsSoporteAutorizador(?bool $esSoporteAutorizador): self
{
$this->esSoporteAutorizador = $esSoporteAutorizador;
return $this;
}
public function isPuedeCorregirOrdenes(): ?bool
{
return $this->puedeCorregirOrdenes;
}
public function setPuedeCorregirOrdenes(?bool $puedeCorregirOrdenes): self
{
$this->puedeCorregirOrdenes = $puedeCorregirOrdenes;
return $this;
}
/**
* @return Collection<int, ClienteFinal>
*/
public function getClientesFinales(): Collection
{
return $this->clientesFinales;
}
public function addClientesFinale(ClienteFinal $clientesFinale): self
{
if (!$this->clientesFinales->contains($clientesFinale)) {
$this->clientesFinales[] = $clientesFinale;
}
return $this;
}
public function removeClientesFinale(ClienteFinal $clientesFinale): self
{
$this->clientesFinales->removeElement($clientesFinale);
return $this;
}
public function isPuedeAccederAdministracion(): ?bool
{
return $this->puedeAccederAdministracion;
}
public function setPuedeAccederAdministracion(?bool $puedeAccederAdministracion): self
{
$this->puedeAccederAdministracion = $puedeAccederAdministracion;
return $this;
}
public function isPuedeEliminarOrdenes(): ?bool
{
return $this->puedeEliminarOrdenes;
}
public function setPuedeEliminarOrdenes(?bool $puedeEliminarOrdenes): self
{
$this->puedeEliminarOrdenes = $puedeEliminarOrdenes;
return $this;
}
public function isTieneAccesoSoporte(): ?bool
{
return $this->tieneAccesoSoporte;
}
public function setTieneAccesoSoporte(?bool $tieneAccesoSoporte): self
{
$this->tieneAccesoSoporte = $tieneAccesoSoporte;
return $this;
}
public function isTieneAccesoComercial(): ?bool
{
return $this->tieneAccesoComercial;
}
public function setTieneAccesoComercial(?bool $tieneAccesoComercial): self
{
$this->tieneAccesoComercial = $tieneAccesoComercial;
return $this;
}
public function isTieneAccesoDesviacionProveedor(): ?bool
{
return $this->tieneAccesoDesviacionProveedor;
}
public function setTieneAccesoDesviacionProveedor(?bool $tieneAccesoDesviacionProveedor): self
{
$this->tieneAccesoDesviacionProveedor = $tieneAccesoDesviacionProveedor;
return $this;
}
public function isPuedeCrearDirecciones(): ?bool
{
return $this->puedeCrearDirecciones;
}
public function setPuedeCrearDirecciones(?bool $puedeCrearDirecciones): self
{
$this->puedeCrearDirecciones = $puedeCrearDirecciones;
return $this;
}
public function isTieneAccesoLogisticaReversa(): ?bool
{
return $this->tieneAccesoLogisticaReversa;
}
public function setTieneAccesoLogisticaReversa(?bool $tieneAccesoLogisticaReversa): self
{
$this->tieneAccesoLogisticaReversa = $tieneAccesoLogisticaReversa;
return $this;
}
public function getAgencia(): ?Agencia
{
return $this->agencia;
}
public function setAgencia(?Agencia $agencia): self
{
$this->agencia = $agencia;
return $this;
}
public function isAdministrarEstadosOrden(): ?bool
{
return $this->administrarEstadosOrden;
}
public function setAdministrarEstadosOrden(?bool $administrarEstadosOrden): self
{
$this->administrarEstadosOrden = $administrarEstadosOrden;
return $this;
}
public function isGopeSiemensDedicado(): ?bool
{
return $this->gopeSiemensDedicado;
}
public function setGopeSiemensDedicado(?bool $gopeSiemensDedicado): self
{
$this->gopeSiemensDedicado = $gopeSiemensDedicado;
return $this;
}
public function isPuedeActualizarOrdenes(): ?bool
{
return $this->puedeActualizarOrdenes;
}
public function setPuedeActualizarOrdenes(?bool $puedeActualizarOrdenes): self
{
$this->puedeActualizarOrdenes = $puedeActualizarOrdenes;
return $this;
}
}