<?php
namespace App\Entity;
use App\Repository\SecUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: SecUserRepository::class)]
class SecUser implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $username = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastLogin = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $requestTokenChange = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastRequestToken = null;
#[ORM\Column(nullable: true)]
private ?bool $enabled = null;
#[ORM\Column(length: 50)]
private ?string $email = null;
#[ORM\Column(nullable: true)]
private ?int $attemptFailLogin = null;
#[ORM\ManyToMany(targetEntity: SecRol::class, mappedBy: 'userId')]
private Collection $secRol;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'persona_id')]
private ?TerPersona $persona = null;
#[ORM\OneToMany(targetEntity: GHContrato::class, mappedBy: 'user')]
private Collection $contratos;
public function __construct()
{
$this->secRol = new ArrayCollection();
$this->contratos = new ArrayCollection();
}
public function __toString() {
return $this->getPersona()->getNombres();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(?\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function getRequestTokenChange(): ?string
{
return $this->requestTokenChange;
}
public function setRequestTokenChange(?string $requestTokenChange): self
{
$this->requestTokenChange = $requestTokenChange;
return $this;
}
public function getLastRequestToken(): ?\DateTimeInterface
{
return $this->lastRequestToken;
}
public function setLastRequestToken(?\DateTimeInterface $lastRequestToken): self
{
$this->lastRequestToken = $lastRequestToken;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getAttemptFailLogin(): ?int
{
return $this->attemptFailLogin;
}
public function setAttemptFailLogin(?int $attemptFailLogin): self
{
$this->attemptFailLogin = $attemptFailLogin;
return $this;
}
/**
* @return Collection<int, SecRol>
*/
public function getSecRol(): Collection
{
return $this->secRol;
}
public function addSecRol(SecRol $secRol): static
{
if (!$this->secRol->contains($secRol)) {
$this->secRol->add($secRol);
$secRol->addUserId($this);
}
return $this;
}
public function removeSecRol(SecRol $secRol): static
{
if ($this->secRol->removeElement($secRol)) {
$secRol->removeUserId($this);
}
return $this;
}
public function getPersona(): ?TerPersona
{
return $this->persona;
}
public function setPersona(?TerPersona $persona): static
{
$this->persona = $persona;
return $this;
}
// Getter
public function getContratos(): Collection
{
return $this->contratos;
}
// Método de adición
public function addContrato(GHContrato $contrato): self
{
if (!$this->contratos->contains($contrato)) {
$this->contratos[] = $contrato;
$contrato->setUser($this);
}
return $this;
}
// Método de eliminación
public function removeContrato(GHContrato $contrato): self
{
if ($this->contratos->removeElement($contrato)) {
// set the owning side to null (unless already changed)
if ($contrato->getUser() === $this) {
$contrato->setUser(null);
}
}
return $this;
}
}