132 lines
4.5 KiB
PHP
132 lines
4.5 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;
|
|
public ?string $gender = null;
|
|
public ?string $nationality = null;
|
|
public ?string $height = null;
|
|
public ?string $shoeSize = null;
|
|
public ?string $weight = null;
|
|
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;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->address = new Address();
|
|
$this->communication = new Communication();
|
|
}
|
|
|
|
/**
|
|
* 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(): array
|
|
{
|
|
// Ensure date of birth is populated
|
|
if (null === $dob = $this->dateOfBirth) {
|
|
$dob = new \DateTimeImmutable(self::DEFAULT_AGE_YEARS.' years ago');
|
|
}
|
|
|
|
return [
|
|
'idadresse' => $this->addressId,
|
|
'idadresseperson' => $this->personId,
|
|
'geburtsdatum' => $dob->format('d.m.Y'),
|
|
'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,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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 [
|
|
'email' => $this->communication->email,
|
|
'profile' => [
|
|
'first_name' => $this->firstName,
|
|
'last_name' => $this->name,
|
|
'title' => $this->title,
|
|
'salutation' => $this->salutation,
|
|
'gender' => $this->gender,
|
|
'nationality' => $this->nationality,
|
|
'address' => [
|
|
'street' => $this->address->street,
|
|
'postcode' => $this->address->postCode,
|
|
'city' => $this->address->city,
|
|
'disctrict' => $this->address->district,
|
|
'country' => $this->address->country,
|
|
],
|
|
'communication' => [
|
|
'email' => $this->communication->email,
|
|
'mobile' => $this->communication->mobile,
|
|
'phone' => $this->communication->phone,
|
|
'newsletter' => $this->communication->newsletter,
|
|
],
|
|
'height' => $this->height,
|
|
'weight' => $this->weight,
|
|
'shoe_size' => $this->shoeSize,
|
|
'remarks' => $this->remarks,
|
|
],
|
|
];
|
|
}
|
|
}
|