wip: age based filtering of options
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates whether a participant has provided their date of birth.
|
||||
*
|
||||
* This condition checks if a participant has a valid date of birth set, which is
|
||||
* required for evaluating age-based service constraints and showing age-dependent
|
||||
* form fields. When no birth date is provided, age-restricted fields should be
|
||||
* hidden until this prerequisite is met.
|
||||
*
|
||||
* The condition is commonly used to control field visibility, ensuring that
|
||||
* age-dependent services and options are only displayed when the participant's
|
||||
* age can be calculated.
|
||||
*/
|
||||
class DateOfBirthProvidedCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates if the participant has provided their date of birth.
|
||||
*
|
||||
* Checks if the participant exists and has a non-null dateOfBirth property.
|
||||
* This is a prerequisite for showing age-dependent form fields and services.
|
||||
*
|
||||
* @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 (unused for this condition)
|
||||
*
|
||||
* @return bool True if the participant has provided their date of birth, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDtoInterface $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
|
||||
return null !== $participant && null !== $participant->dateOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that this condition depends on.
|
||||
*
|
||||
* The date of birth condition depends on the participant's dateOfBirth field.
|
||||
* When this field changes, any conditions based on birth date availability
|
||||
* should be re-evaluated.
|
||||
*
|
||||
* @return string[] Array containing 'dateOfBirth' field name
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return ['dateOfBirth'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of this condition.
|
||||
*
|
||||
* Provides a clear description of what this condition checks for,
|
||||
* useful for debugging and understanding field state logic.
|
||||
*
|
||||
* @return string Description of the date of birth requirement
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Participant must provide their date of birth';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user