src/AppBundle/Entity/Usuario.php line 28
<?php
namespace AppBundle\Entity;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Table(name="usuario")
* @ORM\Entity(repositoryClass="AppBundle\Repository\UsuarioRepository")
* @ORM\HasLifecycleCallbacks()
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="email",
* column=@ORM\Column(
* type="string",
* name="email",
* length=255,
* unique=false,
* nullable=true
* )
* )
* })
*/
class Usuario implements UserInterface, PasswordAuthenticatedUserInterface
{
const ROL_USUARIO = 'ROLE_USER';
const ROL_EMPRESA = 'ROLE_EMPRESA';
const ROL_VENTAS = 'ROLE_VENTAS';
const ROL_RESPCU = 'ROLE_RESPCU';
const ROLE_CONTENIDOS = 'ROLE_CONTENIDOS';
const ROLE_CONTABILIDAD_E_IMPUESTOS = 'ROLE_CONTABILIDAD_E_IMPUESTOS';
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
const ROLE_DEVELOPER = 'ROLE_DEVELOPER';
const ROLE_ABAP = 'ROLE_ABAP';
const ROLE_PROVEEDOR = 'ROLE_PROVEEDOR';
const ROLE_PROVEEDOR_EMPRESA = 'ROLE_PROVEEDOR_EMPRESA';
const ROLE_GERENTE = 'ROLE_GERENTE';
const ROLE_KONNEN = 'ROLE_KONNEN';
const ROLES = [
self::ROL_USUARIO,
self::ROL_EMPRESA,
self::ROL_VENTAS,
self::ROL_RESPCU,
self::ROLE_CONTENIDOS,
self::ROLE_CONTABILIDAD_E_IMPUESTOS,
self::ROLE_SUPER_ADMIN,
self::ROLE_DEVELOPER,
self::ROLE_ABAP,
self::ROLE_PROVEEDOR,
self::ROLE_PROVEEDOR_EMPRESA,
self::ROLE_GERENTE,
self::ROLE_KONNEN,
];
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Assert\NotBlank()
* @Assert\Length(
* min=3,
* max=255,
* minMessage="El nombre es corto.",
* maxMessage="El nombre es largo.",
* groups={"Registration", "Profile"}
* )
* @ORM\Column(name="username", type="string", length=255, nullable=true)
*/
protected $username;
/**
* @Assert\NotBlank()
* @Assert\Email()
* @ORM\Column(name="email", type="string", length=255, nullable=true)
*/
protected $email;
/**
* @var string
*
* @Assert\Length(
* min=6,
* max=255,
* minMessage="La contraseƱa debe tener como mĆnimo {{ limit }} caracteres",
* maxMessage="La contraseƱa no puede exceder los {{ limit }} caracteres."
* )
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* Plain password. Used for model validation. Must not be persisted.
*
* @var string
*/
protected $plainPassword;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=40, nullable=true)
*/
protected $name;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=40, nullable=true)
*/
protected $lastname;
/**
* @var string
*
* @ORM\Column(name="sap_id", type="string", length=12)
*/
protected $sapId = '';
protected $proveedorId = '';
/**
* @var string
*
* @ORM\Column(name="deleted", type="boolean", nullable=true)
*/
protected $deleted = false;
/**
* @ORM\ManyToOne(targetEntity="Empresa", inversedBy="usuarios")
* @ORM\JoinColumn(name="empresa_id", referencedColumnName="id", nullable=true)
*/
protected $empresa;
/**
* @ORM\ManyToOne(targetEntity="Proveedor", inversedBy="usuarios")
* @ORM\JoinColumn(name="proveedor_id", referencedColumnName="id", nullable=true)
*/
protected $proveedor;
/**
* @var bool
*
* @ORM\Column(name="accepted_terms", type="boolean", nullable=true)
*/
protected $acceptedTerms = false;
/**
* @var bool
*
* @ORM\Column(name="accepted_mailing", type="boolean", nullable=true)
*/
protected $acceptedMailing = false;
/**
* @var bool
*
* @ORM\Column(name="aviso_echeq", type="boolean", nullable=false)
*/
protected $avisoEcheq = true;
/**
* @var string
*
* @ORM\Column(name="telefono", type="string", length=30, nullable=true)
*/
protected $telefono;
/**
* @var string
*
* @ORM\Column(name="dni", type="string", length=30, nullable=true)
*/
protected $dni;
/**
* @var datetime
*
* @ORM\Column(name="fecha_alta", type="datetime", nullable=true)
*/
protected $fechaAlta;
/**
* @var bool
*
* @ORM\Column(name="debug", type="boolean", nullable=false)
*/
protected $debug = false;
/**
* @ORM\Column(name="id_debug", type="integer", nullable=true)
*/
protected $idDebug;
/**
* @ORM\Column(name="password_seteada", type="boolean", nullable=true)
*/
protected $passwordSeteada;
/**
* @ORM\Column(name="password_vencida", type="boolean", nullable=true)
*/
protected $passwordVencida;
/**
* @var datetime
*
* @ORM\Column(name="password_last_update", type="datetime", nullable=true)
*/
protected $passwordLastUpdate;
/**
* @ORM\Column(type="json")
*/
protected $roles;
/**
* @var string
*
* @ORM\Column(name="enabled", type="boolean", nullable=true)
*/
protected $enabled = false;
/**
* @var string
*
* @ORM\Column(name="confirmation_token", type="string", length=180, nullable=false)
*/
private $confirmationToken;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255, nullable=true)
*/
private $salt;
/**
* @var datetime
*
* @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
*/
private $password_requested_at;
/**
* @var datetime
*
* @ORM\Column(name="last_login", type="datetime", nullable=true)
*/
protected $lastLogin;
public function __construct()
{
}
public function getId()
{
if($this->debug){
return $this->idDebug;
}
return $this->id;
}
/**
* @Assert\IsTrue(message = "La contraseƱa no puede ser igual al nombre de usuario")
*/
public function isPasswordLegal()
{
return $this->username !== $this->plainPassword;
}
/**
* @ORM\PrePersist
*/
public function updatedTimestamp()
{
if ($this->getFechaAlta() === null) {
$this->setFechaAlta(new \DateTime('now'));
}
}
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Set empresa.
*
* @param string $empresa
*
* @return Empresa
*/
public function setEmpresa($empresa)
{
$this->empresa = $empresa;
return $this;
}
/**
* Get empresa.
*
* @return Empresa
*/
public function getEmpresa()
{
return $this->empresa;
}
/**
* Set proveedor.
*
* @param string $proveedor
*
* @return Usuario
*/
public function setProveedor($proveedor)
{
$this->proveedor = $proveedor;
return $this;
}
/**
* Get proveedor.
*
* @return Proveedor
*/
public function getProveedor()
{
return $this->proveedor;
}
/**
* Set name.
*
* @param string $name
*
* @return Usuario
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set lastname.
*
* @param string $lastname
*
* @return Usuario
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname.
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Get lastname + name.
*
* @return string
*/
public function getFullname()
{
return $this->name .' '. $this->lastname;
}
public function getDeleted()
{
return $this->deleted;
}
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
public function setEmail($email)
{
$this->email = $email;
$this->username = $email;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function getSapId()
{
return $this->sapId;
}
public function setSapId($sapId)
{
$this->sapId = $sapId;
return $this;
}
public function getProveedorId()
{
return $this->proveedorId;
}
public function setProveedorId($proveedorId)
{
$this->proveedorId = $proveedorId;
return $this;
}
public function getAcceptedTerms()
{
return $this->acceptedTerms;
}
public function setAcceptedTerms($acceptedTerms)
{
$this->acceptedTerms = $acceptedTerms;
return $this;
}
public function getAvisoEcheq()
{
return $this->avisoEcheq;
}
public function setAvisoEcheq($avisoEcheq)
{
$this->avisoEcheq = $avisoEcheq;
return $this;
}
public function getTelefono()
{
return $this->telefono;
}
public function setTelefono($telefono)
{
$this->telefono = $telefono;
return $this;
}
public function getDni()
{
return $this->dni;
}
public function setDni($dni)
{
$this->dni = $dni;
return $this;
}
public function getAcceptedMailing()
{
return $this->acceptedMailing;
}
public function setAcceptedMailing($acceptedMailing)
{
$this->acceptedMailing = $acceptedMailing;
return $this;
}
public function esVendedorFamiq()
{
if (in_array('ROLE_RESPCU', $this->getRoles()) || in_array('ROLE_VENTAS', $this->getRoles())) {
return true;
}
return false;
}
public function esEmpresa()
{
if (in_array('ROLE_EMPRESA', $this->getRoles()) || in_array('ROLE_PROVEEDOR_EMPRESA', $this->getRoles())) {
return true;
}
return false;
}
// TODO: Corregir verificaciĆ³n de roles
public function esProveedor()
{
if (in_array('ROLE_CUENTAS_A_PAGAR', $this->getRoles()) || in_array('ROLE_SUPER_ADMIN', $this->getRoles()) ||
in_array('ROLE_DEVELOPER', $this->getRoles()) || in_array('ROLE_ABAP', $this->getRoles()) ||
in_array('ROLE_PROVEEDOR', $this->getRoles()) || in_array('ROLE_PROVEEDOR_EMPRESA', $this->getRoles()))
{
return true;
}
return false;
}
/**
* Este mĆ©todo debe ser renombrado ya que no cumple con la definiciĆ³n
*/
public function esVendedor()
{
if (in_array('ROLE_RESPCU', $this->getRoles()) || in_array('ROLE_VENTAS', $this->getRoles()) ||
in_array('ROLE_CONTENIDOS', $this->getRoles()) || in_array('ROLE_SUPER_ADMIN', $this->getRoles()) ||
in_array('ROLE_CONTABILIDAD_E_IMPUESTOS', $this->getRoles()) || in_array('ROLE_SUPER_ADMIN', $this->getRoles()) ||
in_array('ROLE_DEVELOPER', $this->getRoles()) || in_array('ROLE_ABAP', $this->getRoles()) ||
in_array('ROLE_PLANEAMIENTO', $this->getRoles()) || in_array('ROLE_GERENTE', $this->getRoles())) {
return true;
}
return false;
}
/**
* Return if user is admin or super admin
* @return bool
*/
public function isAdminOrSuperAdmin()
{
if (in_array(self::ROLE_CONTENIDOS, $this->getRoles()) ||
in_array(self::ROLE_CONTABILIDAD_E_IMPUESTOS, $this->getRoles()) ||
in_array(self::ROLE_SUPER_ADMIN, $this->getRoles()) ||
in_array(self::ROLE_DEVELOPER, $this->getRoles()) ||
in_array(self::ROLE_ABAP, $this->getRoles())
) {
return true;
}
return false;
}
/**
* Return if user is developer
* @return bool
*/
public function isDeveloper()
{
if (in_array(self::ROLE_DEVELOPER, $this->getRoles())) {
return true;
}
return false;
}
/**
* Return if user is esKonnen
* @return bool
*/
public function esKonnen()
{
if (in_array(self::ROLE_KONNEN, $this->getRoles())) {
return true;
}
return false;
}
/**
* * Verifica si el usuario es rol cuentas a pagar.
* @return bool
*/
public function esCuentasAPagar()
{
return in_array('ROLE_CUENTAS_A_PAGAR', $this->getRoles());
}
public function estaActivo()
{
return !$this->deleted && $this->enabled;
}
public function esConsumidorFinal() {
$empresa = $this->empresa;
if (is_null($empresa)) {
return false;
}
return $empresa->esConsumidorFinal();
}
/**
* A partir de este deploy, los nuevos consumidores finales
* pueden comprar, por lo que hay que distinguirlos de los viejos
*
* Antes -> consumidores finales dados de alta por la PIN se cargaban con el id de empresa 600000
*
* Ahora -> consumidores finales dados de alta por la PIN se cargaban con el id de empresa PROPIO (generado en ese alta)
*
*
* esConsumidorFinalNew devuelve si es un consumidor final con su propio id de cliente
*/
public function esConsumidorFinalNew() {
$empresa = $this->empresa;
if (is_null($empresa)) {
return false;
}
return $empresa->esConsumidorFinalNew();
}
public function getNombreCompleto()
{
return $this->name . ' ' .$this->lastname;
}
public function getNombreCompletoTruncated()
{
$nombreCompleto = $this->getNombreCompleto();
$out = strlen($nombreCompleto) > 15 ? substr($nombreCompleto, 0, 15).'...' : $nombreCompleto;
return $out;
}
public function getFechaAlta()
{
return $this->fechaAlta;
}
public function setFechaAlta($fechaAlta)
{
$this->fechaAlta = $fechaAlta;
return $this;
}
public function getRoles(): array
{
$roles = $this->roles;
// we need to make sure to have at least one role
$roles[] = self::ROL_USUARIO;
return array_values(array_unique($roles));
}
public function setPasswordSeteada ($passwordSeteada) {
$this->passwordSeteada = $passwordSeteada;
return $this;
}
/**
*
*/
public function necesitaPassword() {
return $this->passwordSeteada == null;
}
/**
* Si el usuario tiene password vencida, se obliga a reestablecerla
*/
public function getPasswordVencida(){
return $this->passwordVencida;
}
/**
* Si el usuario modifica su password, la "desvenso"
*/
public function setPasswordVencida($passwordVencidaBoolVal){
$this->passwordVencida = $passwordVencidaBoolVal;
return $this;
}
public function getPasswordLastUpdate () {
return $this->passwordLastUpdate;
}
public function updatePasswordLastUpdate () {
$this->passwordLastUpdate = new \DateTime('now');;
return $this;
}
/**
* //Heredo la funciĆ³n para modificar el passwordLastUpdate
* {@inheritdoc}
*/
public function setPassword($password)
{
$this->password = $password;
if (!empty($password)) {
$this->updatePasswordLastUpdate();
}
return $this;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials(){
}
/**
* Returns the identifier for this user (e.g. its username or email address).
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function getUsername()
{
return $this->username;
}
/**
* Set confirmationToken.
*
* @param string $confirmationToken
*
* @return Usuario
*/
public function setConfirmationToken($confirmation_token)
{
$this->confirmationToken = $confirmation_token;
return $this;
}
/**
* Get confirmationToken.
*
* @return string
*/
public function getConfirmationToken()
{
return $this->confirmationToken;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function isAcceptedTerms(): ?bool
{
return $this->acceptedTerms;
}
public function isAvisoEcheq(): ?bool
{
return $this->avisoEcheq;
}
public function isAcceptedMailing(): ?bool
{
return $this->acceptedMailing;
}
public function isDebug(): ?bool
{
return $this->debug;
}
public function setDebug(bool $debug): self
{
$this->debug = $debug;
return $this;
}
public function getIdDebug(): ?int
{
return $this->idDebug;
}
public function setIdDebug(?int $idDebug): self
{
$this->idDebug = $idDebug;
return $this;
}
public function isPasswordSeteada(): ?bool
{
return $this->passwordSeteada;
}
public function isPasswordVencida(): ?bool
{
return $this->passwordVencida;
}
public function setPasswordLastUpdate(?\DateTimeInterface $passwordLastUpdate): self
{
$this->passwordLastUpdate = $passwordLastUpdate;
return $this;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getSalt(): ?string
{
return $this->salt;
}
public function setSalt(?string $salt): self
{
$this->salt = $salt;
return $this;
}
public function getPasswordRequestedAt(): ? \DateTimeInterface
{
return $this->password_requested_at;
}
public function setPasswordRequestedAt(?\DateTimeInterface $password_requested_at): self
{
$this->password_requested_at = $password_requested_at;
return $this;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
return $this;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setLastLogin($date)
{
$this->lastLogin = $date;
return $this;
}
public function __toArray(): array
{
return array(
'id' => $this->id,
'username' => $this->username,
'email' => $this->email,
'name' => $this->name,
'lastname' => $this->lastname,
'sapId' => $this->sapId,
'proveedorId' => $this->proveedorId,
'deleted' => $this->deleted,
'proveedor' => $this->proveedor,
'acceptedTerms' => $this->acceptedTerms,
'acceptedMailing' => $this->acceptedMailing,
'avisoEcheq' => $this->avisoEcheq,
'telefono' => $this->telefono,
'dni' => $this->dni,
'fechaAlta' => $this->fechaAlta,
'roles' => $this->roles,
'enabled' => $this->enabled,
'lastLogin' => $this->lastLogin,
'esVendedor' => $this->esVendedor(),
'necesitaPassword' => $this->necesitaPassword()
);
}
public function getFamiqUsername(): string
{
$username = $this->getUsername();
return explode("@", $username)[0];
}
}