173 lines
5.9 KiB
PHP
173 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\Model;
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* Represents personal data for a user including address and communication information.
|
|
*
|
|
* This class handles the storage and transformation of personal information
|
|
* including name, address, communication details, and physical attributes.
|
|
* It provides methods to convert data to API payload format and extract claims
|
|
* for authentication purposes.
|
|
*/
|
|
class PersonalData
|
|
{
|
|
private const DEFAULT_AGE_YEARS = 18;
|
|
|
|
public ?int $addressId = null;
|
|
public ?int $personId = null;
|
|
public bool $mutable = false;
|
|
public ?string $status = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
|
public ?string $name = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
|
public ?string $firstName = '';
|
|
|
|
public ?string $salutation = null;
|
|
public ?string $title = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
|
#[Assert\Choice(choices: ['M', 'W', 'D'], message: 'Bitte gib einen gültigen Wert an', groups: ['personal_data'])]
|
|
public ?string $gender = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
|
public ?string $nationality = null;
|
|
public ?string $height = null;
|
|
public ?string $shoeSize = null;
|
|
public ?string $weight = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
|
public ?\DateTimeImmutable $dateOfBirth = null;
|
|
public ?string $remarks = null;
|
|
|
|
// Wishes (unterbringungswunsch, beförderungswunsch)
|
|
public ?string $remarksRoom = null;
|
|
public ?string $licensePlate = null;
|
|
|
|
#[Assert\Valid(groups: ['personal_data'])]
|
|
public Address $address;
|
|
|
|
#[Assert\Valid(groups: ['personal_data'])]
|
|
public Communication $communication;
|
|
|
|
/** @var list<string> */
|
|
public array $roles = [];
|
|
/** @var list<string> */
|
|
public array $hotelCodes = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->address = new Address();
|
|
$this->communication = new Communication();
|
|
}
|
|
|
|
public function getFullName(): string
|
|
{
|
|
return sprintf('%s %s', $this->firstName, $this->name);
|
|
}
|
|
|
|
/**
|
|
* Converts the personal data to API payload format.
|
|
*
|
|
* Transforms the personal data object into an array structure suitable
|
|
* for API communication with the BusProNet system.
|
|
*
|
|
* @return array<string, mixed> The payload array for API transmission
|
|
*/
|
|
public function toPayload(bool $includeDateOfBirth = true): array
|
|
{
|
|
$payload = [
|
|
'idadresse' => $this->addressId,
|
|
'idadresseperson' => $this->personId,
|
|
'anrede' => $this->salutation,
|
|
'geschlecht' => $this->gender,
|
|
'nationalitaet' => $this->nationality,
|
|
'titel' => $this->title,
|
|
'vorname' => $this->firstName,
|
|
'name' => $this->name,
|
|
'anschrift' => $this->address->toPayload(),
|
|
'kommunikation' => $this->communication->toPayload(),
|
|
'sonstiges1' => $this->height,
|
|
'sonstiges2' => $this->weight,
|
|
'sonstiges3' => $this->shoeSize,
|
|
'bemerkung' => $this->remarks,
|
|
];
|
|
|
|
if (true === $includeDateOfBirth) {
|
|
$dob = $this->dateOfBirth ?? new \DateTimeImmutable(self::DEFAULT_AGE_YEARS.' years ago');
|
|
$payload['geburtsdatum'] = $dob->format('d.m.Y');
|
|
}
|
|
|
|
return $payload;
|
|
}
|
|
|
|
public static function fromContactFormSubmission(ContactFormSubmission $dto): self
|
|
{
|
|
$gender = null !== $dto->gender ? strtoupper($dto->gender) : null;
|
|
if ('F' === $gender) {
|
|
$gender = 'W';
|
|
}
|
|
$instance = new self();
|
|
$instance->name = $dto->lastName;
|
|
$instance->firstName = $dto->firstName;
|
|
$instance->gender = $gender;
|
|
$instance->address->street = $dto->street;
|
|
$instance->address->postCode = $dto->zipCode;
|
|
$instance->address->city = $dto->city;
|
|
$instance->communication->email = $dto->email;
|
|
$instance->communication->phone = $dto->phone;
|
|
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* Extracts user claims for authentication and profile information.
|
|
*
|
|
* Creates a structured array containing user profile information
|
|
* suitable for JWT claims or user session data.
|
|
*
|
|
* @return array<string, mixed> The claims array with user profile data
|
|
*/
|
|
public function getClaims(): array
|
|
{
|
|
return [
|
|
'id' => $this->personId,
|
|
'email' => $this->communication->email,
|
|
'roles' => $this->roles,
|
|
'profile' => [
|
|
'first_name' => $this->firstName,
|
|
'last_name' => $this->name,
|
|
'title' => $this->title,
|
|
'salutation' => $this->salutation,
|
|
'gender' => $this->gender,
|
|
'date_of_birth' => $this->dateOfBirth?->format('Y-m-d'),
|
|
'nationality' => $this->nationality,
|
|
'address' => [
|
|
'street' => $this->address->street,
|
|
'postcode' => $this->address->postCode,
|
|
'city' => $this->address->city,
|
|
'district' => $this->address->district,
|
|
'country' => $this->address->country,
|
|
],
|
|
'communication' => [
|
|
'email' => $this->communication->email,
|
|
'mobile' => $this->communication->mobile,
|
|
'phone' => $this->communication->phone,
|
|
'newsletter' => $this->communication->newsletter,
|
|
],
|
|
'hotel_codes' => $this->hotelCodes,
|
|
'height' => $this->height,
|
|
'weight' => $this->weight,
|
|
'shoe_size' => $this->shoeSize,
|
|
'remarks' => $this->remarks,
|
|
],
|
|
];
|
|
}
|
|
}
|