wip: conditional mandatory body dimensions

This commit is contained in:
Björn Fromme
2026-03-16 11:59:09 +01:00
parent 0f7d95d31b
commit f36c761c28
6 changed files with 207 additions and 10 deletions
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace App\Form\Service\Condition;
use App\BusProNet\Model\Service;
use App\Form\Model\BookingDtoInterface;
use App\Form\Service\Contract\FieldConditionInterface;
/**
* Condition that evaluates whether rental services are selected for a participant.
*
* This condition checks if a participant has selected any rental services from the
* available travel services. When rental services are selected, body dimension
* fields (height, weight, shoeSize) should become mandatory for equipment sizing.
*
* The condition examines the participant's rentals array to determine if any
* services with rental subtypes have been selected, triggering mandatory
* body dimension requirements.
*/
class RentalSelectionCondition implements FieldConditionInterface
{
/**
* Evaluates whether the participant has selected any rental services.
*
* Checks if the participant's rentals array contains any Service objects,
* which would indicate rental services have been selected and body
* dimensions should be required for proper equipment sizing.
*
* @param BookingDtoInterface $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 services are selected, false otherwise
*/
public function evaluate(BookingDtoInterface $bookingDto, int $participantIndex, array $formData): bool
{
// First check submitted form data for rental selections
if (isset($formData['participants'][$participantIndex]['rentals'])) {
$selectedRentals = $formData['participants'][$participantIndex]['rentals'];
if (true === is_array($selectedRentals) && false === empty($selectedRentals)) {
return true;
}
}
// Then check participant DTO data for existing rental selections
$participant = $bookingDto->getParticipant($participantIndex);
if (null !== $participant) {
$rentals = $participant->rentals;
if (false === empty($rentals)) {
// Check if any rental services are actually selected
foreach ($rentals as $rental) {
if ($rental instanceof Service) {
return true;
}
}
}
}
return false;
}
/**
* Returns field names that trigger re-evaluation of this condition.
*
* This condition depends on the rentals field, so any changes to rental
* selections should trigger re-evaluation of body dimension field states.
*
* @return string[] Array containing the field names that affect this condition
*/
public function getDependentFields(): array
{
return ['rentals'];
}
/**
* Returns a human-readable description of this condition.
*
* Provides a clear description of the condition logic for debugging,
* logging, and developer documentation purposes.
*
* @return string A brief description of the condition logic
*/
public function getDescription(): string
{
return 'Body dimensions required when rental services are selected';
}
}
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Form\Service;
use App\Form\Service\Abstract\AbstractFieldStateProvider;
use App\Form\Service\Condition\RentalSelectionCondition;
/**
* Field state provider for the booking create workflow.
@@ -44,6 +45,21 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
*/
protected function registerFieldStateConditions(): void
{
$rentalCondition = new RentalSelectionCondition();
// Make body dimension fields required when rental services are selected
$this->fieldStateConditions['height'] = [
'required' => $rentalCondition,
];
$this->fieldStateConditions['weight'] = [
'required' => $rentalCondition,
];
$this->fieldStateConditions['shoeSize'] = [
'required' => $rentalCondition,
];
// Example field state conditions would be registered here
// For demonstration purposes, here are some example patterns: