236 lines
4.9 KiB
PHP
236 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Repository\UserRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
class User implements UserInterface, TimestampableEntityInterface
|
|
{
|
|
use TimestampableEntity;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column]
|
|
private ?int $busProAddressId = null;
|
|
|
|
#[ORM\Column]
|
|
private ?int $busProPersonId = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $firstName = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $lastName = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $email = null;
|
|
|
|
#[ORM\Column(type: 'json')]
|
|
private array $roles = [];
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?\DateTimeImmutable $lastLoginAt = null;
|
|
|
|
#[ORM\OneToOne(inversedBy: 'user', cascade: ['all'])]
|
|
private ?Teamer $teamer = null;
|
|
|
|
#[ORM\OneToOne(inversedBy: 'user', cascade: ['all'])]
|
|
private ?Contact $contact = null;
|
|
|
|
#[ORM\Column(length: 32, nullable: true)]
|
|
private ?string $hotelCode = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->uuid = Uuid::v4();
|
|
}
|
|
|
|
public function __toString()
|
|
{
|
|
return $this->getFullName();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUuid(): string
|
|
{
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function getBusProAddressId(): ?int
|
|
{
|
|
return $this->busProAddressId;
|
|
}
|
|
|
|
public function setBusProAddressId(int $busProAddressId): static
|
|
{
|
|
$this->busProAddressId = $busProAddressId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBusProPersonId(): ?int
|
|
{
|
|
return $this->busProPersonId;
|
|
}
|
|
|
|
public function setBusProPersonId(int $busProPersonId): static
|
|
{
|
|
$this->busProPersonId = $busProPersonId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFirstName(): ?string
|
|
{
|
|
return $this->firstName;
|
|
}
|
|
|
|
public function setFirstName(?string $firstName): static
|
|
{
|
|
$this->firstName = $firstName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLastName(): ?string
|
|
{
|
|
return $this->lastName;
|
|
}
|
|
|
|
public function setLastName(?string $lastName): static
|
|
{
|
|
$this->lastName = $lastName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFullName(bool $formal = false): string
|
|
{
|
|
if (true === $formal) {
|
|
return sprintf('%s, %s', $this->getLastName(), $this->getFirstName());
|
|
}
|
|
|
|
return sprintf('%s %s', $this->getFirstName(), $this->getLastName());
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(string $email): static
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRoles(): array
|
|
{
|
|
$roles = ['ROLE_USER', ...$this->roles];
|
|
|
|
if (in_array('ROLE_ADMIN', $this->roles) || in_array('ROLE_MANAGER', $this->roles)) {
|
|
$roles[] = 'ROLE_ADMINISTRATIVE';
|
|
}
|
|
|
|
return array_unique($roles);
|
|
}
|
|
|
|
public function setRoles(array $roles): static
|
|
{
|
|
$this->roles = $roles;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function hasRole(string $role): bool
|
|
{
|
|
return in_array($role, $this->getRoles());
|
|
}
|
|
|
|
public function getLastLoginAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->lastLoginAt;
|
|
}
|
|
|
|
public function setLastLoginAt(?\DateTimeImmutable $lastLoginAt): static
|
|
{
|
|
$this->lastLoginAt = $lastLoginAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDefaultRoute(): string
|
|
{
|
|
if ($this->hasRole('ROLE_ADMIN')) {
|
|
return 'app_admin_index';
|
|
} elseif ($this->hasRole('ROLE_MANAGER')) {
|
|
return 'app_admin_index';
|
|
} elseif ($this->hasRole('ROLE_HOUSE_MANAGER')) {
|
|
return 'app_house_manager_index';
|
|
} else {
|
|
return 'app_teamer_index';
|
|
}
|
|
}
|
|
|
|
public function eraseCredentials(): void
|
|
{
|
|
}
|
|
|
|
public function getUserIdentifier(): string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function getTeamer(): ?Teamer
|
|
{
|
|
return $this->teamer;
|
|
}
|
|
|
|
public function setTeamer(?Teamer $teamer): static
|
|
{
|
|
$this->teamer = $teamer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getContact(): ?Contact
|
|
{
|
|
return $this->contact;
|
|
}
|
|
|
|
public function setContact(?Contact $contact): static
|
|
{
|
|
$this->contact = $contact;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHotelCode(): ?string
|
|
{
|
|
return $this->hotelCode;
|
|
}
|
|
|
|
public function setHotelCode(?string $hotelCode): static
|
|
{
|
|
$this->hotelCode = $hotelCode;
|
|
|
|
return $this;
|
|
}
|
|
}
|