wip: check eligibility based on ski pass availability
This commit is contained in:
1 parent
f5913eb947
commit
16c239716b
9 files changed
+471
-184
No files matched your search
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
use App\Service\ParticipantEligibilityService;
|
||||
|
||||
/**
|
||||
* Condition that evaluates whether a participant is eligible for booking.
|
||||
*
|
||||
* A participant is considered ineligible when no skipass is available for their age.
|
||||
* When this condition is met (participant is ineligible), all service fields should
|
||||
* be hidden and replaced with an ineligibility message.
|
||||
*
|
||||
* This prevents underaged participants from booking when the travel has no appropriate
|
||||
* skipasses for their age group. Since skipasses are mandatory for booking, having no
|
||||
* available skipasses means the participant cannot complete the booking process.
|
||||
*
|
||||
* The condition is satisfied when:
|
||||
* 1. Participant has provided date of birth
|
||||
* 2. No skipasses are available for the participant's age at travel date
|
||||
*/
|
||||
class BookingEligibilityCondition implements FieldConditionInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParticipantEligibilityService $participantEligibilityService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates if a participant is ineligible for booking.
|
||||
*
|
||||
* Returns true when the participant is INELIGIBLE (should hide service fields).
|
||||
* Returns false when the participant is eligible (show normal form fields).
|
||||
*
|
||||
* @param BookingDtoInterface $bookingDto The current booking data
|
||||
* @param int $participantIndex The index of the participant being evaluated
|
||||
* @param array<string, mixed> $formData Current form data for condition evaluation
|
||||
*
|
||||
* @return bool True if participant is ineligible (no skipasses available for their age)
|
||||
*/
|
||||
public function evaluate(BookingDtoInterface $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
// Invert the eligibility check since conditions typically evaluate to TRUE for "hide"
|
||||
// isParticipantEligible() returns TRUE when eligible, we need TRUE when INELIGIBLE
|
||||
return !$this->participantEligibilityService->isParticipantEligible($bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that this condition depends on.
|
||||
*
|
||||
* This condition depends on the dateOfBirth field since eligibility
|
||||
* is determined by age-based skipass availability.
|
||||
*
|
||||
* @return string[] Array containing field names this condition depends on
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return ['dateOfBirth'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of this condition.
|
||||
*
|
||||
* @return string Description of the booking eligibility condition
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Participant has no available skipasses for their age';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user