<?php
namespace App\Entity;
use App\Entity\System\usersRoles;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string',length: 255, nullable: true)]
private $email;
#[ORM\Column(type: 'array')]
private $roles = [];
#[ORM\Column(type: 'string',length: 255, nullable: true)]
private $password;
#[ORM\Column(type: 'string',length: 255, nullable: true)]
private $firstName;
#[ORM\Column(type: 'string',length: 255, nullable: true)]
private $lastName;
#[ORM\Column(type: 'boolean', options:["default"=>false])]
private $isEnabled;
#[ORM\Column(type: 'datetime', nullable: true)]
private $createdAt;
#[ORM\Column(type: 'datetime', nullable: true)]
private $lastConnectionAt;
#[ORM\OneToMany(mappedBy: 'users', targetEntity: usersRoles::class)]
private $usersRoles;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->isEnabled = true;
$this->usersRoles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getRoles()
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
public function setRoles($roles) {
$this->roles = $roles;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getLastConnectionAt(): ?\DateTimeInterface
{
return $this->lastConnectionAt;
}
public function setLastConnectionAt(?\DateTimeInterface $lastConnectionAt): self
{
$this->lastConnectionAt = $lastConnectionAt;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in original.security.yaml.old
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, usersRoles>
*/
public function getUsersRoles(): Collection
{
return $this->usersRoles;
}
public function addUsersRole(usersRoles $usersRole): self
{
if (!$this->usersRoles->contains($usersRole)) {
$this->usersRoles[] = $usersRole;
$usersRole->setUsersId($this);
}
return $this;
}
public function removeUsersRole(usersRoles $usersRole): self
{
if ($this->usersRoles->removeElement($usersRole)) {
// set the owning side to null (unless already changed)
if ($usersRole->getUsersId() === $this) {
$usersRole->setUsersId(null);
}
}
return $this;
}
}