feat: special treatment of participants with age 0-2 (babies)
This commit is contained in:
1 parent
cd1ffc3e9a
commit
2e40cbc7c7
12 files changed
+615
-15
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates if a participant is at or under baby age (0-2 years).
|
||||
*
|
||||
* This condition checks if a participant's age at travel start date is at or under
|
||||
* the BABY_MAX_AGE threshold (2 years). It's used to conditionally hide fields
|
||||
* that are not applicable to babies, such as ski pass selection.
|
||||
*
|
||||
* Age is calculated at the travel start date, consistent with other age-dependent
|
||||
* services in the system (insurance, ski pass, etc.).
|
||||
*/
|
||||
class BabyAgeCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates if the participant is at or under baby age.
|
||||
*
|
||||
* Calculates the participant's age at travel start date and checks if it's
|
||||
* at or under BABY_MAX_AGE (2 years). Returns false if the participant has
|
||||
* no date of birth set.
|
||||
*
|
||||
* @param BookingDto $bookingDto The current booking data
|
||||
* @param int $participantIndex The index of the participant being evaluated
|
||||
* @param array<string, mixed> $formData Current form data (unused)
|
||||
*
|
||||
* @return bool True if the participant is at or under baby age, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
|
||||
if (null === $participant || null === $participant->dateOfBirth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$age = $participant->getAge($bookingDto->travel->dateFrom);
|
||||
|
||||
if (null === $age) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $age <= Constants::BABY_MAX_AGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that affect baby age calculation.
|
||||
*
|
||||
* The condition depends on the participant's date of birth field.
|
||||
* When this field changes, any conditions based on baby age should be re-evaluated.
|
||||
*
|
||||
* @return string[] Array containing 'dateOfBirth' field name
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return ['dateOfBirth'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of the condition.
|
||||
*
|
||||
* @return string Description of the baby age condition
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return sprintf('Participant is at or under baby age (%d years)', Constants::BABY_MAX_AGE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that checks if the booking has multiple participants.
|
||||
*
|
||||
* This is used to hide fields that are only relevant when there are
|
||||
* multiple participants, such as the bulk insurance assignment option.
|
||||
*/
|
||||
class MultipleParticipantsCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates if the booking has more than one participant.
|
||||
*
|
||||
* @param BookingDto $bookingDto The current booking data
|
||||
* @param int $participantIndex The index of the participant being evaluated (unused)
|
||||
* @param array<string, mixed> $formData Current form data (unused)
|
||||
*
|
||||
* @return bool True if the booking has 2+ participants, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
return count($bookingDto->participants) > 1;
|
||||
}
|
||||
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Checks if the booking has multiple participants (2+)';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user