src/Entity/User.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as PerseoAssert;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  14.  * @ORM\Table(name="user", schema="perseo")
  15.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  16.  * @PerseoAssert\ContraintsValidarEntidadCp()
  17.  */
  18. class User implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\Column(type="bigint", options={"unsigned":true})
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      */
  25.     protected $id;
  26.     /**
  27.      * @ORM\Column(type="string", unique=true, length=180, nullable=false)
  28.      */
  29.     protected $username;
  30.     /**
  31.      * @ORM\Column(type="string", unique=true, length=180, nullable=false)
  32.      */
  33.     protected $email;
  34.     /**
  35.      * @ORM\Column(type="json", nullable=false)
  36.      */
  37.     protected $roles = [];
  38.     /**
  39.      * @var string The hashed password
  40.      * @ORM\Column(type="string", nullable=false)
  41.      */
  42.     protected $password;
  43.     /**
  44.      * @ORM\Column(type="string", nullable=true)
  45.      */
  46.     protected $nombre;
  47.     /**
  48.      * @ORM\Column(type="string", nullable=true, name="primer_apellido")
  49.      */
  50.     protected $primerApellido;
  51.     /**
  52.      * @ORM\Column(type="string", nullable=true, name="segundo_apellido")
  53.      */
  54.     protected $segundoApellido;
  55.     /**
  56.      * @ORM\Column(type="bigint", nullable=true, name="tipo_genero_id", options={"unsigned":true})
  57.      */
  58.     protected $tipoGenero;
  59.     /**
  60.      * @ORM\Column(type="string", nullable=true)
  61.      */
  62.     protected $direccion;
  63.     /**
  64.      * @ORM\Column(type="string", length=12, nullable=true)
  65.      * @Assert\Length(min = 5, max = 12)
  66.      */
  67.     protected $cp;
  68.     /**
  69.      * @ORM\Column(type="string", nullable=true)
  70.      */
  71.     protected $region;
  72.     /**
  73.      * @ORM\Column(type="string", nullable=true)
  74.      */
  75.     protected $ciudad;
  76.     /**
  77.      * @ORM\Column(type="string", nullable=true)
  78.      */
  79.     protected $telefono;
  80.     /**
  81.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  82.      */
  83.     protected $deletedAt;
  84.     /**
  85.      * @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
  86.      * @Gedmo\Timestampable(on="update")
  87.      */
  88.     protected $updatedAt;
  89.     /**
  90.      * @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
  91.      * @Gedmo\Timestampable(on="create")
  92.      */
  93.     protected $createdAt;
  94.     /**
  95.      * @ORM\Column(type="string", length=2, nullable=true, name="pais")
  96.      */
  97.     protected $pais;
  98.     /**
  99.      * @ORM\ManyToOne(targetEntity="App\Entity\CCAA", inversedBy="user")
  100.      * @ORM\JoinColumn(name="ccaa_id", referencedColumnName="id")
  101.      */
  102.     protected $ccaa;
  103.     /*
  104.      * @ORM\ManyToOne(targetEntity="App\Entity\Ciudad", inversedBy="user")
  105.      * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
  106.      */
  107.     //protected $ciudad;
  108.     /**
  109.      * @ORM\ManyToOne(targetEntity="App\Entity\Provincia", inversedBy="user")
  110.      * @ORM\JoinColumn(name="provincia_id", referencedColumnName="id")
  111.      */
  112.     protected $provincia;
  113.     /**
  114.      * @ORM\OneToOne(targetEntity="App\Entity\Cliente", inversedBy="user", cascade={"persist"})
  115.      * @ORM\JoinColumn(name="cliente_id", referencedColumnName="id", nullable=true, unique=true)
  116.      */
  117.     protected $cliente;
  118.     /**
  119.      * @ORM\OneToOne(targetEntity="App\Entity\Usuario", inversedBy="user", cascade={"persist"})
  120.      * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id", nullable=true, unique=true)
  121.      */
  122.     protected $usuario;
  123.     public function __construct()
  124.     {
  125. //        $this->cliente = new Cliente();
  126. //        $this->usuario = new Usuario();
  127.     }
  128.     public function getNombreCompleto()
  129.     {
  130.         return $this->getNombre() . ' ' $this->getPrimerApellido() . ' ' $this->getSegundoApellido();
  131.     }
  132.     public function getIniciales()
  133.     {
  134.         return mb_substr($this->getNombre(), 01) . ' ' mb_substr($this->getPrimerApellido(), 01) . ' ' mb_substr($this->getSegundoApellido(), 01);
  135.     }
  136.     public function getId(): ?int
  137.     {
  138.         return $this->id;
  139.     }
  140.     /**
  141.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  142.      */
  143.     public function getUsername(): string
  144.     {
  145.         return (string) $this->username;
  146.     }
  147.     public function setUsername(string $username): self
  148.     {
  149.         $this->username $username;
  150.         return $this;
  151.     }
  152.     /**
  153.      * A visual identifier that represents this user.
  154.      *
  155.      * @see UserInterface
  156.      */
  157.     public function getUserIdentifier(): string
  158.     {
  159.         return (string) $this->username;
  160.     }
  161.     /**
  162.      * @see UserInterface
  163.      */
  164.     public function getRoles(): array
  165.     {
  166.         $roles $this->roles;
  167.         // guarantee every user at least has ROLE_USER
  168.         $roles[] = 'ROLE_USER';
  169.         return array_unique($roles);
  170.     }
  171.     public function setRoles(array $roles): self
  172.     {
  173.         $this->roles $roles;
  174.         return $this;
  175.     }
  176.     /**
  177.      * @see PasswordAuthenticatedUserInterface
  178.      */
  179.     public function getPassword(): ?string
  180.     {
  181.         return $this->password;
  182.     }
  183.     public function setPassword(?string $password): self
  184.     {
  185.         $this->password $password;
  186.         return $this;
  187.     }
  188.     /**
  189.      * Returning a salt is only needed, if you are not using a modern
  190.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  191.      *
  192.      * @see UserInterface
  193.      */
  194.     public function getSalt(): ?string
  195.     {
  196.         return null;
  197.     }
  198.     /**
  199.      * @see UserInterface
  200.      */
  201.     public function eraseCredentials()
  202.     {
  203.         // If you store any temporary, sensitive data on the user, clear it here
  204.         // $this->plainPassword = null;
  205.     }
  206.     public function getCliente(): ?Cliente
  207.     {
  208.         return $this->cliente;
  209.     }
  210.     public function setCliente(Cliente $cliente): self
  211.     {
  212.         $this->cliente $cliente;
  213.         return $this;
  214.     }
  215.     public function getUsuario(): ?Usuario
  216.     {
  217.         return $this->usuario;
  218.     }
  219.     public function setUsuario(?Usuario $usuario): self
  220.     {
  221.         $this->usuario $usuario;
  222.         return $this;
  223.     }
  224.     public function getEmail(): ?string
  225.     {
  226.         return $this->email;
  227.     }
  228.     public function setEmail(string $email): self
  229.     {
  230.         $this->email $email;
  231.         return $this;
  232.     }
  233.     public function getNombre(): ?string
  234.     {
  235.         return $this->nombre;
  236.     }
  237.     public function setNombre(?string $nombre): self
  238.     {
  239.         $this->nombre $nombre;
  240.         return $this;
  241.     }
  242.     public function getPrimerApellido(): ?string
  243.     {
  244.         return $this->primerApellido;
  245.     }
  246.     public function setPrimerApellido(?string $primerApellido): self
  247.     {
  248.         $this->primerApellido $primerApellido;
  249.         return $this;
  250.     }
  251.     public function getSegundoApellido(): ?string
  252.     {
  253.         return $this->segundoApellido;
  254.     }
  255.     public function setSegundoApellido(?string $segundoApellido): self
  256.     {
  257.         $this->segundoApellido $segundoApellido;
  258.         return $this;
  259.     }
  260.     public function getTipoGenero(): ?string
  261.     {
  262.         return $this->tipoGenero;
  263.     }
  264.     public function setTipoGenero(?string $tipoGenero): self
  265.     {
  266.         $this->tipoGenero $tipoGenero;
  267.         return $this;
  268.     }
  269.     public function getDireccion(): ?string
  270.     {
  271.         return $this->direccion;
  272.     }
  273.     public function setDireccion(?string $direccion): self
  274.     {
  275.         $this->direccion $direccion;
  276.         return $this;
  277.     }
  278.     public function getCp(): ?string
  279.     {
  280.         return $this->cp;
  281.     }
  282.     public function setCp(?string $cp): self
  283.     {
  284.         $this->cp $cp;
  285.         return $this;
  286.     }
  287.     public function getTelefono(): ?string
  288.     {
  289.         return $this->telefono;
  290.     }
  291.     public function setTelefono(?string $telefono): self
  292.     {
  293.         $this->telefono $telefono;
  294.         return $this;
  295.     }
  296.     public function getCreatedAt(): ?\DateTimeInterface
  297.     {
  298.         return $this->createdAt;
  299.     }
  300.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  301.     {
  302.         $this->createdAt $createdAt;
  303.         return $this;
  304.     }
  305.     public function getUpdatedAt(): ?\DateTimeInterface
  306.     {
  307.         return $this->updatedAt;
  308.     }
  309.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  310.     {
  311.         $this->updatedAt $updatedAt;
  312.         return $this;
  313.     }
  314.     public function getCcaa(): ?CCAA
  315.     {
  316.         return $this->ccaa;
  317.     }
  318.     public function setCcaa(?CCAA $ccaa): self
  319.     {
  320.         $this->ccaa $ccaa;
  321.         return $this;
  322.     }
  323.     public function getCiudad(): ?string
  324.     {
  325.         return $this->ciudad;
  326.     }
  327.     public function setCiudad(?string $ciudad): self
  328.     {
  329.         $this->ciudad $ciudad;
  330.         return $this;
  331.     }
  332.     public function getPais(): ?string
  333.     {
  334.         return $this->pais;
  335.     }
  336.     public function setPais(?string $pais): self
  337.     {
  338.         $this->pais $pais;
  339.         return $this;
  340.     }
  341.     public function getProvincia(): ?Provincia
  342.     {
  343.         return $this->provincia;
  344.     }
  345.     public function setProvincia(?Provincia $provincia): self
  346.     {
  347.         $this->provincia $provincia;
  348.         return $this;
  349.     }
  350.     public function getDeletedAt(): ?\DateTimeInterface
  351.     {
  352.         return $this->deletedAt;
  353.     }
  354.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  355.     {
  356.         $this->deletedAt $deletedAt;
  357.         return $this;
  358.     }
  359.     public function getRegion(): ?string
  360.     {
  361.         return $this->region;
  362.     }
  363.     public function setRegion(?string $region): static
  364.     {
  365.         $this->region $region;
  366.         return $this;
  367.     }
  368. }