feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
1 parent
6d9265de0f
commit
c510cbf590
19 files changed
+1829
-72
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user