WIP
This commit is contained in:
+54
-55
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Embeddable\Address;
|
||||
use App\Entity\Embeddable\Communication;
|
||||
use App\Entity\Embeddable\Profile;
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
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)]
|
||||
class User implements UserInterface
|
||||
@@ -15,23 +18,23 @@ class User implements UserInterface
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $busProAddressId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $busProPersonId = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $firstName = null;
|
||||
#[ORM\Embedded(class: Profile::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Profile $profile = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $lastName = null;
|
||||
#[ORM\Embedded(class: Address::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Address $address = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $role = null;
|
||||
#[ORM\Embedded(class: Communication::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Communication $communication = null;
|
||||
|
||||
#[ORM\Column(type: 'json')]
|
||||
private array $roles = [];
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $lastLoginAt = null;
|
||||
@@ -41,30 +44,6 @@ class User implements UserInterface
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
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 getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
@@ -77,42 +56,61 @@ class User implements UserInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstName(): ?string
|
||||
public function getProfile(): ?Profile
|
||||
{
|
||||
return $this->firstName;
|
||||
return $this->profile;
|
||||
}
|
||||
|
||||
public function setFirstName(string $firstName): static
|
||||
public function setProfile(?Profile $profile): static
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
$this->profile = $profile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastName(): ?string
|
||||
public function getAddress(): ?Address
|
||||
{
|
||||
return $this->lastName;
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
public function setLastName(string $lastName): static
|
||||
public function setAddress(?Address $address): static
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRole(): ?string
|
||||
public function getCommunication(): ?Communication
|
||||
{
|
||||
return $this->role;
|
||||
return $this->communication;
|
||||
}
|
||||
|
||||
public function setRole(string $role): static
|
||||
public function setCommunication(?Communication $communication): static
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->communication = $communication;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = ['ROLE_USER', ...$this->roles];
|
||||
|
||||
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;
|
||||
@@ -127,12 +125,13 @@ class User implements UserInterface
|
||||
|
||||
public function getDefaultRoute(): string
|
||||
{
|
||||
return 'app_index';
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return ['ROLE_USER', $this->getRole()];
|
||||
if ($this->hasRole('ROLE_ADMIN')) {
|
||||
return 'app_admin_index';
|
||||
} elseif ($this->hasRole('ROLE_MANAGER')) {
|
||||
return 'app_manager_index';
|
||||
} else {
|
||||
return 'app_teamer_index';
|
||||
}
|
||||
}
|
||||
|
||||
public function eraseCredentials(): void
|
||||
|
||||
Reference in New Issue
Block a user