355 lines
7.6 KiB
PHP
355 lines
7.6 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Repository\UserRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
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]
|
|
private bool $superAdmin = false;
|
|
|
|
#[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(type: 'json')]
|
|
private array $hotelCodes = [];
|
|
|
|
#[ORM\Column]
|
|
private bool $muteNotifications = false;
|
|
|
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
|
private ?\DateTimeImmutable $disabledAt = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $disabledReason = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $disabledReasonInternal = 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 getInitials(): string
|
|
{
|
|
$token = substr($this->getFirstName(), 0, 1).substr($this->getLastName(), 0, 2);
|
|
|
|
return strtoupper($token);
|
|
}
|
|
|
|
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 (true === $this->isSuperAdmin()) {
|
|
$roles[] = 'ROLE_SUPER_ADMIN';
|
|
}
|
|
|
|
return array_unique($roles);
|
|
}
|
|
|
|
public function getRolesLabels(): array
|
|
{
|
|
$labels = [];
|
|
|
|
foreach ($this->roles as $role) {
|
|
$labels[] = match ($role) {
|
|
'ROLE_ADMIN' => 'Admin',
|
|
'ROLE_MANAGER' => 'Reisemanager',
|
|
'ROLE_HOUSE_MANAGER' => 'Hausleitung',
|
|
'ROLE_TEAMER' => 'Teamer',
|
|
default => $role,
|
|
};
|
|
}
|
|
|
|
return $labels;
|
|
}
|
|
|
|
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 isSuperAdmin(): bool
|
|
{
|
|
return $this->superAdmin;
|
|
}
|
|
|
|
public function setSuperAdmin(bool $superAdmin): static
|
|
{
|
|
$this->superAdmin = $superAdmin;
|
|
|
|
return $this;
|
|
}
|
|
|
|
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_manager_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 getHotelCodes(): array
|
|
{
|
|
return $this->hotelCodes;
|
|
}
|
|
|
|
public function setHotelCodes(array $hotelCodes): static
|
|
{
|
|
$this->hotelCodes = $hotelCodes;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isMuteNotifications(): bool
|
|
{
|
|
return $this->muteNotifications;
|
|
}
|
|
|
|
public function setMuteNotifications(bool $muteNotifications): static
|
|
{
|
|
$this->muteNotifications = $muteNotifications;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function hasHotelCodeMatch(string $hotelCode): bool
|
|
{
|
|
foreach ($this->hotelCodes as $userHotelCode) {
|
|
if (
|
|
str_starts_with($hotelCode, $userHotelCode)
|
|
|| str_ends_with($hotelCode, $userHotelCode)
|
|
) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getDisabledAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->disabledAt;
|
|
}
|
|
|
|
public function setDisabledAt(?\DateTimeImmutable $disabledAt): static
|
|
{
|
|
$this->disabledAt = $disabledAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isDisabled(): bool
|
|
{
|
|
return null !== $this->disabledAt;
|
|
}
|
|
|
|
public function getDisabledReason(): ?string
|
|
{
|
|
return $this->disabledReason;
|
|
}
|
|
|
|
public function setDisabledReason(?string $disabledReason): static
|
|
{
|
|
$this->disabledReason = $disabledReason;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisabledReasonInternal(): ?string
|
|
{
|
|
return $this->disabledReasonInternal;
|
|
}
|
|
|
|
public function setDisabledReasonInternal(?string $disabledReasonInternal): static
|
|
{
|
|
$this->disabledReasonInternal = $disabledReasonInternal;
|
|
|
|
return $this;
|
|
}
|
|
}
|