src/Entity/User.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\Table(name'`user`')]
  13. #[ORM\InheritanceType("JOINED")]
  14. #[ORM\DiscriminatorColumn(name"discr"type"string")]
  15. #[ORM\DiscriminatorMap(["user" => User::class, "admin" => Admin::class, "contador" => Contador::class])]
  16. #[UniqueEntity(fields: ['email'], message'Ya existe una cuenta con este correo.')]
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface\Serializable
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255)]
  24.     private $nombre;
  25.     #[ORM\Column(type'string'length255)]
  26.     private $apellido;
  27.     #[ORM\Column(name'email'type'string'length255unique:true)]
  28.     private $email;
  29.     #[ORM\Column(type'json')]
  30.     private $roles = [];
  31.     #[ORM\Column(type'string')]
  32.     private $password;
  33.     #[ORM\Column(type'string'nullabletrue)]
  34.     private $foto false;
  35.     #[ORM\Column(type'boolean')]
  36.     private $isVerified false;
  37.     #[ORM\Column(type'boolean')]
  38.     private $enabled false;
  39.     #[ORM\Column(type'datetime'nullabletrue)]
  40.     private $registerDate;
  41.     #[ORM\OneToMany(mappedBy'user'targetEntityObservacion::class)]
  42.     private $observacions;
  43.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityObservacion::class)]
  44.     private $observaciones;
  45.     #[ORM\OneToMany(mappedBy'user'targetEntityRegistroAcceso::class)]
  46.     private $registroAccesos;
  47.     #[ORM\OneToMany(mappedBy'user'targetEntitySucursal::class)]
  48.     private $sucursals;
  49.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityEmpleado::class)]
  50.     private $empleado;
  51.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityFamiliar::class)]
  52.     private $familiars;
  53.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityBoleta::class)]
  54.     private $boletas;
  55.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityContadorMensaje::class)]
  56.     private $contadorMensaje;
  57.     #[ORM\Column(type'integer'nullabletrue)]
  58.     private $id_viejo;
  59.     #[ORM\OneToMany(mappedBy'userCargo'targetEntityEmpleadoEmpresaSucursal::class)]
  60.     private Collection $empleadoEmpresaSucursals;
  61.     public function __construct()
  62.     {
  63.         $this->observacions = new ArrayCollection();
  64.         $this->registroAccesos = new ArrayCollection();
  65.         $this->sucursals = new ArrayCollection();
  66.         $this->empleado = new ArrayCollection();
  67.         $this->familiars = new ArrayCollection();
  68.         $this->boletas = new ArrayCollection();
  69.         $this->contadorMensaje = new ArrayCollection();
  70.         $this->empleadoEmpresaSucursals = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getEmail(): ?string
  77.     {
  78.         return $this->email;
  79.     }
  80.     public function setEmail(string $email): self
  81.     {
  82.         $this->email $email;
  83.         return $this;
  84.     }
  85.     /**
  86.      * A visual identifier that represents this user.
  87.      *
  88.      * @see UserInterface
  89.      */
  90.     public function getUserIdentifier(): string
  91.     {
  92.         return (string) $this->email;
  93.     }
  94.     /**
  95.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  96.      */
  97.     public function getUsername(): string
  98.     {
  99.         return (string) $this->email;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function getRoles(): array
  105.     {
  106.         $roles $this->roles;
  107.         // guarantee every user at least has ROLE_USER
  108.         $roles[] = 'ROLE_USER';
  109.         return array_unique($roles);
  110.     }
  111.     public function setRoles(array $roles): self
  112.     {
  113.         $this->roles $roles;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @see PasswordAuthenticatedUserInterface
  118.      */
  119.     public function getPassword(): string
  120.     {
  121.         return $this->password;
  122.     }
  123.     public function setPassword(string $password): self
  124.     {
  125.         $this->password $password;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Returning a salt is only needed, if you are not using a modern
  130.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  131.      *
  132.      * @see UserInterface
  133.      */
  134.     public function getSalt(): ?string
  135.     {
  136.         return null;
  137.     }
  138.     /**
  139.      * @see UserInterface
  140.      */
  141.     public function eraseCredentials()
  142.     {
  143.         // If you store any temporary, sensitive data on the user, clear it here
  144.         // $this->plainPassword = null;
  145.     }
  146.     /** @see \Serializable::serialize() */
  147.     public function serialize()
  148.     {
  149.         return serialize(array(
  150.             $this->id,
  151.             $this->nombre,
  152.             $this->email,
  153.             $this->password,
  154.             // see section on salt below
  155.             // $this->salt,
  156.         ));
  157.     }
  158.     /** @see \Serializable::unserialize() */
  159.     public function unserialize($serialized)
  160.     {
  161.         list (
  162.             $this->id,
  163.             $this->nombre,
  164.             $this->email,
  165.             $this->password,
  166.             // see section on salt below
  167.             // $this->salt
  168.         ) = unserialize($serialized, array('allowed_classes' => false));
  169.     }
  170.     public function getIsVerified(): bool
  171.     {
  172.         return $this->isVerified;
  173.     }
  174.     public function setIsVerified(bool $isVerified): self
  175.     {
  176.         $this->isVerified $isVerified;
  177.         return $this;
  178.     }
  179.     /**
  180.      * Get the value of nombre
  181.      */ 
  182.     public function getNombre()
  183.     {
  184.         return $this->nombre;
  185.     }
  186.     /**
  187.      * Set the value of nombre
  188.      *
  189.      * @return  self
  190.      */ 
  191.     public function setNombre($nombre)
  192.     {
  193.         $this->nombre $nombre;
  194.         return $this;
  195.     }
  196.     /**
  197.      * Get the value of apellido
  198.      */ 
  199.     public function getApellido()
  200.     {
  201.         return $this->apellido;
  202.     }
  203.     /**
  204.      * Set the value of apellido
  205.      *
  206.      * @return  self
  207.      */ 
  208.     public function setApellido($apellido)
  209.     {
  210.         $this->apellido $apellido;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get the value of enabled
  215.      */
  216.     public function getEnabled()
  217.     {
  218.         return $this->enabled;
  219.     }
  220.     /**
  221.      * Set the value of enabled
  222.      */
  223.     public function setEnabled($enabled): self
  224.     {
  225.         $this->enabled $enabled;
  226.         return $this;
  227.     }
  228.     /**
  229.      * Get the value of foto
  230.      */
  231.     public function getFoto()
  232.     {
  233.         return $this->foto;
  234.     }
  235.     /**
  236.      * Set the value of foto
  237.      */
  238.     public function setFoto($foto): self
  239.     {
  240.         $this->foto $foto;
  241.         return $this;
  242.     }
  243.     public function __toString() {
  244.         return $this->getNombre();
  245.     }
  246.     public function isGranted($role)
  247.     {
  248.         return in_array($role$this->getRoles());
  249.     }
  250.     /**
  251.      * @return Collection<int, Observacion>
  252.      */
  253.     public function getObservacions(): Collection
  254.     {
  255.         return $this->observacions;
  256.     }
  257.     public function addObservacion(Observacion $observacion): self
  258.     {
  259.         if (!$this->observacions->contains($observacion)) {
  260.             $this->observacions[] = $observacion;
  261.             $observacion->setUser($this);
  262.         }
  263.         return $this;
  264.     }
  265.     public function removeObservacion(Observacion $observacion): self
  266.     {
  267.         if ($this->observacions->removeElement($observacion)) {
  268.             // set the owning side to null (unless already changed)
  269.             if ($observacion->getUser() === $this) {
  270.                 $observacion->setUser(null);
  271.             }
  272.         }
  273.         return $this;
  274.     }
  275.     /**
  276.      * @return Collection<int, Observacion>
  277.      */
  278.     public function getObservaciones(): Collection
  279.     {
  280.         return $this->observacions;
  281.     }
  282.     public function addObservaciones(Observacion $observacion): self
  283.     {
  284.         if (!$this->observacions->contains($observacion)) {
  285.             $this->observacions[] = $observacion;
  286.             $observacion->setUserCargo($this);
  287.         }
  288.         return $this;
  289.     }
  290.     public function removeObservaciones(Observacion $observacion): self
  291.     {
  292.         if ($this->observacions->removeElement($observacion)) {
  293.             // set the owning side to null (unless already changed)
  294.             if ($observacion->getUserCargo() === $this) {
  295.                 $observacion->setUserCargo(null);
  296.             }
  297.         }
  298.         return $this;
  299.     }
  300.         /**
  301.      * @return Collection<int, Empleado>
  302.      */
  303.     public function getEmpleado(): Collection
  304.     {
  305.         return $this->empleado;
  306.     }
  307.     public function addEmpleado(Empleado $empleado): self
  308.     {
  309.         if (!$this->empleado->contains($empleado)) {
  310.             $this->empleado[] = $empleado;
  311.             $empleado->setUserCargo($this);
  312.         }
  313.         return $this;
  314.     }
  315.     public function removeEmpleado(Empleado $empleado): self
  316.     {
  317.         if ($this->empleado->removeElement($empleado)) {
  318.             // set the owning side to null (unless already changed)
  319.             if ($empleado->getUserCargo() === $this) {
  320.                 $empleado->setUserCargo(null);
  321.             }
  322.         }
  323.         return $this;
  324.     }
  325.     public function getRegisterDate(): ?\DateTimeInterface
  326.     {
  327.         return $this->registerDate;
  328.     }
  329.     public function setRegisterDate(\DateTimeInterface $registerDate): self
  330.     {
  331.         $this->registerDate $registerDate;
  332.         return $this;
  333.     }
  334.     /**
  335.      * @return Collection<int, RegistroAcceso>
  336.      */
  337.     public function getRegistroAccesos(): Collection
  338.     {
  339.         return $this->registroAccesos;
  340.     }
  341.     public function addRegistroAcceso(RegistroAcceso $registroAcceso): self
  342.     {
  343.         if (!$this->registroAccesos->contains($registroAcceso)) {
  344.             $this->registroAccesos[] = $registroAcceso;
  345.             $registroAcceso->setUser($this);
  346.         }
  347.         return $this;
  348.     }
  349.     public function removeRegistroAcceso(RegistroAcceso $registroAcceso): self
  350.     {
  351.         if ($this->registroAccesos->removeElement($registroAcceso)) {
  352.             // set the owning side to null (unless already changed)
  353.             if ($registroAcceso->getUser() === $this) {
  354.                 $registroAcceso->setUser(null);
  355.             }
  356.         }
  357.         return $this;
  358.     }
  359.         /**
  360.      * @return Collection<int, Sucursal>
  361.      */
  362.     public function getSucursals(): Collection
  363.     {
  364.         return $this->sucursals;
  365.     }
  366.     public function addSucursal(Sucursal $sucursal): self
  367.     {
  368.         if (!$this->sucursals->contains($sucursal)) {
  369.             $this->sucursals[] = $sucursal;
  370.             $sucursal->setUser($this);
  371.         }
  372.         return $this;
  373.     }
  374.     public function removeSucursal(Sucursal $sucursal): self
  375.     {
  376.         if ($this->sucursals->removeElement($sucursal)) {
  377.             // set the owning side to null (unless already changed)
  378.             if ($sucursal->getUser() === $this) {
  379.                 $sucursal->setUser(null);
  380.             }
  381.         }
  382.         return $this;
  383.     }
  384.     /**
  385.      * @return Collection<int, Familiar>
  386.      */
  387.     public function getFamiliars(): Collection
  388.     {
  389.         return $this->familiars;
  390.     }
  391.     public function addFamiliar(Familiar $familiar): self
  392.     {
  393.         if (!$this->familiars->contains($familiar)) {
  394.             $this->familiars[] = $familiar;
  395.             $familiar->setUserCargo($this);
  396.         }
  397.         return $this;
  398.     }
  399.     public function removeFamiliar(Familiar $familiar): self
  400.     {
  401.         if ($this->familiars->removeElement($familiar)) {
  402.             // set the owning side to null (unless already changed)
  403.             if ($familiar->getUserCargo() === $this) {
  404.                 $familiar->setUserCargo(null);
  405.             }
  406.         }
  407.         return $this;
  408.     }
  409.     /**
  410.      * @return Collection<int, Boleta>
  411.      */
  412.     public function getBoletas(): Collection
  413.     {
  414.         return $this->boletas;
  415.     }
  416.     public function addBoleta(Boleta $boleta): self
  417.     {
  418.         if (!$this->boletas->contains($boleta)) {
  419.             $this->boletas[] = $boleta;
  420.             $boleta->setUserCargo($this);
  421.         }
  422.         return $this;
  423.     }
  424.     public function removeBoleta(Boleta $boleta): self
  425.     {
  426.         if ($this->boletas->removeElement($boleta)) {
  427.             // set the owning side to null (unless already changed)
  428.             if ($boleta->getUserCargo() === $this) {
  429.                 $boleta->setUserCargo(null);
  430.             }
  431.         }
  432.         return $this;
  433.     }
  434.         /**
  435.      * @return Collection<int, ContadorMensaje>
  436.      */
  437.     public function getContadorMensaje(): Collection
  438.     {
  439.         return $this->contadorMensaje;
  440.     }
  441.     public function addContadorMensaje(ContadorMensaje $contadorMensaje): self
  442.     {
  443.         if (!$this->contadorMensaje->contains($contadorMensaje)) {
  444.             $this->contadorMensaje[] = $contadorMensaje;
  445.             $contadorMensaje->setUserCargo($this);
  446.         }
  447.         return $this;
  448.     }
  449.     public function removeContadorMensaje(ContadorMensaje $contadorMensaje): self
  450.     {
  451.         if ($this->contadorMensaje->removeElement($contadorMensaje)) {
  452.             // set the owning side to null (unless already changed)
  453.             if ($contadorMensaje->getUserCargo() === $this) {
  454.                 $contadorMensaje->setUserCargo(null);
  455.             }
  456.         }
  457.         return $this;
  458.     }
  459.     /**
  460.      * Get the value of id_viejo
  461.      */ 
  462.     public function getId_viejo()
  463.     {
  464.         return $this->id_viejo;
  465.     }
  466.     /**
  467.      * Set the value of id_viejo
  468.      *
  469.      * @return  self
  470.      */ 
  471.     public function setId_viejo($id_viejo)
  472.     {
  473.         $this->id_viejo $id_viejo;
  474.         return $this;
  475.     }
  476.     /**
  477.      * @return Collection<int, EmpleadoEmpresaSucursal>
  478.      */
  479.     public function getEmpleadoEmpresaSucursals(): Collection
  480.     {
  481.         return $this->empleadoEmpresaSucursals;
  482.     }
  483.     public function addEmpleadoEmpresaSucursal(EmpleadoEmpresaSucursal $empleadoEmpresaSucursal): self
  484.     {
  485.         if (!$this->empleadoEmpresaSucursals->contains($empleadoEmpresaSucursal)) {
  486.             $this->empleadoEmpresaSucursals->add($empleadoEmpresaSucursal);
  487.             $empleadoEmpresaSucursal->setUserCargo($this);
  488.         }
  489.         return $this;
  490.     }
  491.     public function removeEmpleadoEmpresaSucursal(EmpleadoEmpresaSucursal $empleadoEmpresaSucursal): self
  492.     {
  493.         if ($this->empleadoEmpresaSucursals->removeElement($empleadoEmpresaSucursal)) {
  494.             // set the owning side to null (unless already changed)
  495.             if ($empleadoEmpresaSucursal->getUserCargo() === $this) {
  496.                 $empleadoEmpresaSucursal->setUserCargo(null);
  497.             }
  498.         }
  499.         return $this;
  500.     }
  501. }