This commit is contained in:
Björn Fromme
2023-09-02 18:47:42 +02:00
parent 23e66b08e8
commit 08f7836d41
21 changed files with 693 additions and 82 deletions
+100
View File
@@ -0,0 +1,100 @@
<?php
namespace App\Entity\Embeddable;
use App\BusProNet\Model\Address as BpnAddress;
use App\BusProNet\Model\ProfileResponse;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Embeddable]
class Address
{
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotBlank(message: 'required_input')]
protected ?string $street = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotBlank(message: 'required_input')]
protected ?string $postCode = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotBlank(message: 'required_input')]
protected ?string $city = null;
#[ORM\Column(type: 'string', nullable: true)]
protected ?string $country = null;
public function toArray(): array
{
return [
'street' => $this->getStreet(),
'post_code' => $this->getPostCode(),
'city' => $this->getCity(),
'country' => $this->getCountry(),
];
}
public static function fromApiResponse(ProfileResponse $profileResponse): static
{
$address = $profileResponse->getAddress();
$instance = new static();
$instance
->setStreet($address->getStreet())
->setPostCode($address->getPostCode())
->setCity($address->getCity())
->setCountry($address->getCountry() ?? 'DE')
;
return $instance;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(?string $street): static
{
$this->street = $street;
return $this;
}
public function getPostCode(): ?string
{
return $this->postCode;
}
public function setPostCode(?string $postCode): static
{
$this->postCode = $postCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): static
{
$this->city = $city;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): static
{
$this->country = $country;
return $this;
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
namespace App\Entity\Embeddable;
use App\BusProNet\Model\ProfileResponse;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Embeddable]
class Communication
{
#[ORM\Column(type: 'string', nullable: true)]
protected ?string $phone = null;
#[ORM\Column(type: 'string', nullable: true)]
protected ?string $mobile = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Email(mode: 'strict')]
protected ?string $email = null;
public static function fromApiResponse(ProfileResponse $profileResponse): static
{
$communication = $profileResponse->getCommunication();
$instance = new static();
$instance
->setPhone($communication->getPhone())
->setMobile($communication->getMobile())
->setEmail($communication->getEmail())
;
return $instance;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): static
{
$this->mobile = $mobile;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
}
+149
View File
@@ -0,0 +1,149 @@
<?php
namespace App\Entity\Embeddable;
use App\BusProNet\Model\ProfileResponse;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Embeddable]
class Profile
{
#[ORM\Column]
private ?int $busProAddressId = null;
#[ORM\Column]
private ?int $busProPersonId = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255)]
private ?string $salutation = null;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 1, nullable: true)]
private ?string $gender = null;
#[ORM\Column(type: 'date_immutable', nullable: true)]
private ?\DateTimeImmutable $dateOfBirth = null;
public static function fromApiResponse(ProfileResponse $profileResponse): static
{
$instance = new static();
$instance
->setBusProAddressId($profileResponse->getAddressId())
->setBusProPersonId($profileResponse->getPersonId())
->setTitle($profileResponse->getTitle())
->setSalutation($profileResponse->getSalutation())
->setFirstName($profileResponse->getFirstName())
->setLastName($profileResponse->getName())
->setGender($profileResponse->getGender())
->setDateOfBirth($profileResponse->getDateOfBirth())
;
return $instance;
}
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 getSalutation(): ?string
{
return $this->salutation;
}
public function setSalutation(?string $salutation): static
{
$this->salutation = $salutation;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): static
{
$this->title = $title;
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 getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): static
{
$this->gender = $gender;
return $this;
}
public function getDateOfBirth(): ?\DateTimeImmutable
{
return $this->dateOfBirth;
}
public function setDateOfBirth(?\DateTimeImmutable $dateOfBirth): static
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
}
+54 -55
View File
@@ -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