feat: auto-booking services

addresses #869cfcptv
This commit is contained in:
Björn Fromme committed 2026-03-16 20:24:58 +01:00
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;
/**
@@ -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.
*