feat: readonly room selection for single room types
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates whether only a single room type is selected in the booking.
|
||||
*
|
||||
* This condition checks if exactly one room type has been selected with a positive quantity
|
||||
* in the booking's room selections. When only one room type is available, the room assignment
|
||||
* dropdown becomes unnecessary and can be made readonly to improve UX.
|
||||
*/
|
||||
class SingleRoomTypeCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates whether exactly one room type is selected in the booking.
|
||||
*
|
||||
* Counts the number of room types that have been selected with a quantity greater than zero.
|
||||
* Returns true when exactly one room type is selected, false otherwise.
|
||||
*
|
||||
* @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 exactly one room type is selected, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
$selectedRoomCount = 0;
|
||||
|
||||
foreach ($bookingDto->roomSelections as $roomSelection) {
|
||||
if (null !== $roomSelection->quantity && $roomSelection->quantity > 0) {
|
||||
++$selectedRoomCount;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 === $selectedRoomCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that trigger re-evaluation of this condition.
|
||||
*
|
||||
* This condition depends on booking-level room selection data, not participant fields.
|
||||
* Room selections are determined in step 1 and remain static during participant editing,
|
||||
* so no participant-level field dependencies are needed.
|
||||
*
|
||||
* @return string[] Empty array (no participant-level dependencies)
|
||||
*/
|
||||
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 'Field readonly when exactly one room type is selected';
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use App\Form\Service\Condition\FieldValueCondition;
|
||||
use App\Form\Service\Condition\RentalSelectionCondition;
|
||||
use App\Form\Service\Condition\RoomSelectionCondition;
|
||||
use App\Form\Service\Condition\ServiceSubTypeCondition;
|
||||
use App\Form\Service\Condition\SingleRoomTypeCondition;
|
||||
use App\Form\Service\Condition\SkiPassSelectionCondition;
|
||||
use App\Service\ParticipantEligibilityService;
|
||||
|
||||
@@ -204,6 +205,11 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
'required' => new ApplicantCondition(),
|
||||
];
|
||||
|
||||
// Make assignedRoomId readonly when only one room type is selected
|
||||
$this->fieldStateConditions['assignedRoomId'] = [
|
||||
'readonly' => new SingleRoomTypeCondition(),
|
||||
];
|
||||
|
||||
// Example field state conditions would be registered here
|
||||
// For demonstration purposes, here are some example patterns:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user