src/Entity/Usuario.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UsuarioRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UsuarioRepository::class)
  11.  * @ORM\Table(name="user")
  12.  * @UniqueEntity("email")
  13.  * @UniqueEntity("username")
  14.  */
  15. class Usuario implements UserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $username;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private $nombre;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $apellidos;
  39.     /**
  40.      * @ORM\Column(type="datetime")
  41.      */
  42.     private $fechaAlta;
  43.     /**
  44.      * @ORM\Column(type="datetime", nullable=true)
  45.      */
  46.     private $fechaUltimoLogin;
  47.     /**
  48.      * @ORM\Column(type="json")
  49.      */
  50.     private $roles = [];
  51.     /**
  52.      * @var string The hashed password
  53.      * @ORM\Column(type="string")
  54.      */
  55.     private $password;
  56.     /**
  57.      * @var string
  58.      */
  59.     private $plainPassword;
  60.     /**
  61.      * @ORM\Column(type="boolean")
  62.      */
  63.     private $enabled true;
  64.     /**
  65.      * @ORM\Column(type="datetime", nullable=true)
  66.      */
  67.     private $ultimoAcceso;
  68.     public function __construct()
  69.     {
  70.     }
  71.     public function __toString(): string
  72.     {
  73.         return $this->getNombreCompleto();
  74.     }
  75.     /**
  76.      * @see UserInterface
  77.      */
  78.     public function eraseCredentials()
  79.     {
  80.         $this->plainPassword null;
  81.     }
  82.     /**
  83.      * @see UserInterface
  84.      */
  85.     public function getSalt()
  86.     {
  87.     }
  88.     /**
  89.      * @see UserInterface
  90.      */
  91.     public function getUserIdentifier()
  92.     {
  93.         return $this->getUsername();
  94.     }
  95.     public function getId(): ?int
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getEmail(): ?string
  100.     {
  101.         return $this->email;
  102.     }
  103.     public function setEmail(string $email): self
  104.     {
  105.         $this->email $email;
  106.         return $this;
  107.     }
  108.     public function getUsername(): ?string
  109.     {
  110.         return $this->username;
  111.     }
  112.     public function setUsername(string $username): self
  113.     {
  114.         $this->username $username;
  115.         return $this;
  116.     }
  117.     public function getNombreCompleto(): ?string
  118.     {
  119.         return $this->nombre ' ' $this->apellidos;
  120.     }
  121.     public function getNombre(): ?string
  122.     {
  123.         return $this->nombre;
  124.     }
  125.     public function setNombre(string $nombre): self
  126.     {
  127.         $this->nombre $nombre;
  128.         return $this;
  129.     }
  130.     public function getApellidos(): ?string
  131.     {
  132.         return $this->apellidos;
  133.     }
  134.     public function setApellidos(string $apellidos): self
  135.     {
  136.         $this->apellidos $apellidos;
  137.         return $this;
  138.     }
  139.     public function getFechaAlta(): ?\DateTimeInterface
  140.     {
  141.         return $this->fechaAlta;
  142.     }
  143.     public function setFechaAlta(\DateTimeInterface $fechaAlta): self
  144.     {
  145.         $this->fechaAlta $fechaAlta;
  146.         return $this;
  147.     }
  148.     public function getFechaUltimoLogin(): ?\DateTimeInterface
  149.     {
  150.         return $this->fechaUltimoLogin;
  151.     }
  152.     public function setFechaUltimoLogin(?\DateTimeInterface $fechaUltimoLogin): self
  153.     {
  154.         $this->fechaUltimoLogin $fechaUltimoLogin;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @see UserInterface
  159.      */
  160.     public function getRoles(): array
  161.     {
  162.         $roles $this->roles;
  163.         return array_unique($roles);
  164.     }
  165.     public function setRoles(array $roles): self
  166.     {
  167.         $this->roles $roles;
  168.         return $this;
  169.     }
  170.     public function hasRole(string $role): bool
  171.     {
  172.         return in_array($role$this->getRoles());
  173.     }
  174.     public function getRole(): string
  175.     {
  176.         return $this->roles $this->roles[0] : null;
  177.     }
  178.     /**
  179.      * @see UserInterface
  180.      */
  181.     public function getPassword(): string
  182.     {
  183.         return (string) $this->password;
  184.     }
  185.     public function setPassword(string $password): self
  186.     {
  187.         $this->password $password;
  188.         return $this;
  189.     }
  190.     public function getPlainPassword(): ?string
  191.     {
  192.         return $this->plainPassword;
  193.     }
  194.     public function setPlainPassword(string $plainPassword): self
  195.     {
  196.         $this->plainPassword $plainPassword;
  197.         return $this;
  198.     }
  199.     public function getEnabled(): ?bool
  200.     {
  201.         return $this->enabled;
  202.     }
  203.     public function setEnabled(bool $enabled): self
  204.     {
  205.         $this->enabled $enabled;
  206.         return $this;
  207.     }
  208.     public function getUltimoAcceso(): ?\DateTimeInterface
  209.     {
  210.         return $this->ultimoAcceso;
  211.     }
  212.     public function setUltimoAcceso(\DateTimeInterface $ultimoAcceso): self
  213.     {
  214.         $this->ultimoAcceso $ultimoAcceso;
  215.         return $this;
  216.     }
  217. }