wip: conditional mandatory body dimensions

This commit is contained in:
Björn Fromme
2025-07-25 21:47:00 +02:00
parent 9c5597eb23
commit b992e4a5ea
6 changed files with 207 additions and 10 deletions
+43
View File
@@ -7,8 +7,10 @@ use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use App\Validator\Constraints as AppAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[AppAssert\Participant(groups: ['booking_edit'])]
#[Assert\Callback('validateBodyDimensionsForRentals', groups: ['booking_create_step_2', 'booking_edit'])]
class ParticipantDto
{
public ?int $index = null;
@@ -25,6 +27,7 @@ class ParticipantDto
public ?string $title = null;
public ?string $gender = null;
public ?string $nationality = null;
public ?string $height = null;
public ?string $shoeSize = null;
public ?string $weight = null;
@@ -81,4 +84,44 @@ class ParticipantDto
{
return 'O' === $this->status;
}
/**
* Validates that body dimension fields are provided when rental services are selected.
*
* This callback validator ensures that height, weight, and shoe size are mandatory
* when the participant has selected any rental services. This is required for
* proper equipment sizing and rental fulfillment.
*
* @param ExecutionContextInterface $context The validation context
*/
public function validateBodyDimensionsForRentals(ExecutionContextInterface $context): void
{
$rentals = $this->rentals ?? [];
// If no rental services are selected, body dimensions are not required
if (empty($rentals)) {
return;
}
// Validate height field
if (true === empty($this->height)) {
$context->buildViolation('Deine Körpergröße ist erforderlich wenn Leihmaterial ausgewählt wurde')
->atPath('height')
->addViolation();
}
// Validate weight field
if (true === empty($this->weight)) {
$context->buildViolation('Dein Gewicht ist erforderlich wenn Leihmaterial ausgewählt wurde')
->atPath('weight')
->addViolation();
}
// Validate shoe size field
if (true === empty($this->shoeSize)) {
$context->buildViolation('Deine Schuhgröße ist erforderlich wenn Leihmaterial ausgewählt wurde')
->atPath('shoeSize')
->addViolation();
}
}
}