feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
@@ -86,6 +86,10 @@ class ParticipantDto
|
||||
|
||||
public array $courses = [];
|
||||
public array $additionalServices = [];
|
||||
public array $autoBookOptOutServiceIds = [];
|
||||
public array $autoBookOptOutSkiPassIds = [];
|
||||
public array $autoBookOptOutBoardIds = [];
|
||||
public array $autoBookOptOutRentalIds = [];
|
||||
|
||||
// Note: Ski pass validation is conditional - see ParticipantEditDto::validateSkiPassRequired()
|
||||
// Babies (0-2 years) are exempt from ski pass requirement
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
|
||||
/**
|
||||
@@ -96,6 +97,10 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === $participant instanceof ParticipantDto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract current service selections from submitted data
|
||||
$selectedServices = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||
|
||||
@@ -114,10 +119,66 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
$this->updateAutoBookOptOutServices(
|
||||
$participant,
|
||||
$availableServices,
|
||||
$validSelections,
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
// Update participant with validated selections
|
||||
$participant->additionalServices = $validSelections;
|
||||
}
|
||||
|
||||
private function updateAutoBookOptOutServices(
|
||||
ParticipantDto $participant,
|
||||
array $availableServices,
|
||||
array $validSelections,
|
||||
BookingDto $bookingDto,
|
||||
int $participantIndex,
|
||||
): void {
|
||||
$currentlySelectedAutoBookIds = [];
|
||||
foreach ($participant->additionalServices as $selectedService) {
|
||||
if (false === $selectedService instanceof Service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $this->isServiceValidForParticipant($selectedService, $availableServices, $bookingDto, $participantIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds = [];
|
||||
foreach ($validSelections as $selectedService) {
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
// Add explicit user deselections to opt-out list
|
||||
foreach ($currentlySelectedAutoBookIds as $serviceId) {
|
||||
if (false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
&& false === in_array($serviceId, $participant->autoBookOptOutServiceIds, true)) {
|
||||
$participant->autoBookOptOutServiceIds[] = $serviceId;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove opt-out when user manually re-selects the service
|
||||
$participant->autoBookOptOutServiceIds = array_values(array_filter(
|
||||
$participant->autoBookOptOutServiceIds,
|
||||
static fn (int $serviceId): bool => false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters service selections to keep only those valid for the participant's age.
|
||||
*
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
|
||||
/**
|
||||
@@ -57,6 +58,10 @@ class ParticipantBoardFieldHandler extends AbstractParticipantFieldHandler
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === $participant instanceof ParticipantDto) {
|
||||
return;
|
||||
}
|
||||
|
||||
$selectedBoard = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||
|
||||
// Get available board options from travel data (includes booked options in edit mode)
|
||||
@@ -73,9 +78,63 @@ class ParticipantBoardFieldHandler extends AbstractParticipantFieldHandler
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
$this->updateAutoBookOptOutBoard(
|
||||
$participant,
|
||||
$availableBoard,
|
||||
$validSelections,
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
$participant->board = $validSelections;
|
||||
}
|
||||
|
||||
private function updateAutoBookOptOutBoard(
|
||||
ParticipantDto $participant,
|
||||
array $availableBoard,
|
||||
array $validSelections,
|
||||
BookingDto $bookingDto,
|
||||
int $participantIndex,
|
||||
): void {
|
||||
$currentlySelectedAutoBookIds = [];
|
||||
foreach ($participant->board as $selectedService) {
|
||||
if (false === $selectedService instanceof Service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $this->isServiceValidForParticipant($selectedService, $availableBoard, $bookingDto, $participantIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds = [];
|
||||
foreach ($validSelections as $selectedService) {
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
foreach ($currentlySelectedAutoBookIds as $serviceId) {
|
||||
if (false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
&& false === in_array($serviceId, $participant->autoBookOptOutBoardIds, true)) {
|
||||
$participant->autoBookOptOutBoardIds[] = $serviceId;
|
||||
}
|
||||
}
|
||||
|
||||
$participant->autoBookOptOutBoardIds = array_values(array_filter(
|
||||
$participant->autoBookOptOutBoardIds,
|
||||
static fn (int $serviceId): bool => false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
));
|
||||
}
|
||||
|
||||
private function filterValidServiceSelections(
|
||||
array $selectedServices,
|
||||
array $availableServices,
|
||||
|
||||
@@ -249,13 +249,26 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
|
||||
$attributes = [];
|
||||
|
||||
// Make mandatory services readonly only when actually selected by participant.
|
||||
if (true === $service->mandatory) {
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
$isSelected = null !== $participant
|
||||
&& $this->hasServiceById($participant->board, $service->id);
|
||||
|
||||
if (true === $isSelected) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'Diese Leistung ist nicht abwählbar';
|
||||
}
|
||||
}
|
||||
|
||||
// Add service description as data attribute for frontend use
|
||||
if (null !== $service->description && '' !== trim($service->description)) {
|
||||
$attributes['data-description'] = $service->description;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'board')) {
|
||||
// Make readonly if service is unavailable (only if not already mandatory)
|
||||
if (false === $service->mandatory
|
||||
&& $this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'board')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -361,13 +374,26 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
|
||||
$attributes = [];
|
||||
|
||||
// Make mandatory services readonly only when actually selected by participant.
|
||||
if (true === $service->mandatory) {
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
$isSelected = null !== $participant
|
||||
&& $this->hasServiceById($participant->rentals, $service->id);
|
||||
|
||||
if (true === $isSelected) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'Diese Leistung ist nicht abwählbar';
|
||||
}
|
||||
}
|
||||
|
||||
// Add service description as data attribute for frontend use
|
||||
if (null !== $service->description && '' !== trim($service->description)) {
|
||||
$attributes['data-description'] = $service->description;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'rentals')) {
|
||||
// Make readonly if service is unavailable (only if not already mandatory)
|
||||
if (false === $service->mandatory
|
||||
&& $this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'rentals')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,10 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === $participant instanceof ParticipantDto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Store previous rental state BEFORE checking skipass
|
||||
$previousRentals = $participant->rentals;
|
||||
|
||||
@@ -102,6 +107,14 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
$this->updateAutoBookOptOutRentals(
|
||||
$participant,
|
||||
$durationFilteredRentals,
|
||||
$validSelections,
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
// Notify if rentals were cleared due to skipass duration change
|
||||
// Only show notification if user had submitted rentals that got filtered out,
|
||||
// not if the user intentionally cleared the selection (empty submission)
|
||||
@@ -115,6 +128,52 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
||||
$participant->rentals = $validSelections;
|
||||
}
|
||||
|
||||
private function updateAutoBookOptOutRentals(
|
||||
ParticipantDto $participant,
|
||||
array $availableRentals,
|
||||
array $validSelections,
|
||||
BookingDto $bookingDto,
|
||||
int $participantIndex,
|
||||
): void {
|
||||
$currentlySelectedAutoBookIds = [];
|
||||
foreach ($participant->rentals as $selectedService) {
|
||||
if (false === $selectedService instanceof Service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $this->isServiceValidForParticipant($selectedService, $availableRentals, $bookingDto, $participantIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds = [];
|
||||
foreach ($validSelections as $selectedService) {
|
||||
if (null === $selectedService->id || true === $selectedService->mandatory || false === $selectedService->autoBook) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newlySelectedAutoBookIds[] = $selectedService->id;
|
||||
}
|
||||
|
||||
foreach ($currentlySelectedAutoBookIds as $serviceId) {
|
||||
if (false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
&& false === in_array($serviceId, $participant->autoBookOptOutRentalIds, true)) {
|
||||
$participant->autoBookOptOutRentalIds[] = $serviceId;
|
||||
}
|
||||
}
|
||||
|
||||
$participant->autoBookOptOutRentalIds = array_values(array_filter(
|
||||
$participant->autoBookOptOutRentalIds,
|
||||
static fn (int $serviceId): bool => false === in_array($serviceId, $newlySelectedAutoBookIds, true)
|
||||
));
|
||||
}
|
||||
|
||||
private function filterValidServiceSelections(
|
||||
array $selectedServices,
|
||||
array $availableServices,
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
|
||||
/**
|
||||
@@ -91,6 +92,10 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === $participant instanceof ParticipantDto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract current skipass selection from submitted data
|
||||
$selectedSkiPass = $this->getFieldValue($submittedData, $this->getFieldName());
|
||||
|
||||
@@ -102,6 +107,13 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
||||
true
|
||||
);
|
||||
|
||||
$currentlySelectedAutoBookSkiPassId = $this->getSelectedAutoBookSkiPassId(
|
||||
$participant,
|
||||
$availableSkipasses,
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
// For single selection, validate the selected skipass and convert ID to Service object
|
||||
$validSelection = null;
|
||||
if (null !== $selectedSkiPass) {
|
||||
@@ -111,10 +123,61 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateAutoBookOptOutSkiPasses($participant, $currentlySelectedAutoBookSkiPassId, $validSelection);
|
||||
|
||||
// Update participant with validated selection
|
||||
$participant->skiPass = $validSelection;
|
||||
}
|
||||
|
||||
private function getSelectedAutoBookSkiPassId(
|
||||
ParticipantDto $participant,
|
||||
array $availableSkipasses,
|
||||
BookingDto $bookingDto,
|
||||
int $participantIndex,
|
||||
): ?int {
|
||||
$currentSkiPass = $participant->skiPass;
|
||||
if (null === $currentSkiPass || null === $currentSkiPass->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (true === $currentSkiPass->mandatory || false === $currentSkiPass->autoBook) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (false === $this->isServiceValidForParticipant($currentSkiPass, $availableSkipasses, $bookingDto, $participantIndex)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $currentSkiPass->id;
|
||||
}
|
||||
|
||||
private function updateAutoBookOptOutSkiPasses(
|
||||
ParticipantDto $participant,
|
||||
?int $currentlySelectedAutoBookSkiPassId,
|
||||
?Service $validSelection,
|
||||
): void {
|
||||
$newlySelectedAutoBookSkiPassId = null;
|
||||
if (null !== $validSelection
|
||||
&& null !== $validSelection->id
|
||||
&& false === $validSelection->mandatory
|
||||
&& true === $validSelection->autoBook) {
|
||||
$newlySelectedAutoBookSkiPassId = $validSelection->id;
|
||||
}
|
||||
|
||||
if (null !== $currentlySelectedAutoBookSkiPassId
|
||||
&& $currentlySelectedAutoBookSkiPassId !== $newlySelectedAutoBookSkiPassId
|
||||
&& false === in_array($currentlySelectedAutoBookSkiPassId, $participant->autoBookOptOutSkiPassIds, true)) {
|
||||
$participant->autoBookOptOutSkiPassIds[] = $currentlySelectedAutoBookSkiPassId;
|
||||
}
|
||||
|
||||
if (null !== $newlySelectedAutoBookSkiPassId) {
|
||||
$participant->autoBookOptOutSkiPassIds = array_values(array_filter(
|
||||
$participant->autoBookOptOutSkiPassIds,
|
||||
static fn (int $serviceId): bool => $serviceId !== $newlySelectedAutoBookSkiPassId
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if a selected skipass is still valid for the participant.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user