fix: ensure rental insurance is selectable when insurance is available
addresses #869bp9ev5
This commit is contained in:
1 parent
ce828a6ef5
commit
d7fd273475
3 files changed
+79
-4
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates whether rental insurance services are available for the travel.
|
||||
*
|
||||
* This condition checks if the travel has any LVS (rental insurance) services available.
|
||||
* The rental insurance checkbox should only be shown when both rental equipment is selected
|
||||
* AND rental insurance services actually exist for the travel period.
|
||||
*/
|
||||
class RentalInsuranceAvailableCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates whether rental insurance services are available for the travel.
|
||||
*
|
||||
* @param BookingDto $bookingDto The current booking data (create or edit)
|
||||
* @param int $participantIndex The index of the participant being evaluated
|
||||
* @param array<string, mixed> $formData Current form data for condition evaluation
|
||||
*
|
||||
* @return bool True if rental insurance services are available, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
if (null === $bookingDto->travel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$services = $bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_RENTAL_INSURANCE,
|
||||
true
|
||||
);
|
||||
|
||||
return false === empty($services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that trigger re-evaluation of this condition.
|
||||
*
|
||||
* This condition depends on travel data which doesn't change during form interaction,
|
||||
* so no fields trigger re-evaluation.
|
||||
*
|
||||
* @return string[] Empty array as this condition is static for a given travel
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of this condition.
|
||||
*
|
||||
* @return string A brief description of the condition logic
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Rental insurance checkbox shown only when LVS services exist for travel';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user