<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(['email'])]
#[UniqueEntity(['username'])]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
final const USER_SUPER_ADMIN_ID = 1;
final const USER_DEFAULT_ID = 2;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[Assert\Email]
#[Assert\NotNull]
private ?string $email;
#[ORM\Column(length: 255)]
// #[Assert\Length(
// min: 3,
// max: 4096,
// minMessage: " the username must have minimum {{ limit }} characters")]
// #[Assert\NotNull]
private ?string $username = null;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'string')]
#[Assert\Length(min: 6, minMessage: 'Your password should be at least {{ limit }} characters')]
private ?string $password= null;
#[ORM\OneToOne(inversedBy: 'user', targetEntity: Personal::class, cascade: ['persist', 'remove'])]
private ?Personal $personal;
#[ORM\Column(type: 'boolean')]
private bool $isVerified = false;
#[ORM\Column(nullable: false)]
private ?bool $active = null;
#[ORM\ManyToOne(cascade: ['persist'])]
private ?Customer $customer = null;
#[ORM\Column(length: 255,nullable: true)]
private ?string $google_id = null;
/* #[ORM\Column(type: 'string')]
private ?string $verifToken = null;*/
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->email;
}
/**
* @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 getRole(): string
{
if ($this->roles && count($this->roles) > 0) {
$role = $this->roles[0];
$role = str_replace("ROLE_", "", $role);
//$role = str_replace("_"," ", $role);
return $role;
}
return '';
}
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;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getPersonal(): ?Personal
{
return $this->personal;
}
public function setPersonal(?Personal $personal): self
{
$this->personal = $personal;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
public function __toString(): string
{
return $this->username;
}
public function getGoogleId(): ?string
{
return $this->google_id;
}
public function setGoogleId(string $google_id): static
{
$this->google_id = $google_id;
return $this;
}
}