wip: check eligibility based on ski pass availability
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Service\Abstract\AbstractFieldStateProvider;
|
||||
use App\Form\Service\Condition\BookingEligibilityCondition;
|
||||
use App\Form\Service\Condition\BulkInsuranceBookingCondition;
|
||||
use App\Form\Service\Condition\CompositeCondition;
|
||||
use App\Form\Service\Condition\DateOfBirthProvidedCondition;
|
||||
@@ -14,6 +15,7 @@ use App\Form\Service\Condition\RentalSelectionCondition;
|
||||
use App\Form\Service\Condition\RoomSelectionCondition;
|
||||
use App\Form\Service\Condition\ServiceSubTypeCondition;
|
||||
use App\Form\Service\Condition\SkiPassSelectionCondition;
|
||||
use App\Service\ParticipantEligibilityService;
|
||||
|
||||
/**
|
||||
* Field state provider for the booking create workflow.
|
||||
@@ -27,9 +29,15 @@ use App\Form\Service\Condition\SkiPassSelectionCondition;
|
||||
* - Age-dependent service fields are hidden until birth date is provided
|
||||
* - Transportation pickup fields are hidden by default, shown only when transportation type is BUS
|
||||
* - Parking field is hidden by default, shown only when outbound transportation is PKW
|
||||
* - All service fields are hidden for ineligible participants (no skipasses available for their age)
|
||||
*/
|
||||
class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParticipantEligibilityService $participantEligibilityService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Registers field state conditions for the create workflow.
|
||||
*
|
||||
@@ -56,6 +64,9 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
*/
|
||||
protected function registerFieldStateConditions(): void
|
||||
{
|
||||
// Booking eligibility condition - hide all service fields when no skipasses available for participant's age
|
||||
$bookingEligibilityCondition = new BookingEligibilityCondition($this->participantEligibilityService);
|
||||
|
||||
$rentalCondition = new RentalSelectionCondition();
|
||||
$skiPassCondition = new SkiPassSelectionCondition();
|
||||
|
||||
@@ -67,25 +78,43 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
// Hide age-dependent fields when no date of birth is provided
|
||||
$dateOfBirthProvidedCondition = new DateOfBirthProvidedCondition();
|
||||
|
||||
// Age-dependent service fields are hidden until birth date is provided
|
||||
// Age-dependent service fields are hidden until birth date is provided OR when participant is ineligible
|
||||
$this->fieldStateConditions['courses'] = [
|
||||
'hidden' => CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
$this->fieldStateConditions['additionalServices'] = [
|
||||
'hidden' => CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
// Show rentals only when both date of birth is provided AND skipass is selected
|
||||
// Skipass field - hidden when participant is ineligible OR when no date of birth
|
||||
$this->fieldStateConditions['skiPass'] = [
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
// Show rentals only when both date of birth is provided AND skipass is selected AND participant is eligible
|
||||
$this->fieldStateConditions['rentals'] = [
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
CompositeCondition::not($skiPassCondition)
|
||||
CompositeCondition::not($skiPassCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
$this->fieldStateConditions['board'] = [
|
||||
'hidden' => CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
// Bulk insurance booking conditions
|
||||
@@ -114,11 +143,12 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
),
|
||||
];
|
||||
|
||||
// Hide insurance field until date of birth is provided OR when bulk insurance booking is active for dependent participants
|
||||
// Hide insurance field until date of birth is provided OR when bulk insurance booking is active OR when participant is ineligible
|
||||
$this->fieldStateConditions['insurance'] = [
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bulkInsuranceBookingCondition
|
||||
$bulkInsuranceBookingCondition,
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
@@ -131,6 +161,23 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
];
|
||||
|
||||
// Transportation-related field conditions
|
||||
// All transportation fields require date of birth and participant eligibility
|
||||
|
||||
// Outbound transportation - hidden until date of birth provided AND participant is eligible
|
||||
$this->fieldStateConditions['transportationOutbound'] = [
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
// Inbound transportation - hidden until date of birth provided AND participant is eligible
|
||||
$this->fieldStateConditions['transportationInbound'] = [
|
||||
'hidden' => CompositeCondition::or(
|
||||
CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
$bookingEligibilityCondition
|
||||
),
|
||||
];
|
||||
|
||||
// Show outbound pickup only when transportation is BUS (hidden by default)
|
||||
$this->fieldStateConditions['pickupOutbound'] = [
|
||||
|
||||
Reference in New Issue
Block a user