feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
@@ -29,6 +29,9 @@ class Service
|
|||||||
#[Groups(['api:single', 'api:list'])]
|
#[Groups(['api:single', 'api:list'])]
|
||||||
public bool $mandatory = false;
|
public bool $mandatory = false;
|
||||||
|
|
||||||
|
#[Groups(['api:single', 'api:list'])]
|
||||||
|
public bool $autoBook = false;
|
||||||
|
|
||||||
#[Groups(['api:single', 'api:list'])]
|
#[Groups(['api:single', 'api:list'])]
|
||||||
public ?string $label = null;
|
public ?string $label = null;
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ class TravelParser extends AbstractParser
|
|||||||
$service->id = $serviceId;
|
$service->id = $serviceId;
|
||||||
$service->subType = $serviceNode->attr('unterart');
|
$service->subType = $serviceNode->attr('unterart');
|
||||||
$service->mandatory = $this->stringToBool($serviceNode->attr('pflicht'));
|
$service->mandatory = $this->stringToBool($serviceNode->attr('pflicht'));
|
||||||
|
$autoBookValue = $serviceNode->attr('automatisch_buchen');
|
||||||
|
$service->autoBook = $this->stringToBool($autoBookValue)
|
||||||
|
|| 'true' === strtolower((string) $autoBookValue);
|
||||||
$service->dateFrom = $this->stringToDate($serviceNode->attr('termin'));
|
$service->dateFrom = $this->stringToDate($serviceNode->attr('termin'));
|
||||||
$service->dateTo = $this->stringToDate($serviceNode->attr('bis'));
|
$service->dateTo = $this->stringToDate($serviceNode->attr('bis'));
|
||||||
$service->label = $this->getStringOrNullValue($serviceNode->filterXPath('//text'));
|
$service->label = $this->getStringOrNullValue($serviceNode->filterXPath('//text'));
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Step2Controller extends AbstractController
|
|||||||
$this->roomAssignmentService->assignRoomsIfNeeded($bookingCreateDto);
|
$this->roomAssignmentService->assignRoomsIfNeeded($bookingCreateDto);
|
||||||
|
|
||||||
// Preselect mandatory services
|
// Preselect mandatory services
|
||||||
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
|
$this->bookingService->preselectDefaultServices($bookingCreateDto);
|
||||||
|
|
||||||
// Save BookingDto to session
|
// Save BookingDto to session
|
||||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||||
@@ -149,18 +149,19 @@ class Step2Controller extends AbstractController
|
|||||||
$form = $this->createParticipantForm($bookingDto, $index);
|
$form = $this->createParticipantForm($bookingDto, $index);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
$isSubmitted = $form->isSubmitted();
|
||||||
|
|
||||||
// Detect dummy data fill token — render pre-filled form immediately, skipping validation
|
// Detect dummy data fill token — render pre-filled form immediately, skipping validation
|
||||||
$isDummyDataFill = $this
|
$isDummyDataFill = $this
|
||||||
->dummyDataFillService
|
->dummyDataFillService
|
||||||
->isTokenMatch($bookingDto->participants[$index], $bookingDto->getMode())
|
->isTokenMatch($bookingDto->participants[$index], $bookingDto->getMode())
|
||||||
;
|
;
|
||||||
if (true === $form->isSubmitted() && true === $isDummyDataFill) {
|
if (true === $isSubmitted && true === $isDummyDataFill) {
|
||||||
$this->dummyDataFillService->fill($bookingDto->participants[$index], $index);
|
$this->dummyDataFillService->fill($bookingDto->participants[$index], $index);
|
||||||
|
|
||||||
// Keep behavior consistent with cards view: newly filled participant data
|
// Keep behavior consistent with cards view: newly filled participant data
|
||||||
// (especially dateOfBirth) must immediately trigger mandatory service preselection.
|
// (especially dateOfBirth) must immediately trigger mandatory service preselection.
|
||||||
$this->bookingService->preselectMandatoryServices($bookingDto);
|
$this->bookingService->preselectDefaultServices($bookingDto);
|
||||||
|
|
||||||
$bookingDto->bookingStatus = Constants::BOOKING_STATUS_OPEN;
|
$bookingDto->bookingStatus = Constants::BOOKING_STATUS_OPEN;
|
||||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
||||||
@@ -171,10 +172,16 @@ class Step2Controller extends AbstractController
|
|||||||
return $this->renderParticipantForm($form, $index, $bookingDto);
|
return $this->renderParticipantForm($form, $index, $bookingDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true === $isSubmitted) {
|
||||||
|
// Re-run default preselection after participant form input changes (e.g. DOB).
|
||||||
|
// This ensures auto-book defaults are applied as soon as eligibility becomes known.
|
||||||
|
$this->bookingService->preselectDefaultServices($bookingDto);
|
||||||
|
}
|
||||||
|
|
||||||
// Collect notifications from field handlers (run during PRE_SUBMIT)
|
// Collect notifications from field handlers (run during PRE_SUBMIT)
|
||||||
$notifications = $this->collectAndClearNotifications($bookingDto);
|
$notifications = $this->collectAndClearNotifications($bookingDto);
|
||||||
|
|
||||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
if (true === $isSubmitted && true === $form->isValid()) {
|
||||||
// Save BookingDto to session
|
// Save BookingDto to session
|
||||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
||||||
|
|
||||||
|
|||||||
@@ -122,13 +122,19 @@ trait ParticipantCardFlowTrait
|
|||||||
int $index,
|
int $index,
|
||||||
string $refreshRouteName,
|
string $refreshRouteName,
|
||||||
): Response {
|
): Response {
|
||||||
|
$refreshFormOptions = ['validation_groups' => false];
|
||||||
|
|
||||||
// Create form with validation disabled
|
// Create form with validation disabled
|
||||||
$form = $this->createParticipantForm($bookingDto, $index, [
|
$form = $this->createParticipantForm($bookingDto, $index, $refreshFormOptions);
|
||||||
'validation_groups' => false,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
// Refresh endpoint is POST-only and always processes submitted participant data.
|
||||||
|
$this->bookingService->preselectDefaultServices($bookingDto);
|
||||||
|
|
||||||
|
// Recreate form so the rendered state reflects any new auto-preselections.
|
||||||
|
$form = $this->createParticipantForm($bookingDto, $index, $refreshFormOptions);
|
||||||
|
|
||||||
// Collect notifications from field handlers
|
// Collect notifications from field handlers
|
||||||
$notifications = $this->collectAndClearNotifications($bookingDto);
|
$notifications = $this->collectAndClearNotifications($bookingDto);
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ class ParticipantDto
|
|||||||
|
|
||||||
public array $courses = [];
|
public array $courses = [];
|
||||||
public array $additionalServices = [];
|
public array $additionalServices = [];
|
||||||
|
public array $autoBookOptOutServiceIds = [];
|
||||||
|
public array $autoBookOptOutSkiPassIds = [];
|
||||||
|
public array $autoBookOptOutBoardIds = [];
|
||||||
|
public array $autoBookOptOutRentalIds = [];
|
||||||
|
|
||||||
// Note: Ski pass validation is conditional - see ParticipantEditDto::validateSkiPassRequired()
|
// Note: Ski pass validation is conditional - see ParticipantEditDto::validateSkiPassRequired()
|
||||||
// Babies (0-2 years) are exempt from ski pass requirement
|
// 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\Constants;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,6 +97,10 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === $participant instanceof ParticipantDto) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Extract current service selections from submitted data
|
// Extract current service selections from submitted data
|
||||||
$selectedServices = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
$selectedServices = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||||
|
|
||||||
@@ -114,10 +119,66 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
|||||||
$participantIndex
|
$participantIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->updateAutoBookOptOutServices(
|
||||||
|
$participant,
|
||||||
|
$availableServices,
|
||||||
|
$validSelections,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex
|
||||||
|
);
|
||||||
|
|
||||||
// Update participant with validated selections
|
// Update participant with validated selections
|
||||||
$participant->additionalServices = $validSelections;
|
$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.
|
* 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\Constants;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +58,10 @@ class ParticipantBoardFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === $participant instanceof ParticipantDto) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$selectedBoard = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
$selectedBoard = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||||
|
|
||||||
// Get available board options from travel data (includes booked options in edit mode)
|
// Get available board options from travel data (includes booked options in edit mode)
|
||||||
@@ -73,9 +78,63 @@ class ParticipantBoardFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
$participantIndex
|
$participantIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->updateAutoBookOptOutBoard(
|
||||||
|
$participant,
|
||||||
|
$availableBoard,
|
||||||
|
$validSelections,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex
|
||||||
|
);
|
||||||
|
|
||||||
$participant->board = $validSelections;
|
$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(
|
private function filterValidServiceSelections(
|
||||||
array $selectedServices,
|
array $selectedServices,
|
||||||
array $availableServices,
|
array $availableServices,
|
||||||
|
|||||||
@@ -249,13 +249,26 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
|||||||
|
|
||||||
$attributes = [];
|
$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
|
// Add service description as data attribute for frontend use
|
||||||
if (null !== $service->description && '' !== trim($service->description)) {
|
if (null !== $service->description && '' !== trim($service->description)) {
|
||||||
$attributes['data-description'] = $service->description;
|
$attributes['data-description'] = $service->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
// Make readonly if service is unavailable (only if not already mandatory)
|
||||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'board')) {
|
if (false === $service->mandatory
|
||||||
|
&& $this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'board')) {
|
||||||
$attributes['readonly'] = true;
|
$attributes['readonly'] = true;
|
||||||
$attributes['data-tooltip'] = 'ausgebucht';
|
$attributes['data-tooltip'] = 'ausgebucht';
|
||||||
}
|
}
|
||||||
@@ -361,13 +374,26 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
|||||||
|
|
||||||
$attributes = [];
|
$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
|
// Add service description as data attribute for frontend use
|
||||||
if (null !== $service->description && '' !== trim($service->description)) {
|
if (null !== $service->description && '' !== trim($service->description)) {
|
||||||
$attributes['data-description'] = $service->description;
|
$attributes['data-description'] = $service->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
// Make readonly if service is unavailable (only if not already mandatory)
|
||||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'rentals')) {
|
if (false === $service->mandatory
|
||||||
|
&& $this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'rentals')) {
|
||||||
$attributes['readonly'] = true;
|
$attributes['readonly'] = true;
|
||||||
$attributes['data-tooltip'] = 'ausgebucht';
|
$attributes['data-tooltip'] = 'ausgebucht';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
|||||||
use App\BusProNet\Constants;
|
use App\BusProNet\Constants;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +66,10 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === $participant instanceof ParticipantDto) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Store previous rental state BEFORE checking skipass
|
// Store previous rental state BEFORE checking skipass
|
||||||
$previousRentals = $participant->rentals;
|
$previousRentals = $participant->rentals;
|
||||||
|
|
||||||
@@ -102,6 +107,14 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
$participantIndex
|
$participantIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->updateAutoBookOptOutRentals(
|
||||||
|
$participant,
|
||||||
|
$durationFilteredRentals,
|
||||||
|
$validSelections,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex
|
||||||
|
);
|
||||||
|
|
||||||
// Notify if rentals were cleared due to skipass duration change
|
// Notify if rentals were cleared due to skipass duration change
|
||||||
// Only show notification if user had submitted rentals that got filtered out,
|
// Only show notification if user had submitted rentals that got filtered out,
|
||||||
// not if the user intentionally cleared the selection (empty submission)
|
// not if the user intentionally cleared the selection (empty submission)
|
||||||
@@ -115,6 +128,52 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
$participant->rentals = $validSelections;
|
$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(
|
private function filterValidServiceSelections(
|
||||||
array $selectedServices,
|
array $selectedServices,
|
||||||
array $availableServices,
|
array $availableServices,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Form\Service;
|
|||||||
use App\BusProNet\Constants;
|
use App\BusProNet\Constants;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +92,10 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === $participant instanceof ParticipantDto) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Extract current skipass selection from submitted data
|
// Extract current skipass selection from submitted data
|
||||||
$selectedSkiPass = $this->getFieldValue($submittedData, $this->getFieldName());
|
$selectedSkiPass = $this->getFieldValue($submittedData, $this->getFieldName());
|
||||||
|
|
||||||
@@ -102,6 +107,13 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$currentlySelectedAutoBookSkiPassId = $this->getSelectedAutoBookSkiPassId(
|
||||||
|
$participant,
|
||||||
|
$availableSkipasses,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex
|
||||||
|
);
|
||||||
|
|
||||||
// For single selection, validate the selected skipass and convert ID to Service object
|
// For single selection, validate the selected skipass and convert ID to Service object
|
||||||
$validSelection = null;
|
$validSelection = null;
|
||||||
if (null !== $selectedSkiPass) {
|
if (null !== $selectedSkiPass) {
|
||||||
@@ -111,10 +123,61 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->updateAutoBookOptOutSkiPasses($participant, $currentlySelectedAutoBookSkiPassId, $validSelection);
|
||||||
|
|
||||||
// Update participant with validated selection
|
// Update participant with validated selection
|
||||||
$participant->skiPass = $validSelection;
|
$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.
|
* Validates if a selected skipass is still valid for the participant.
|
||||||
*
|
*
|
||||||
|
|||||||
+435
-60
@@ -6,12 +6,14 @@ namespace App\Service;
|
|||||||
|
|
||||||
use App\BusProNet\Constants;
|
use App\BusProNet\Constants;
|
||||||
use App\BusProNet\Model\Room;
|
use App\BusProNet\Model\Room;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
use App\Exception\BookingSessionNotFoundException;
|
use App\Exception\BookingSessionNotFoundException;
|
||||||
use App\Exception\NoRoomsAvailableException;
|
use App\Exception\NoRoomsAvailableException;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Service\ServiceAgeEvaluator;
|
||||||
use App\Form\Model\RoomSelectionDto;
|
use App\Form\Model\RoomSelectionDto;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -460,72 +462,445 @@ class BookingService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre-selects mandatory services for all participants in the booking DTO.
|
* Pre-selects default services for all participants.
|
||||||
*
|
*
|
||||||
* This method ensures that mandatory services are selected before form rendering
|
* Mandatory and auto-book rules are handled in dedicated methods:
|
||||||
* and pricing calculations, resolving timing issues where mandatory services
|
* mandatory first, auto-book second.
|
||||||
* were only selected during form rendering via choice_attr callbacks.
|
*/
|
||||||
*
|
public function preselectDefaultServices(BookingDto $bookingDto): void
|
||||||
* Mandatory services are only preselected for eligible participants - those who
|
{
|
||||||
* have at least one skipass available for their age. Ineligible participants are
|
$additionalServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_ADDITIONAL);
|
||||||
* skipped to prevent their mandatory services from being included in pricing.
|
$mandatoryAdditionalServices = array_filter(
|
||||||
*
|
$additionalServices,
|
||||||
* @param BookingDto $bookingDto The booking DTO to update with mandatory services
|
static fn (Service $service): bool => true === $service->mandatory
|
||||||
|
);
|
||||||
|
$autoBookAdditionalServices = array_filter(
|
||||||
|
$additionalServices,
|
||||||
|
// Services that are both mandatory and auto-book belong to mandatory bucket only.
|
||||||
|
static fn (Service $service): bool => true === $service->autoBook && false === $service->mandatory
|
||||||
|
);
|
||||||
|
|
||||||
|
$skiPassServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_SKI_PASS, true);
|
||||||
|
$mandatorySkiPassServices = array_filter(
|
||||||
|
$skiPassServices,
|
||||||
|
static fn (Service $service): bool => true === $service->mandatory
|
||||||
|
);
|
||||||
|
$autoBookSkiPassServices = array_filter(
|
||||||
|
$skiPassServices,
|
||||||
|
// Services that are both mandatory and auto-book belong to mandatory bucket only.
|
||||||
|
static fn (Service $service): bool => true === $service->autoBook && false === $service->mandatory
|
||||||
|
);
|
||||||
|
|
||||||
|
$boardServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_BOARD, true);
|
||||||
|
$mandatoryBoardServices = array_filter(
|
||||||
|
$boardServices,
|
||||||
|
static fn (Service $service): bool => true === $service->mandatory
|
||||||
|
);
|
||||||
|
$autoBookBoardServices = array_filter(
|
||||||
|
$boardServices,
|
||||||
|
// Services that are both mandatory and auto-book belong to mandatory bucket only.
|
||||||
|
static fn (Service $service): bool => true === $service->autoBook && false === $service->mandatory
|
||||||
|
);
|
||||||
|
|
||||||
|
$rentalServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTALS, true);
|
||||||
|
$mandatoryRentalServices = array_filter(
|
||||||
|
$rentalServices,
|
||||||
|
static fn (Service $service): bool => true === $service->mandatory
|
||||||
|
);
|
||||||
|
$autoBookRentalServices = array_filter(
|
||||||
|
$rentalServices,
|
||||||
|
// Services that are both mandatory and auto-book belong to mandatory bucket only.
|
||||||
|
static fn (Service $service): bool => true === $service->autoBook && false === $service->mandatory
|
||||||
|
);
|
||||||
|
|
||||||
|
$ageEvaluator = new ServiceAgeEvaluator();
|
||||||
|
|
||||||
|
foreach ($bookingDto->participants as $participantIndex => $participant) {
|
||||||
|
if (false === $this->canPreselectServicesForParticipant($bookingDto, $participantIndex, $participant)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preselectMandatoryAdditionalServices(
|
||||||
|
$participant,
|
||||||
|
$mandatoryAdditionalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectAutoBookAdditionalServices(
|
||||||
|
$participant,
|
||||||
|
$autoBookAdditionalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectMandatorySkiPass(
|
||||||
|
$participant,
|
||||||
|
$mandatorySkiPassServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectAutoBookSkiPass(
|
||||||
|
$participant,
|
||||||
|
$autoBookSkiPassServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectMandatoryBoardServices(
|
||||||
|
$participant,
|
||||||
|
$mandatoryBoardServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectAutoBookBoardServices(
|
||||||
|
$participant,
|
||||||
|
$autoBookBoardServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectMandatoryRentals(
|
||||||
|
$participant,
|
||||||
|
$mandatoryRentalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
$this->preselectAutoBookRentals(
|
||||||
|
$participant,
|
||||||
|
$autoBookRentalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use preselectDefaultServices() instead.
|
||||||
*/
|
*/
|
||||||
public function preselectMandatoryServices(BookingDto $bookingDto): void
|
public function preselectMandatoryServices(BookingDto $bookingDto): void
|
||||||
{
|
{
|
||||||
$additionalServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_ADDITIONAL);
|
$this->preselectDefaultServices($bookingDto);
|
||||||
$mandatoryServices = array_filter($additionalServices, fn ($service) => true === $service->mandatory);
|
}
|
||||||
|
|
||||||
// Pre-select mandatory services for each participant
|
private function canPreselectServicesForParticipant(
|
||||||
foreach ($bookingDto->participants as $participantIndex => $participant) {
|
BookingDto $bookingDto,
|
||||||
if (null === $participant->dateOfBirth) {
|
int $participantIndex,
|
||||||
continue; // Skip participants without age information
|
ParticipantDto $participant,
|
||||||
}
|
): bool {
|
||||||
|
if (null === $participant->dateOfBirth) {
|
||||||
// Skip babies - they only get services with explicit age ranges (handled by field filtering)
|
return false;
|
||||||
$age = $participant->getAge($bookingDto->travel->dateFrom);
|
|
||||||
if (null !== $age && $age <= Constants::BABY_MAX_AGE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip ineligible participants (no skipasses available for their age)
|
|
||||||
if (false === $this->participantEligibilityService->isParticipantEligible($bookingDto, $participantIndex)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get age-appropriate mandatory services for this participant
|
|
||||||
$ageAppropriateServices = array_filter($mandatoryServices, function ($service) use ($bookingDto, $participant) {
|
|
||||||
if (null === $service->ageFrom && null === $service->ageTo) {
|
|
||||||
return true; // No age restrictions
|
|
||||||
}
|
|
||||||
|
|
||||||
// participant's age at travel date is relevant
|
|
||||||
$age = $participant->getAge($bookingDto->travel->dateFrom);
|
|
||||||
|
|
||||||
if (null !== $service->ageFrom && $age < $service->ageFrom) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $service->ageTo && $age > $service->ageTo) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add mandatory services to current selections
|
|
||||||
$currentSelections = $participant->additionalServices ?? [];
|
|
||||||
$currentServiceIds = array_map(fn ($service) => $service->id, $currentSelections);
|
|
||||||
|
|
||||||
foreach ($ageAppropriateServices as $mandatoryService) {
|
|
||||||
if (false === in_array($mandatoryService->id, $currentServiceIds, true)) {
|
|
||||||
$currentSelections[] = $mandatoryService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$participant->additionalServices = $currentSelections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$age = $participant->getAge($bookingDto->travel->dateFrom);
|
||||||
|
if (null !== $age && $age <= Constants::BABY_MAX_AGE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->participantEligibilityService->isParticipantEligible($bookingDto, $participantIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectMandatoryAdditionalServices(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $mandatoryAdditionalServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$mandatoryAdditionalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->appendAdditionalServices($participant, $eligibleServices, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectAutoBookAdditionalServices(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $autoBookAdditionalServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$autoBookAdditionalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->appendAdditionalServices($participant, $eligibleServices, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectMandatorySkiPass(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $mandatorySkiPassServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
if (null !== $participant->skiPass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$mandatorySkiPassServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($eligibleServices as $service) {
|
||||||
|
$participant->skiPass = $service;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectAutoBookSkiPass(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $autoBookSkiPassServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
if (null !== $participant->skiPass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$autoBookSkiPassServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($eligibleServices as $service) {
|
||||||
|
if (null !== $service->id
|
||||||
|
&& true === in_array($service->id, $participant->autoBookOptOutSkiPassIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$participant->skiPass = $service;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectMandatoryBoardServices(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $mandatoryBoardServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$mandatoryBoardServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->appendBoardServices($participant, $eligibleServices, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectAutoBookBoardServices(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $autoBookBoardServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$autoBookBoardServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->appendBoardServices($participant, $eligibleServices, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectMandatoryRentals(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $mandatoryRentalServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
if (null === $participant->skiPass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$mandatoryRentalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$matchingDurationServices = $this->getRentalsMatchingSkiPassDuration($eligibleServices, $participant);
|
||||||
|
|
||||||
|
$this->appendRentalServices($participant, $matchingDurationServices, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function preselectAutoBookRentals(
|
||||||
|
ParticipantDto $participant,
|
||||||
|
array $autoBookRentalServices,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): void {
|
||||||
|
if (null === $participant->skiPass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$eligibleServices = $this->getEligibleServicesForParticipant(
|
||||||
|
$autoBookRentalServices,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
);
|
||||||
|
|
||||||
|
$matchingDurationServices = $this->getRentalsMatchingSkiPassDuration($eligibleServices, $participant);
|
||||||
|
|
||||||
|
$this->appendRentalServices($participant, $matchingDurationServices, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Service[] $services
|
||||||
|
*
|
||||||
|
* @return Service[]
|
||||||
|
*/
|
||||||
|
private function getEligibleServicesForParticipant(
|
||||||
|
array $services,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): array {
|
||||||
|
return array_filter(
|
||||||
|
$services,
|
||||||
|
fn (Service $service): bool => $this->isServiceAvailableForParticipant(
|
||||||
|
$service,
|
||||||
|
$bookingDto,
|
||||||
|
$participantIndex,
|
||||||
|
$ageEvaluator
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Service[] $services
|
||||||
|
*/
|
||||||
|
private function appendAdditionalServices(ParticipantDto $participant, array $services, bool $respectOptOut): void
|
||||||
|
{
|
||||||
|
$currentSelections = $participant->additionalServices ?? [];
|
||||||
|
$currentServiceIds = array_map(static fn (Service $service): ?int => $service->id, $currentSelections);
|
||||||
|
|
||||||
|
foreach ($services as $service) {
|
||||||
|
if (null === $service->id || true === in_array($service->id, $currentServiceIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $respectOptOut
|
||||||
|
&& true === in_array($service->id, $participant->autoBookOptOutServiceIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentSelections[] = $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
$participant->additionalServices = $currentSelections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Service[] $services
|
||||||
|
*/
|
||||||
|
private function appendBoardServices(ParticipantDto $participant, array $services, bool $respectOptOut): void
|
||||||
|
{
|
||||||
|
$currentSelections = $participant->board ?? [];
|
||||||
|
$currentServiceIds = array_map(static fn (Service $service): ?int => $service->id, $currentSelections);
|
||||||
|
|
||||||
|
foreach ($services as $service) {
|
||||||
|
if (null === $service->id || true === in_array($service->id, $currentServiceIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $respectOptOut
|
||||||
|
&& true === in_array($service->id, $participant->autoBookOptOutBoardIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentSelections[] = $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
$participant->board = $currentSelections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Service[] $services
|
||||||
|
*/
|
||||||
|
private function appendRentalServices(ParticipantDto $participant, array $services, bool $respectOptOut): void
|
||||||
|
{
|
||||||
|
$currentSelections = $participant->rentals ?? [];
|
||||||
|
$currentServiceIds = array_map(static fn (Service $service): ?int => $service->id, $currentSelections);
|
||||||
|
|
||||||
|
foreach ($services as $service) {
|
||||||
|
if (null === $service->id || true === in_array($service->id, $currentServiceIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $respectOptOut
|
||||||
|
&& true === in_array($service->id, $participant->autoBookOptOutRentalIds, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentSelections[] = $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
$participant->rentals = $currentSelections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Service[] $rentals
|
||||||
|
*
|
||||||
|
* @return Service[]
|
||||||
|
*/
|
||||||
|
private function getRentalsMatchingSkiPassDuration(array $rentals, ParticipantDto $participant): array
|
||||||
|
{
|
||||||
|
$selectedSkiPass = $participant->skiPass;
|
||||||
|
if (null === $selectedSkiPass || null === $selectedSkiPass->dateFrom || null === $selectedSkiPass->dateTo) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_filter($rentals, static function (Service $rental) use ($selectedSkiPass): bool {
|
||||||
|
if (null === $rental->dateFrom || null === $rental->dateTo) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rental->dateFrom == $selectedSkiPass->dateFrom
|
||||||
|
&& $rental->dateTo == $selectedSkiPass->dateTo;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isServiceAvailableForParticipant(
|
||||||
|
Service $service,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $participantIndex,
|
||||||
|
ServiceAgeEvaluator $ageEvaluator,
|
||||||
|
): bool
|
||||||
|
{
|
||||||
|
if (false === $ageEvaluator->canEvaluate($service)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TravelParserTest extends TestCase
|
|||||||
<preis>0,00</preis>
|
<preis>0,00</preis>
|
||||||
<status>Frei</status>
|
<status>Frei</status>
|
||||||
</leistung>
|
</leistung>
|
||||||
<leistung id="2" idbuspro="183659" unterart="SON" termin="01.01.2030" bis="06.01.2030" automatisch_buchen="False" pflicht="False">
|
<leistung id="2" idbuspro="183659" unterart="SON" termin="01.01.2030" bis="06.01.2030" automatisch_buchen="True" pflicht="False">
|
||||||
<text>Bettwäsche-Set inkl. Handtuch</text>
|
<text>Bettwäsche-Set inkl. Handtuch</text>
|
||||||
<hinweis>Das Bettwäsche-Set umfasst Spannbettlaken, Kissen- und Deckenbezug. Beim Handtuch handelt es sich um ein Duschtuch (ca. 70x140cm).</hinweis>
|
<hinweis>Das Bettwäsche-Set umfasst Spannbettlaken, Kissen- und Deckenbezug. Beim Handtuch handelt es sich um ein Duschtuch (ca. 70x140cm).</hinweis>
|
||||||
<preis>13,90</preis>
|
<preis>13,90</preis>
|
||||||
@@ -92,6 +92,7 @@ class TravelParserTest extends TestCase
|
|||||||
'Das Bettwäsche-Set umfasst Spannbettlaken, Kissen- und Deckenbezug. Beim Handtuch handelt es sich um ein Duschtuch (ca. 70x140cm).',
|
'Das Bettwäsche-Set umfasst Spannbettlaken, Kissen- und Deckenbezug. Beim Handtuch handelt es sich um ein Duschtuch (ca. 70x140cm).',
|
||||||
$bettwascheService->description
|
$bettwascheService->description
|
||||||
);
|
);
|
||||||
|
$this->assertTrue($bettwascheService->autoBook);
|
||||||
|
|
||||||
// Service without description (ID 183656 - Skipass, has hinweis_stamm but no hinweis)
|
// Service without description (ID 183656 - Skipass, has hinweis_stamm but no hinweis)
|
||||||
$this->assertArrayHasKey(183656, $additionalServices);
|
$this->assertArrayHasKey(183656, $additionalServices);
|
||||||
@@ -112,6 +113,7 @@ class TravelParserTest extends TestCase
|
|||||||
$busService = $transportationServices[183649];
|
$busService = $transportationServices[183649];
|
||||||
$this->assertSame('Bus-Hinfahrt', $busService->label);
|
$this->assertSame('Bus-Hinfahrt', $busService->label);
|
||||||
$this->assertSame('Bus fährt nur bei ausreichender Teilnehmerzahl', $busService->description);
|
$this->assertSame('Bus fährt nur bei ausreichender Teilnehmerzahl', $busService->description);
|
||||||
|
$this->assertFalse($busService->autoBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParseServiceWithoutDescriptions(): void
|
public function testParseServiceWithoutDescriptions(): void
|
||||||
@@ -149,6 +151,39 @@ class TravelParserTest extends TestCase
|
|||||||
$this->assertNull($service->description); // No hinweis node should result in null description
|
$this->assertNull($service->description); // No hinweis node should result in null description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseServiceWithLowerCaseAutoBookFlag(): void
|
||||||
|
{
|
||||||
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<reisen>
|
||||||
|
<reise id="1" idbuspro="2187" code="SSTMR">
|
||||||
|
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
|
||||||
|
<text>Test Travel</text>
|
||||||
|
<abpreis>659,00</abpreis>
|
||||||
|
<lei_sonstiges>
|
||||||
|
<leistung id="1" idbuspro="183660" unterart="VPF" automatisch_buchen="true" pflicht="False">
|
||||||
|
<text>Service with auto-book</text>
|
||||||
|
<preis>8,90</preis>
|
||||||
|
<status>Frei</status>
|
||||||
|
</leistung>
|
||||||
|
</lei_sonstiges>
|
||||||
|
<hotel id="1" idbuspro="157047">
|
||||||
|
<zimmer>
|
||||||
|
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="8" />
|
||||||
|
</zimmer>
|
||||||
|
</hotel>
|
||||||
|
</termin>
|
||||||
|
</reise>
|
||||||
|
</reisen>';
|
||||||
|
|
||||||
|
$crawler = new Crawler($xmlContent);
|
||||||
|
$travelNode = $crawler->filterXPath('//reise/termin')->first();
|
||||||
|
$travel = $this->parser->parse($travelNode);
|
||||||
|
|
||||||
|
$additionalServices = $travel->additionalServices;
|
||||||
|
$this->assertArrayHasKey(183660, $additionalServices);
|
||||||
|
$this->assertTrue($additionalServices[183660]->autoBook);
|
||||||
|
}
|
||||||
|
|
||||||
public function testParseServiceWithEmptyDescription(): void
|
public function testParseServiceWithEmptyDescription(): void
|
||||||
{
|
{
|
||||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Controller\Booking;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Controller\Booking\Traits\ParticipantCardFlowTrait;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\BookingSummaryDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Service\BookingService;
|
||||||
|
use App\Service\BookingSummaryDataService;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\Form\FormView;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class ParticipantCardFlowTraitTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testHandleParticipantRefreshReappliesDefaultPreselectionInEditMode(): void
|
||||||
|
{
|
||||||
|
$bookingService = $this->createMock(BookingService::class);
|
||||||
|
$summaryDataService = $this->createMock(BookingSummaryDataService::class);
|
||||||
|
|
||||||
|
$formOne = $this->createMock(FormInterface::class);
|
||||||
|
$formOne->expects($this->once())
|
||||||
|
->method('handleRequest');
|
||||||
|
$formOne->method('isSubmitted')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$formTwo = $this->createMock(FormInterface::class);
|
||||||
|
$formTwo->expects($this->once())
|
||||||
|
->method('createView')
|
||||||
|
->willReturn(new FormView());
|
||||||
|
|
||||||
|
$bookingDto = $this->createEditModeBookingDto();
|
||||||
|
$request = new Request();
|
||||||
|
|
||||||
|
$bookingService->expects($this->once())
|
||||||
|
->method('preselectDefaultServices')
|
||||||
|
->with($bookingDto);
|
||||||
|
|
||||||
|
$bookingService->expects($this->once())
|
||||||
|
->method('saveBookingDto')
|
||||||
|
->with($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||||
|
|
||||||
|
$summaryDataService->expects($this->once())
|
||||||
|
->method('getSummaryData')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn(new BookingSummaryDto([], 1, 0.0, 0.0, [], [], [], null));
|
||||||
|
|
||||||
|
$controller = new class($bookingService, $summaryDataService, [$formOne, $formTwo]) {
|
||||||
|
use ParticipantCardFlowTrait;
|
||||||
|
|
||||||
|
public BookingService $bookingService;
|
||||||
|
public BookingSummaryDataService $summaryDataService;
|
||||||
|
public object $participantCardService;
|
||||||
|
|
||||||
|
/** @var FormInterface[] */
|
||||||
|
private array $forms;
|
||||||
|
|
||||||
|
public function __construct(BookingService $bookingService, BookingSummaryDataService $summaryDataService, array $forms)
|
||||||
|
{
|
||||||
|
$this->bookingService = $bookingService;
|
||||||
|
$this->summaryDataService = $summaryDataService;
|
||||||
|
$this->forms = $forms;
|
||||||
|
$this->participantCardService = new class() {
|
||||||
|
public function getAllCardsData(BookingDto $bookingDto): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function callHandleParticipantRefresh(
|
||||||
|
Request $request,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $index,
|
||||||
|
string $refreshRouteName,
|
||||||
|
): Response {
|
||||||
|
$method = new \ReflectionMethod($this, 'handleParticipantRefresh');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
return $method->invoke($this, $request, $bookingDto, $index, $refreshRouteName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function htmxOobResponse(string $template, array $blocks, array $parameters): Response
|
||||||
|
{
|
||||||
|
return new Response('ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getParameter(string $name): mixed
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createForm(string $type, $data = null, array $options = []): FormInterface
|
||||||
|
{
|
||||||
|
return array_shift($this->forms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||||
|
{
|
||||||
|
return new Response('rendered');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addFlash(string $type, mixed $message): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||||
|
{
|
||||||
|
return new RedirectResponse('/');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$response = $controller->callHandleParticipantRefresh(
|
||||||
|
$request,
|
||||||
|
$bookingDto,
|
||||||
|
0,
|
||||||
|
'app_booking_edit_step_2_participant_refresh'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame('ok', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createEditModeBookingDto(): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 157047);
|
||||||
|
$bookingDto->booking = new Booking(); // Marks DTO as edit mode
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = new \DateTimeImmutable('1990-01-01');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Form\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Service\ParticipantAdditionalServicesFieldHandler;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParticipantAdditionalServicesFieldHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDeselectAutoBookServiceAddsOptOutId(): void
|
||||||
|
{
|
||||||
|
$autoBookService = new Service();
|
||||||
|
$autoBookService->id = 10;
|
||||||
|
$autoBookService->subType = Constants::TOKEN_ADDITIONAL;
|
||||||
|
$autoBookService->label = 'Auto Book';
|
||||||
|
$autoBookService->autoBook = true;
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [10 => $autoBookService];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->additionalServices = [$autoBookService];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$handler = new ParticipantAdditionalServicesFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([10], $participant->autoBookOptOutServiceIds);
|
||||||
|
$this->assertSame([], $participant->additionalServices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeselectMandatoryAutoBookServiceDoesNotAddOptOutId(): void
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 11;
|
||||||
|
$service->subType = Constants::TOKEN_ADDITIONAL;
|
||||||
|
$service->label = 'Mandatory Auto Book';
|
||||||
|
$service->mandatory = true;
|
||||||
|
$service->autoBook = true;
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [11 => $service];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->additionalServices = [$service];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$handler = new ParticipantAdditionalServicesFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutServiceIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Form\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Service\ParticipantBoardFieldHandler;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParticipantBoardFieldHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDeselectAutoBookBoardAddsOptOutId(): void
|
||||||
|
{
|
||||||
|
$autoBookBoard = new Service();
|
||||||
|
$autoBookBoard->id = 60;
|
||||||
|
$autoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||||
|
$autoBookBoard->label = 'Auto Book Board';
|
||||||
|
$autoBookBoard->autoBook = true;
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [60 => $autoBookBoard];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->board = [$autoBookBoard];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$handler = new ParticipantBoardFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([60], $participant->autoBookOptOutBoardIds);
|
||||||
|
$this->assertSame([], $participant->board);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeselectMandatoryAutoBookBoardDoesNotAddOptOutId(): void
|
||||||
|
{
|
||||||
|
$mandatoryAutoBookBoard = new Service();
|
||||||
|
$mandatoryAutoBookBoard->id = 61;
|
||||||
|
$mandatoryAutoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||||
|
$mandatoryAutoBookBoard->label = 'Mandatory Auto Book Board';
|
||||||
|
$mandatoryAutoBookBoard->mandatory = true;
|
||||||
|
$mandatoryAutoBookBoard->autoBook = true;
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [61 => $mandatoryAutoBookBoard];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->board = [$mandatoryAutoBookBoard];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$handler = new ParticipantBoardFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutBoardIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReselectAutoBookBoardRemovesOptOutId(): void
|
||||||
|
{
|
||||||
|
$autoBookBoard = new Service();
|
||||||
|
$autoBookBoard->id = 62;
|
||||||
|
$autoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||||
|
$autoBookBoard->label = 'Auto Book Board';
|
||||||
|
$autoBookBoard->autoBook = true;
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [62 => $autoBookBoard];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->autoBookOptOutBoardIds = [62];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$handler = new ParticipantBoardFieldHandler();
|
||||||
|
$handler->processField(['board' => ['62']], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutBoardIds);
|
||||||
|
$this->assertCount(1, $participant->board);
|
||||||
|
$this->assertSame(62, $participant->board[0]->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,6 +91,7 @@ class ParticipantFieldOptionsProviderMandatoryServiceTest extends TestCase
|
|||||||
$nonMandatoryService->available = 10;
|
$nonMandatoryService->available = 10;
|
||||||
$nonMandatoryService->price = 10.0;
|
$nonMandatoryService->price = 10.0;
|
||||||
$nonMandatoryService->mandatory = false;
|
$nonMandatoryService->mandatory = false;
|
||||||
|
$nonMandatoryService->autoBook = true;
|
||||||
|
|
||||||
$travel = $this->createTravelWithAdditionalServices([$nonMandatoryService]);
|
$travel = $this->createTravelWithAdditionalServices([$nonMandatoryService]);
|
||||||
$bookingDto = new BookingDto($travel, 1);
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Form\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Service\ParticipantRentalsFieldHandler;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParticipantRentalsFieldHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDeselectAutoBookRentalAddsOptOutId(): void
|
||||||
|
{
|
||||||
|
$skiPass = $this->createSkiPass(70);
|
||||||
|
$autoBookRental = $this->createRental(71, autoBook: true, mandatory: false);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $autoBookRental);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->rentals = [$autoBookRental];
|
||||||
|
|
||||||
|
$handler = new ParticipantRentalsFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([71], $participant->autoBookOptOutRentalIds);
|
||||||
|
$this->assertSame([], $participant->rentals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeselectMandatoryAutoBookRentalDoesNotAddOptOutId(): void
|
||||||
|
{
|
||||||
|
$skiPass = $this->createSkiPass(72);
|
||||||
|
$mandatoryAutoBookRental = $this->createRental(73, autoBook: true, mandatory: true);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $mandatoryAutoBookRental);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->rentals = [$mandatoryAutoBookRental];
|
||||||
|
|
||||||
|
$handler = new ParticipantRentalsFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutRentalIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReselectAutoBookRentalRemovesOptOutId(): void
|
||||||
|
{
|
||||||
|
$skiPass = $this->createSkiPass(74);
|
||||||
|
$autoBookRental = $this->createRental(75, autoBook: true, mandatory: false);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $autoBookRental);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->autoBookOptOutRentalIds = [75];
|
||||||
|
|
||||||
|
$handler = new ParticipantRentalsFieldHandler();
|
||||||
|
$handler->processField(['rentals' => ['75']], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutRentalIds);
|
||||||
|
$this->assertCount(1, $participant->rentals);
|
||||||
|
$this->assertSame(75, $participant->rentals[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBookingDtoWithSkiPassAndRental(Service $skiPass, Service $rental): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||||
|
$travel->additionalServices = [
|
||||||
|
$skiPass->id => $skiPass,
|
||||||
|
$rental->id => $rental,
|
||||||
|
];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->skiPass = $skiPass;
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createSkiPass(int $id): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = $id;
|
||||||
|
$service->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$service->label = 'Ski Pass';
|
||||||
|
$service->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$service->dateTo = new \DateTimeImmutable('2030-01-07');
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createRental(int $id, bool $autoBook, bool $mandatory): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = $id;
|
||||||
|
$service->subType = 'VER';
|
||||||
|
$service->label = 'Rental';
|
||||||
|
$service->autoBook = $autoBook;
|
||||||
|
$service->mandatory = $mandatory;
|
||||||
|
$service->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$service->dateTo = new \DateTimeImmutable('2030-01-07');
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Form\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Service\ParticipantSkiPassFieldHandler;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParticipantSkiPassFieldHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDeselectAutoBookSkiPassAddsOptOutId(): void
|
||||||
|
{
|
||||||
|
$autoBookSkiPass = $this->createSkiPass(31, autoBook: true, mandatory: false);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPass($autoBookSkiPass);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->skiPass = $autoBookSkiPass;
|
||||||
|
|
||||||
|
$handler = new ParticipantSkiPassFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([31], $participant->autoBookOptOutSkiPassIds);
|
||||||
|
$this->assertNull($participant->skiPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeselectMandatoryAutoBookSkiPassDoesNotAddOptOutId(): void
|
||||||
|
{
|
||||||
|
$mandatoryAutoBookSkiPass = $this->createSkiPass(32, autoBook: true, mandatory: true);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPass($mandatoryAutoBookSkiPass);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->skiPass = $mandatoryAutoBookSkiPass;
|
||||||
|
|
||||||
|
$handler = new ParticipantSkiPassFieldHandler();
|
||||||
|
$handler->processField([], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutSkiPassIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReselectAutoBookSkiPassRemovesOptOutId(): void
|
||||||
|
{
|
||||||
|
$autoBookSkiPass = $this->createSkiPass(33, autoBook: true, mandatory: false);
|
||||||
|
$bookingDto = $this->createBookingDtoWithSkiPass($autoBookSkiPass);
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->autoBookOptOutSkiPassIds = [33];
|
||||||
|
|
||||||
|
$handler = new ParticipantSkiPassFieldHandler();
|
||||||
|
$handler->processField(['skiPass' => '33'], $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->autoBookOptOutSkiPassIds);
|
||||||
|
$this->assertNotNull($participant->skiPass);
|
||||||
|
$this->assertSame(33, $participant->skiPass?->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBookingDtoWithSkiPass(Service $skiPass): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = [$skiPass->id => $skiPass];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createSkiPass(int $id, bool $autoBook, bool $mandatory): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = $id;
|
||||||
|
$service->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$service->label = 'Ski Pass';
|
||||||
|
$service->autoBook = $autoBook;
|
||||||
|
$service->mandatory = $mandatory;
|
||||||
|
$service->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$service->dateTo = new \DateTimeImmutable('+36 days');
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -189,6 +189,299 @@ class BookingServiceBabyTest extends TestCase
|
|||||||
$this->assertEmpty($participant->additionalServices, 'Age should be calculated at travel date, not current date');
|
$this->assertEmpty($participant->additionalServices, 'Age should be calculated at travel date, not current date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesIncludesAutoBookServiceForEligibleParticipant(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->additionalServices = [];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->additionalServices);
|
||||||
|
$this->assertSame('Auto Book Service', $participant->additionalServices[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesRespectsAutoBookOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->additionalServices = [];
|
||||||
|
$participant->autoBookOptOutServiceIds = [2];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertEmpty($participant->additionalServices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesMandatoryOverridesAutoBookOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithMandatoryAndAutoBookService();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->additionalServices = [];
|
||||||
|
$participant->autoBookOptOutServiceIds = [3];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->additionalServices);
|
||||||
|
$this->assertSame('Mandatory And Auto Book Service', $participant->additionalServices[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesIncludesAutoBookSkiPassForEligibleParticipant(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookSkiPassServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertNotNull($participant->skiPass);
|
||||||
|
$this->assertSame('Auto Book Ski Pass', $participant->skiPass?->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesRespectsAutoBookSkiPassOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookSkiPassServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->autoBookOptOutSkiPassIds = [20];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertNull($participant->skiPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesMandatorySkiPassOverridesAutoBookOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithMandatoryAndAutoBookSkiPassService();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->autoBookOptOutSkiPassIds = [21];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertNotNull($participant->skiPass);
|
||||||
|
$this->assertSame('Mandatory And Auto Book Ski Pass', $participant->skiPass?->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesIncludesAutoBookBoardForEligibleParticipant(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookBoardServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->board);
|
||||||
|
$this->assertSame('Auto Book Board', $participant->board[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesRespectsAutoBookBoardOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookBoardServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->autoBookOptOutBoardIds = [40];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->board);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesMandatoryBoardOverridesAutoBookOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithMandatoryAndAutoBookBoardService();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->autoBookOptOutBoardIds = [41];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->board);
|
||||||
|
$this->assertSame('Mandatory And Auto Book Board', $participant->board[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesIncludesAutoBookRentalForMatchingSkiPass(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookRentalServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->skiPass = $travel->additionalServices[20];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->rentals);
|
||||||
|
$this->assertSame('Auto Book Rental', $participant->rentals[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesRespectsAutoBookRentalOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookRentalServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->skiPass = $travel->additionalServices[20];
|
||||||
|
$participant->autoBookOptOutRentalIds = [50];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->rentals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesMandatoryRentalOverridesAutoBookOptOut(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithMandatoryAndAutoBookRentalServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->skiPass = $travel->additionalServices[22];
|
||||||
|
$participant->autoBookOptOutRentalIds = [51];
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertCount(1, $participant->rentals);
|
||||||
|
$this->assertSame('Mandatory And Auto Book Rental', $participant->rentals[0]->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesSkipsAutoBookRentalWithoutSkiPass(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookRentalServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->rentals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreselectMandatoryServicesSkipsAutoBookRentalForNonMatchingSkiPassDuration(): void
|
||||||
|
{
|
||||||
|
$travel = $this->createTravelWithAutoBookRentalServices();
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||||
|
$participant->skiPass = new Service();
|
||||||
|
$participant->skiPass->id = 99;
|
||||||
|
$participant->skiPass->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$participant->skiPass->dateFrom = new \DateTimeImmutable('+31 days');
|
||||||
|
$participant->skiPass->dateTo = new \DateTimeImmutable('+35 days');
|
||||||
|
$bookingDto->participants[0] = $participant;
|
||||||
|
|
||||||
|
$this->participantEligibilityService
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->bookingService->preselectMandatoryServices($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $participant->rentals);
|
||||||
|
}
|
||||||
|
|
||||||
private function createTravelWithMandatoryServices(): Travel
|
private function createTravelWithMandatoryServices(): Travel
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
@@ -199,6 +492,86 @@ class BookingServiceBabyTest extends TestCase
|
|||||||
return $travel;
|
return $travel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createTravelWithAutoBookServices(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createAutoBookAdditionalServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithMandatoryAndAutoBookService(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createMandatoryAndAutoBookAdditionalServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithAutoBookSkiPassServices(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createAutoBookSkiPassServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithMandatoryAndAutoBookSkiPassService(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createMandatoryAndAutoBookSkiPassServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithAutoBookBoardServices(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createAutoBookBoardServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithMandatoryAndAutoBookBoardService(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||||
|
$travel->additionalServices = $this->createMandatoryAndAutoBookBoardServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithAutoBookRentalServices(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||||
|
$travel->additionalServices = $this->createAutoBookRentalServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTravelWithMandatoryAndAutoBookRentalServices(): Travel
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||||
|
$travel->additionalServices = $this->createMandatoryAndAutoBookRentalServices();
|
||||||
|
|
||||||
|
return $travel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, Service>
|
* @return array<int, Service>
|
||||||
*/
|
*/
|
||||||
@@ -214,4 +587,176 @@ class BookingServiceBabyTest extends TestCase
|
|||||||
|
|
||||||
return [1 => $mandatoryService];
|
return [1 => $mandatoryService];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createAutoBookAdditionalServices(): array
|
||||||
|
{
|
||||||
|
$autoBookService = new Service();
|
||||||
|
$autoBookService->id = 2;
|
||||||
|
$autoBookService->label = 'Auto Book Service';
|
||||||
|
$autoBookService->subType = Constants::TOKEN_ADDITIONAL;
|
||||||
|
$autoBookService->mandatory = false;
|
||||||
|
$autoBookService->autoBook = true;
|
||||||
|
$autoBookService->available = 10;
|
||||||
|
$autoBookService->price = 10.0;
|
||||||
|
|
||||||
|
return [2 => $autoBookService];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createMandatoryAndAutoBookAdditionalServices(): array
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 3;
|
||||||
|
$service->label = 'Mandatory And Auto Book Service';
|
||||||
|
$service->subType = Constants::TOKEN_ADDITIONAL;
|
||||||
|
$service->mandatory = true;
|
||||||
|
$service->autoBook = true;
|
||||||
|
$service->available = 10;
|
||||||
|
$service->price = 10.0;
|
||||||
|
|
||||||
|
return [3 => $service];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createAutoBookSkiPassServices(): array
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 20;
|
||||||
|
$service->label = 'Auto Book Ski Pass';
|
||||||
|
$service->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$service->mandatory = false;
|
||||||
|
$service->autoBook = true;
|
||||||
|
$service->available = 10;
|
||||||
|
$service->price = 59.0;
|
||||||
|
$service->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$service->dateTo = new \DateTimeImmutable('+36 days');
|
||||||
|
|
||||||
|
return [20 => $service];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createMandatoryAndAutoBookSkiPassServices(): array
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 21;
|
||||||
|
$service->label = 'Mandatory And Auto Book Ski Pass';
|
||||||
|
$service->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$service->mandatory = true;
|
||||||
|
$service->autoBook = true;
|
||||||
|
$service->available = 10;
|
||||||
|
$service->price = 59.0;
|
||||||
|
$service->dateFrom = new \DateTimeImmutable('+30 days');
|
||||||
|
$service->dateTo = new \DateTimeImmutable('+36 days');
|
||||||
|
|
||||||
|
return [21 => $service];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createAutoBookBoardServices(): array
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 40;
|
||||||
|
$service->label = 'Auto Book Board';
|
||||||
|
$service->subType = Constants::TOKEN_BOARD;
|
||||||
|
$service->mandatory = false;
|
||||||
|
$service->autoBook = true;
|
||||||
|
$service->available = 10;
|
||||||
|
$service->price = 12.0;
|
||||||
|
|
||||||
|
return [40 => $service];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createMandatoryAndAutoBookBoardServices(): array
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->id = 41;
|
||||||
|
$service->label = 'Mandatory And Auto Book Board';
|
||||||
|
$service->subType = Constants::TOKEN_BOARD;
|
||||||
|
$service->mandatory = true;
|
||||||
|
$service->autoBook = true;
|
||||||
|
$service->available = 10;
|
||||||
|
$service->price = 12.0;
|
||||||
|
|
||||||
|
return [41 => $service];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createAutoBookRentalServices(): array
|
||||||
|
{
|
||||||
|
$serviceDateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$serviceDateTo = new \DateTimeImmutable('2030-01-07');
|
||||||
|
|
||||||
|
$skiPass = new Service();
|
||||||
|
$skiPass->id = 20;
|
||||||
|
$skiPass->label = 'Matching Ski Pass';
|
||||||
|
$skiPass->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$skiPass->mandatory = false;
|
||||||
|
$skiPass->autoBook = false;
|
||||||
|
$skiPass->available = 10;
|
||||||
|
$skiPass->price = 59.0;
|
||||||
|
$skiPass->dateFrom = $serviceDateFrom;
|
||||||
|
$skiPass->dateTo = $serviceDateTo;
|
||||||
|
|
||||||
|
$rental = new Service();
|
||||||
|
$rental->id = 50;
|
||||||
|
$rental->label = 'Auto Book Rental';
|
||||||
|
$rental->subType = 'VER';
|
||||||
|
$rental->mandatory = false;
|
||||||
|
$rental->autoBook = true;
|
||||||
|
$rental->available = 10;
|
||||||
|
$rental->price = 39.0;
|
||||||
|
$rental->dateFrom = $serviceDateFrom;
|
||||||
|
$rental->dateTo = $serviceDateTo;
|
||||||
|
|
||||||
|
return [20 => $skiPass, 50 => $rental];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, Service>
|
||||||
|
*/
|
||||||
|
private function createMandatoryAndAutoBookRentalServices(): array
|
||||||
|
{
|
||||||
|
$serviceDateFrom = new \DateTimeImmutable('2030-01-01');
|
||||||
|
$serviceDateTo = new \DateTimeImmutable('2030-01-07');
|
||||||
|
|
||||||
|
$skiPass = new Service();
|
||||||
|
$skiPass->id = 22;
|
||||||
|
$skiPass->label = 'Matching Ski Pass Mandatory Rental';
|
||||||
|
$skiPass->subType = Constants::TOKEN_SKI_PASS;
|
||||||
|
$skiPass->mandatory = false;
|
||||||
|
$skiPass->autoBook = false;
|
||||||
|
$skiPass->available = 10;
|
||||||
|
$skiPass->price = 59.0;
|
||||||
|
$skiPass->dateFrom = $serviceDateFrom;
|
||||||
|
$skiPass->dateTo = $serviceDateTo;
|
||||||
|
|
||||||
|
$rental = new Service();
|
||||||
|
$rental->id = 51;
|
||||||
|
$rental->label = 'Mandatory And Auto Book Rental';
|
||||||
|
$rental->subType = 'VER';
|
||||||
|
$rental->mandatory = true;
|
||||||
|
$rental->autoBook = true;
|
||||||
|
$rental->available = 10;
|
||||||
|
$rental->price = 39.0;
|
||||||
|
$rental->dateFrom = $serviceDateFrom;
|
||||||
|
$rental->dateTo = $serviceDateTo;
|
||||||
|
|
||||||
|
return [22 => $skiPass, 51 => $rental];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user