4.7 KiB
4.7 KiB
Implementation Plan: Duration-Based Rental Filtering Based on Skipass Selection
Overview
Implement cross-field dependency where rentals are only visible/selectable when a skipass is selected, and filter rentals to match the selected skipass's date range (dateFrom/dateTo).
Analysis
Based on code review:
- Both rentals and skipasses have
dateFromanddateToproperties for duration - Current system already filters services by travel date range using
getAdditionalServicesBySubTypes($token, true, true) - Need to implement skipass-to-rental date matching logic
- Field state conditions system is already in place for hiding/showing fields
- Need to create a custom field options provider for duration-filtered rentals
Implementation Steps
1. Create SkiPassSelectionCondition
File: src/Form/Service/Condition/SkiPassSelectionCondition.php
- Similar to
RentalSelectionConditionbut checks for skipass selection - Evaluates both form data and participant DTO for skipass
- Returns true if participant has selected a skipass
2. Update Field State Provider
File: src/Form/Service/CreateFieldStateProvider.php
- Add rentals field hidden condition based on skipass selection
- Similar to how rental insurance is hidden unless rentals are selected:
$skiPassCondition = new SkiPassSelectionCondition();
$this->fieldStateConditions['rentals'] = [
'hidden' => CompositeCondition::not($skiPassCondition),
];
3. Create Duration-Based Rental Filtering
File: src/Form/Service/ParticipantFieldOptionsProvider.php
- Modify existing rentals field provider to filter by selected skipass duration
- Extract selected skipass from participant data
- Filter available rentals to only those with matching dateFrom/dateTo ranges
- Use exact date matching:
rental.dateFrom == skipass.dateFrom && rental.dateTo == skipass.dateTo
4. Update RentalsFieldHandler Dependencies
File: src/Form/Service/ParticipantRentalsFieldHandler.php
- Add
skiPassto dependencies array:['dateOfBirth', 'skiPass'] - Add DTO cleanup: clear rentals when no skipass is selected
- Filter rentals by skipass duration in
processField()method
5. Update Field Handler Dependencies
File: src/Form/Service/ParticipantRentalInsuranceFieldHandler.php
- Update dependencies to include skipass:
['dateOfBirth', 'rentals', 'skiPass'] - Modify visibility logic: rental insurance only shown when both skipass AND rentals selected
Key Technical Details
Duration Matching Logic
Rentals will be filtered to match skipass duration exactly:
private function filterRentalsBySkiPassDuration(array $rentals, ?Service $selectedSkiPass): array
{
if (null === $selectedSkiPass || null === $selectedSkiPass->dateFrom || null === $selectedSkiPass->dateTo) {
return []; // No skipass or invalid dates = no rentals
}
return array_filter($rentals, function(Service $rental) use ($selectedSkiPass) {
return $rental->dateFrom?->format('Y-m-d') === $selectedSkiPass->dateFrom?->format('Y-m-d')
&& $rental->dateTo?->format('Y-m-d') === $selectedSkiPass->dateTo?->format('Y-m-d');
});
}
Field Visibility Chain
- SkiPass: Always visible (after dateOfBirth)
- Rentals: Only visible when skipass selected, filtered by skipass duration
- Rental Insurance: Only visible when rentals selected (existing logic)
- Body Dimensions: Only visible when rentals selected (existing logic)
HTMX Integration
- Existing HTMX system will handle dynamic updates when skipass selection changes
- Field state conditions will automatically trigger rental field visibility
- Rental options will be re-rendered with duration-filtered choices
Dependencies
- No new dependencies required
- Leverages existing field state condition system
- Uses existing Service model date properties
- Maintains backward compatibility with existing workflows
Progress Tracking
Status: Implementation Complete ✅
- System architecture analysis
- Existing code review
- Implementation strategy defined
- Technical approach documented
Implementation Phase: COMPLETED ✅
- Step 1: Create SkiPassSelectionCondition
- Step 2: Update Field State Provider
- Step 3: Create Duration-Based Rental Filtering
- Step 4: Update RentalsFieldHandler Dependencies
- Step 5: Update Field Handler Dependencies
- Testing: Verify cross-field dependencies work correctly
- Testing: Verify HTMX updates work properly
- Documentation: Update CLAUDE.md with new feature details
Notes
- Implementation follows existing architectural patterns
- Maintains consistency with current field state condition system
- Preserves backward compatibility
- Leverages existing HTMX infrastructure for dynamic updates