src/Entity/User.php line 22

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