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;
|
||||
|
||||
/**
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user