feat: hide unavailable ski passes from selection in create flow
This commit is contained in:
@@ -471,11 +471,9 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'skiPass')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
// No availability readonly state here: unavailable ski passes are removed from
|
||||
// the choices by filterSkiPassChoices(), and the ones that survive as protected
|
||||
// selections have to stay selectable
|
||||
|
||||
return $attributes;
|
||||
},
|
||||
@@ -998,8 +996,13 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
* Filters ski pass choices for display.
|
||||
*
|
||||
* Ski passes follow the same age evaluation rules as the rest of the booking flow.
|
||||
* Participants only see passes that match their age or birth year. In edit mode,
|
||||
* the currently booked ski pass is preserved even if it would otherwise be filtered
|
||||
* Participants only see passes that match their age or birth year. Unlike the other
|
||||
* service categories, unavailable ski passes - sold out or on Buchungsstop - are not
|
||||
* rendered read-only but removed from the choices entirely, because a short-term,
|
||||
* special-priced pass that is gone is no longer an offer worth showing.
|
||||
*
|
||||
* Passes the participant already holds are protected from that removal, and in edit
|
||||
* mode the currently booked ski pass is preserved even if age rules would filter it
|
||||
* out, so existing bookings remain renderable and editable.
|
||||
*
|
||||
* @param Service[] $services Array of ski pass Service objects to filter
|
||||
@@ -1017,20 +1020,77 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
return [];
|
||||
}
|
||||
|
||||
$filteredServices = $this->filterServicesByAgeConstraints($services, $bookingDto, $participantIndex);
|
||||
$isEditMode = BookingDto::MODE_EDIT === $bookingDto->getMode();
|
||||
$ageFilteredServices = $this->filterServicesByAgeConstraints($services, $bookingDto, $participantIndex);
|
||||
|
||||
if (BookingDto::MODE_EDIT !== $bookingDto->getMode() || null === $participant->skiPass?->id) {
|
||||
return $filteredServices;
|
||||
}
|
||||
$filteredServices = $this->serviceAvailabilityCalculator->filterAvailableServices(
|
||||
$ageFilteredServices,
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
$currentSkiPassId = $participant->skiPass->id;
|
||||
if (false === isset($filteredServices[$currentSkiPassId])) {
|
||||
$filteredServices[$currentSkiPassId] = $services[$currentSkiPassId] ?? $participant->skiPass;
|
||||
foreach ($this->getProtectedSkiPassIds($bookingDto, $participantIndex) as $protectedId) {
|
||||
if (true === isset($filteredServices[$protectedId])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$protectedService = $ageFilteredServices[$protectedId] ?? null;
|
||||
|
||||
// Age rules are only bypassed in edit mode, where a booked pass has to stay renderable
|
||||
if (null === $protectedService && true === $isEditMode) {
|
||||
$protectedService = $services[$protectedId] ?? null;
|
||||
|
||||
if (null === $protectedService && $participant->skiPass?->id === $protectedId) {
|
||||
$protectedService = $participant->skiPass;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $protectedService) {
|
||||
$filteredServices[$protectedId] = $protectedService;
|
||||
}
|
||||
}
|
||||
|
||||
return $filteredServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the ski pass IDs that have to stay selectable regardless of availability.
|
||||
*
|
||||
* Both the current selection and - in edit mode - the pass of the underlying booking are
|
||||
* protected. Without this, a participant holding a pass that sold out or went on
|
||||
* Buchungsstop meanwhile would lose it on the next refresh, and switching to another pass
|
||||
* would be a one-way decision.
|
||||
*
|
||||
* @param BookingDto $bookingDto The booking DTO containing participant and booking data
|
||||
* @param int $participantIndex Index of the participant to evaluate
|
||||
*
|
||||
* @return int[] Ski pass service IDs that must not be filtered out
|
||||
*/
|
||||
private function getProtectedSkiPassIds(BookingDto $bookingDto, int $participantIndex): array
|
||||
{
|
||||
$protectedIds = [];
|
||||
|
||||
$currentSkiPassId = $bookingDto->getParticipant($participantIndex)?->skiPass?->id;
|
||||
if (null !== $currentSkiPassId) {
|
||||
$protectedIds[] = $currentSkiPassId;
|
||||
}
|
||||
|
||||
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $bookingDto->booking) {
|
||||
$bookedSkiPasses = $bookingDto->booking->getAdditionalServicesForParticipantByGroup(
|
||||
$participantIndex,
|
||||
Constants::TOKEN_SKI_PASS
|
||||
);
|
||||
|
||||
foreach ($bookedSkiPasses as $bookedSkiPass) {
|
||||
if (null !== $bookedSkiPass->id) {
|
||||
$protectedIds[] = $bookedSkiPass->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($protectedIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a German tooltip explaining age restrictions for a service.
|
||||
*
|
||||
|
||||
@@ -51,7 +51,9 @@ class ServiceAvailabilityCalculator
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter services array to only include those with remaining availability.
|
||||
* Filter services array to only include those that are still bookable.
|
||||
*
|
||||
* Delegates to isServiceUnavailable() so that both entry points share one rule set.
|
||||
*
|
||||
* @param array<int, Service> $services Array of Service objects to filter
|
||||
* @param BookingDto $bookingDto The booking data with participant selections
|
||||
@@ -61,32 +63,28 @@ class ServiceAvailabilityCalculator
|
||||
*/
|
||||
public function filterAvailableServices(array $services, BookingDto $bookingDto, int $participantIndex): array
|
||||
{
|
||||
$remainingAvailability = $this->calculateRemainingAvailability($bookingDto, $participantIndex);
|
||||
|
||||
return array_filter($services, function (Service $service) use ($remainingAvailability) {
|
||||
// If service has no availability limit set (null), treat as unlimited
|
||||
if (null === $service->available) {
|
||||
return array_filter($services, function (Service $service) use ($bookingDto, $participantIndex) {
|
||||
// Services without an ID cannot be resolved against travel data - treat as available
|
||||
if (null === $service->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If availability is 0, service is sold out at the API level
|
||||
if (0 === $service->available) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For services with positive availability, check remaining availability
|
||||
return ($remainingAvailability[$service->id] ?? $service->available) > 0;
|
||||
return false === $this->isServiceUnavailable($service->id, $bookingDto, $participantIndex);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific service is unavailable (sold out) for the current participant.
|
||||
* Check if a specific service is unavailable for the current participant.
|
||||
*
|
||||
* A service is unavailable when it carries a booking stop (Buchungsstop) or when its
|
||||
* contingent is exhausted, either at the API level or through selections made by the
|
||||
* other participants of the current booking.
|
||||
*
|
||||
* @param int $serviceId The ID of the service to check
|
||||
* @param BookingDto $bookingDto The booking data with participant selections
|
||||
* @param int $participantIndex The index of the participant currently filling the form
|
||||
*
|
||||
* @return bool True if the service is unavailable (has availability limit and remaining is 0)
|
||||
* @return bool True if the service is unavailable
|
||||
*/
|
||||
public function isServiceUnavailable(int $serviceId, BookingDto $bookingDto, int $participantIndex): bool
|
||||
{
|
||||
@@ -105,6 +103,11 @@ class ServiceAvailabilityCalculator
|
||||
return false;
|
||||
}
|
||||
|
||||
// A booking stop blocks the service regardless of its contingent
|
||||
if (Constants::STATUS_BLOCKED === $service->status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If no availability tracking (null), service is unlimited and available
|
||||
if (null === $service->available) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user