src/Entity/SecUser.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SecUserRepository;
  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 Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassSecUserRepository::class)]
  11. class SecUser implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length180uniquetrue)]
  18.     private ?string $username null;
  19.     #[ORM\Column]
  20.     private array $roles = [];
  21.     /**
  22.      * @var string The hashed password
  23.      */
  24.     #[ORM\Column]
  25.     private ?string $password null;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  27.     private ?\DateTimeInterface $lastLogin null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $requestTokenChange null;
  30.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  31.     private ?\DateTimeInterface $lastRequestToken null;
  32.     #[ORM\Column(nullabletrue)]
  33.     private ?bool $enabled null;
  34.     #[ORM\Column(length50)]
  35.     private ?string $email null;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?int $attemptFailLogin null;
  38.     #[ORM\ManyToMany(targetEntitySecRol::class, mappedBy'userId')]
  39.     private Collection $secRol;
  40.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  41.     #[ORM\JoinColumn(name'persona_id')]
  42.     private ?TerPersona $persona null;
  43.     #[ORM\OneToMany(targetEntityGHContrato::class, mappedBy'user')]
  44.     private Collection $contratos;
  45.     public function __construct()
  46.     {
  47.         $this->secRol = new ArrayCollection();
  48.         $this->contratos = new ArrayCollection();
  49.     }
  50.     
  51.     public function __toString() {
  52.         return $this->getPersona()->getNombres();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     /**
  59.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  60.      */
  61.     public function getUsername(): string
  62.     {
  63.         return (string) $this->username;
  64.     }
  65.     public function setUsername(string $username): self
  66.     {
  67.         $this->username $username;
  68.         return $this;
  69.     }
  70.     /**
  71.      * A visual identifier that represents this user.
  72.      *
  73.      * @see UserInterface
  74.      */
  75.     public function getUserIdentifier(): string
  76.     {
  77.         return (string) $this->username;
  78.     }
  79.     /**
  80.      * @see UserInterface
  81.      */
  82.     public function getRoles(): array
  83.     {
  84.         $roles $this->roles;
  85.         // guarantee every user at least has ROLE_USER
  86.         $roles[] = 'ROLE_USER';
  87.         return array_unique($roles);
  88.     }
  89.     public function setRoles(array $roles): self
  90.     {
  91.         $this->roles $roles;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @see PasswordAuthenticatedUserInterface
  96.      */
  97.     public function getPassword(): string
  98.     {
  99.         return $this->password;
  100.     }
  101.     public function setPassword(string $password): self
  102.     {
  103.         $this->password $password;
  104.         return $this;
  105.     }
  106.     /**
  107.      * Returning a salt is only needed, if you are not using a modern
  108.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  109.      *
  110.      * @see UserInterface
  111.      */
  112.     public function getSalt(): ?string
  113.     {
  114.         return null;
  115.     }
  116.     /**
  117.      * @see UserInterface
  118.      */
  119.     public function eraseCredentials()
  120.     {
  121.         // If you store any temporary, sensitive data on the user, clear it here
  122.         // $this->plainPassword = null;
  123.     }
  124.     public function getLastLogin(): ?\DateTimeInterface
  125.     {
  126.         return $this->lastLogin;
  127.     }
  128.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  129.     {
  130.         $this->lastLogin $lastLogin;
  131.         return $this;
  132.     }
  133.     public function getRequestTokenChange(): ?string
  134.     {
  135.         return $this->requestTokenChange;
  136.     }
  137.     public function setRequestTokenChange(?string $requestTokenChange): self
  138.     {
  139.         $this->requestTokenChange $requestTokenChange;
  140.         return $this;
  141.     }
  142.     public function getLastRequestToken(): ?\DateTimeInterface
  143.     {
  144.         return $this->lastRequestToken;
  145.     }
  146.     public function setLastRequestToken(?\DateTimeInterface $lastRequestToken): self
  147.     {
  148.         $this->lastRequestToken $lastRequestToken;
  149.         return $this;
  150.     }
  151.     public function isEnabled(): ?bool
  152.     {
  153.         return $this->enabled;
  154.     }
  155.     public function setEnabled(?bool $enabled): self
  156.     {
  157.         $this->enabled $enabled;
  158.         return $this;
  159.     }
  160.     public function getEmail(): ?string
  161.     {
  162.         return $this->email;
  163.     }
  164.     public function setEmail(string $email): self
  165.     {
  166.         $this->email $email;
  167.         return $this;
  168.     }
  169.     public function getAttemptFailLogin(): ?int
  170.     {
  171.         return $this->attemptFailLogin;
  172.     }
  173.     public function setAttemptFailLogin(?int $attemptFailLogin): self
  174.     {
  175.         $this->attemptFailLogin $attemptFailLogin;
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection<int, SecRol>
  180.      */
  181.     public function getSecRol(): Collection
  182.     {
  183.         return $this->secRol;
  184.     }
  185.     public function addSecRol(SecRol $secRol): static
  186.     {
  187.         if (!$this->secRol->contains($secRol)) {
  188.             $this->secRol->add($secRol);
  189.             $secRol->addUserId($this);
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeSecRol(SecRol $secRol): static
  194.     {
  195.         if ($this->secRol->removeElement($secRol)) {
  196.             $secRol->removeUserId($this);
  197.         }
  198.         return $this;
  199.     }
  200.     public function getPersona(): ?TerPersona
  201.     {
  202.         return $this->persona;
  203.     }
  204.     public function setPersona(?TerPersona $persona): static
  205.     {
  206.         $this->persona $persona;
  207.         return $this;
  208.     }
  209.     // Getter
  210.     public function getContratos(): Collection
  211.     {
  212.         return $this->contratos;
  213.     }
  214. // Método de adición
  215.     public function addContrato(GHContrato $contrato): self
  216.     {
  217.         if (!$this->contratos->contains($contrato)) {
  218.             $this->contratos[] = $contrato;
  219.             $contrato->setUser($this);
  220.         }
  221.         return $this;
  222.     }
  223. // Método de eliminación
  224.     public function removeContrato(GHContrato $contrato): self
  225.     {
  226.         if ($this->contratos->removeElement($contrato)) {
  227.             // set the owning side to null (unless already changed)
  228.             if ($contrato->getUser() === $this) {
  229.                 $contrato->setUser(null);
  230.             }
  231.         }
  232.         return $this;
  233.     }
  234. }