feat: functionality to determine family status of a booking

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 7ce3bc18b2
commit 96c53cc173
2 changed files with 53 additions and 0 deletions
+34
View File
@@ -51,6 +51,40 @@ class BookingCreateDto implements BookingDtoInterface
return $this->participants[$index] ?? null; return $this->participants[$index] ?? null;
} }
/**
* Determines if this is a family booking based on participant age distribution.
*
* A family booking is defined as:
* - 1-2 participants aged 18 or older (adults)
* - At least 1 participant aged 20 or younger (young people/children)
*
* @return bool True if this qualifies as a family booking
*/
public function isFamilyBooking(): bool
{
$adults = 0; // Count of participants >= 18 years
$youngPeople = 0; // Count of participants <= 20 years
foreach ($this->participants as $participant) {
$age = $participant->getAge();
if (null === $age) {
continue; // Skip participants without birth date
}
if ($age >= 18) {
++$adults;
}
if ($age <= 20) {
++$youngPeople;
}
}
// Check family booking criteria
return ($adults >= 1 && $adults <= 2) && ($youngPeople >= 1);
}
#[Assert\Callback(callback: 'validateRoomSelection', groups: ['booking_create_step_1'])] #[Assert\Callback(callback: 'validateRoomSelection', groups: ['booking_create_step_1'])]
public function validateRoomSelection(ExecutionContextInterface $context): void public function validateRoomSelection(ExecutionContextInterface $context): void
{ {
+19
View File
@@ -106,4 +106,23 @@ class ParticipantDto
{ {
return 'O' === $this->status; return 'O' === $this->status;
} }
/**
* Calculates the participant's current age in complete years.
*
* Uses the same logic as existing age evaluators in the system
* for consistency across age-related calculations.
*
* @return int|null The calculated age in complete years, or null if no birth date
*/
public function getAge(): ?int
{
if (null === $this->dateOfBirth) {
return null;
}
$today = new \DateTimeImmutable();
return $this->dateOfBirth->diff($today)->y;
}
} }