vendor/novosga/core/Entity/Usuario.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Novo SGA project.
  4.  *
  5.  * (c) Rogerio Lino <rogeriolino@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Novosga\Entity;
  11. use DateTime;
  12. use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
  13. use Symfony\Component\Security\Core\User\EquatableInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. /**
  16.  * Usuario
  17.  *
  18.  * @author Rogerio Lino <rogeriolino@gmail.com>
  19.  */
  20. class Usuario implements
  21.     \Serializable,
  22.     \JsonSerializable,
  23.     UserInterface,
  24.     EquatableInterface,
  25.     EncoderAwareInterface
  26. {
  27.     /**
  28.      * @var mixed
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @var string
  33.      */
  34.     private $login;
  35.     /**
  36.      * @var string
  37.      */
  38.     private $nome;
  39.     /**
  40.      * @var string
  41.      */
  42.     private $sobrenome;
  43.     /**
  44.      * @var string
  45.      */
  46.     private $email;
  47.     /**
  48.      * @var string
  49.      */
  50.     private $senha;
  51.     /**
  52.      * @var bool
  53.      */
  54.     private $ativo;
  55.     /**
  56.      * @var DateTime
  57.      */
  58.     private $ultimoAcesso;
  59.     /**
  60.      * @var string
  61.      */
  62.     private $ip;
  63.     /**
  64.      * @var string
  65.      */
  66.     private $sessionId;
  67.     /**
  68.      * @var Lotacao[]
  69.      */
  70.     private $lotacoes;
  71.     /**
  72.      * @var Lotacao
  73.      */
  74.     private $lotacao;
  75.     /**
  76.      * @var bool
  77.      */
  78.     private $admin;
  79.     /**
  80.      * @var string
  81.      */
  82.     private $algorithm;
  83.     /**
  84.      * @var string
  85.      */
  86.     private $salt;
  87.     /**
  88.      * @var array
  89.      */
  90.     private $roles = [];
  91.     /**
  92.      * @var \DateTime
  93.      */
  94.     private $createdAt;
  95.     /**
  96.      * @var \DateTime
  97.      */
  98.     private $updatedAt;
  99.     /**
  100.      * @var \DateTime
  101.      */
  102.     private $deletedAt;
  103.     public function __construct()
  104.     {
  105.         $this->ativo true;
  106.         $this->lotacoes = new \Doctrine\Common\Collections\ArrayCollection();
  107.     }
  108.     public function getId()
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function setId($id): self
  113.     {
  114.         $this->id $id;
  115.         return $this;
  116.     }
  117.     public function setLogin($login): self
  118.     {
  119.         $this->login $login;
  120.         return $this;
  121.     }
  122.     public function getLogin()
  123.     {
  124.         return $this->login;
  125.     }
  126.     public function setNome($nome): self
  127.     {
  128.         $this->nome $nome;
  129.         return $this;
  130.     }
  131.     public function getNome()
  132.     {
  133.         return $this->nome;
  134.     }
  135.     public function setSobrenome($sobrenome): self
  136.     {
  137.         $this->sobrenome $sobrenome;
  138.         return $this;
  139.     }
  140.     public function getSobrenome()
  141.     {
  142.         return $this->sobrenome;
  143.     }
  144.     /**
  145.      * Retorna o nome completo do usuario (nome + sobrenome).
  146.      *
  147.      * @return string
  148.      */
  149.     public function getNomeCompleto()
  150.     {
  151.         return $this->nome ' ' $this->sobrenome;
  152.     }
  153.     public function getEmail()
  154.     {
  155.         return $this->email;
  156.     }
  157.     public function setEmail($email): self
  158.     {
  159.         $this->email $email;
  160.         
  161.         return $this;
  162.     }
  163.     public function getSenha()
  164.     {
  165.         return $this->senha;
  166.     }
  167.     public function setSenha($senha): self
  168.     {
  169.         $this->senha $senha;
  170.         return $this;
  171.     }
  172.     public function setAtivo(bool $ativo): self
  173.     {
  174.         $this->ativo $ativo;
  175.         return $this;
  176.     }
  177.     public function getLotacao()
  178.     {
  179.         return $this->lotacao;
  180.     }
  181.     public function setLotacao(?Lotacao $lotacao): self
  182.     {
  183.         $this->lotacao $lotacao;
  184.         return $this;
  185.     }
  186.     public function getLotacoes()
  187.     {
  188.         return $this->lotacoes;
  189.     }
  190.     public function setSalt($salt): self
  191.     {
  192.         $this->salt $salt;
  193.         return $this;
  194.     }
  195.     public function setLotacoes($lotacoes): self
  196.     {
  197.         $this->lotacoes $lotacoes;
  198.         return $this;
  199.     }
  200.     public function addLotacoe(Lotacao $lotacao): self
  201.     {
  202.         $lotacao->setUsuario($this);
  203.         $this->getLotacoes()->add($lotacao);
  204.         return $this;
  205.     }
  206.     public function removeLotacoe(Lotacao $lotacao): self
  207.     {
  208.         $this->getLotacoes()->removeElement($lotacao);
  209.         return $this;
  210.     }
  211.     public function isAtivo(): bool
  212.     {
  213.         return (bool) $this->ativo;
  214.     }
  215.     public function getUltimoAcesso()
  216.     {
  217.         return $this->ultimoAcesso;
  218.     }
  219.     public function setUltimoAcesso($ultimoAcesso): self
  220.     {
  221.         $this->ultimoAcesso $ultimoAcesso;
  222.         return $this;
  223.     }
  224.     public function getIp()
  225.     {
  226.         return $this->ip;
  227.     }
  228.     public function setIp($ip): self
  229.     {
  230.         $this->ip $ip;
  231.         return $this;
  232.     }
  233.     public function getSessionId()
  234.     {
  235.         return $this->sessionId;
  236.     }
  237.     public function setSessionId($sessionId): self
  238.     {
  239.         $this->sessionId $sessionId;
  240.         return $this;
  241.     }
  242.     public function getAlgorithm()
  243.     {
  244.         return $this->algorithm;
  245.     }
  246.     public function setAlgorithm($algorithm): self
  247.     {
  248.         $this->algorithm $algorithm;
  249.         return $this;
  250.     }
  251.     public function isAdmin()
  252.     {
  253.         return $this->admin;
  254.     }
  255.     public function setAdmin($admin): self
  256.     {
  257.         $this->admin $admin;
  258.         return $this;
  259.     }
  260.     public function getCreatedAt()
  261.     {
  262.         return $this->createdAt;
  263.     }
  264.     public function getUpdatedAt()
  265.     {
  266.         return $this->updatedAt;
  267.     }
  268.     public function getDeletedAt()
  269.     {
  270.         return $this->deletedAt;
  271.     }
  272.     public function setCreatedAt(\DateTime $createdAt): self
  273.     {
  274.         $this->createdAt $createdAt;
  275.         return $this;
  276.     }
  277.     public function setUpdatedAt(\DateTime $updatedAt): self
  278.     {
  279.         $this->updatedAt $updatedAt;
  280.         return $this;
  281.     }
  282.     public function setDeletedAt(\DateTime $deletedAt): self
  283.     {
  284.         $this->deletedAt $deletedAt;
  285.         return $this;
  286.     }
  287.     public function isEnabled()
  288.     {
  289.         return !$this->getDeletedAt() && $this->isAtivo();
  290.     }
  291.     public function eraseCredentials()
  292.     {
  293.     }
  294.     public function getPassword()
  295.     {
  296.         return $this->getSenha();
  297.     }
  298.     public function getRoles()
  299.     {
  300.         return $this->roles;
  301.     }
  302.     public function addRole($role): self
  303.     {
  304.         $this->roles[] = $role;
  305.         return $this;
  306.     }
  307.     public function getSalt()
  308.     {
  309.         return $this->salt;
  310.     }
  311.     public function getUsername()
  312.     {
  313.         return $this->getLogin();
  314.     }
  315.     public function getEncoderName()
  316.     {
  317.         return $this->algorithm;
  318.     }
  319.     
  320.     public function isEqualTo(UserInterface $user)
  321.     {
  322.         if (!$user instanceof Usuario) {
  323.             return false;
  324.         }
  325.         if ($this->getPassword() !== $user->getPassword()) {
  326.             return false;
  327.         }
  328.         if ($this->getSalt() !== $user->getSalt()) {
  329.             return false;
  330.         }
  331.         if ($this->getUsername() !== $user->getUsername()) {
  332.             return false;
  333.         }
  334.         if ($this->isEnabled() !== $user->isEnabled()) {
  335.             return false;
  336.         }
  337.         if ($this->getSessionId() !== $user->getSessionId()) {
  338.             return false;
  339.         }
  340.         
  341.         return true;
  342.     }
  343.     public function serialize()
  344.     {
  345.         return serialize([
  346.             $this->id,
  347.             $this->login,
  348.             $this->nome,
  349.             $this->sessionId,
  350.             $this->senha,
  351.             $this->salt,
  352.             $this->ativo,
  353.         ]);
  354.     }
  355.     public function unserialize($serialized)
  356.     {
  357.         list (
  358.             $this->id,
  359.             $this->login,
  360.             $this->nome,
  361.             $this->sessionId,
  362.             $this->senha,
  363.             $this->salt,
  364.             $this->ativo,
  365.         ) = unserialize($serialized);
  366.     }
  367.     public function jsonSerialize()
  368.     {
  369.         return [
  370.             'id'        => $this->getId(),
  371.             'login'     => $this->getLogin(),
  372.             'nome'      => $this->getNome(),
  373.             'sobrenome' => $this->getSobrenome(),
  374.             'ativo'     => $this->isAtivo(),
  375.             'createdAt' => $this->getCreatedAt() ? $this->getCreatedAt()->format('Y-m-d\TH:i:s') : null,
  376.             'updatedAt' => $this->getUpdatedAt() ? $this->getUpdatedAt()->format('Y-m-d\TH:i:s') : null,
  377.             'deletedAt' => $this->getDeletedAt() ? $this->getDeletedAt()->format('Y-m-d\TH:i:s') : null,
  378.         ];
  379.     }
  380.     public function __tostring()
  381.     {
  382.         return (string) $this->getLogin();
  383.     }
  384. }