130 lines
4.6 KiB
PHP
130 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Model;
|
|
|
|
use App\BusProNet\Model\PersonalData;
|
|
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;
|
|
public ?int $addressId = null;
|
|
public ?int $personId = null;
|
|
public ?string $status = null;
|
|
public bool $mutable = false;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
|
|
public ?string $firstName = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
|
|
public ?string $lastName = null;
|
|
public ?string $title = null;
|
|
public ?string $gender = null;
|
|
public ?string $nationality = null;
|
|
|
|
public ?string $height = null;
|
|
public ?string $shoeSize = null;
|
|
public ?string $weight = null;
|
|
|
|
#[Assert\NotNull(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
|
|
public ?\DateTimeImmutable $dateOfBirth = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
|
|
#[Assert\Email(message: 'Bitte eine gültige E-Mail Adresse angeben', mode: 'strict', groups: ['booking_edit', 'booking_create_step_2'])]
|
|
public ?string $email = null;
|
|
|
|
public ?string $mobile = null;
|
|
|
|
#[Assert\NotNull(message: 'Bitte ein Zimmer auswählen', groups: ['booking_create_step_2'])]
|
|
public ?int $assignedRoomId = null;
|
|
|
|
public ?string $remarksRoom = null;
|
|
|
|
public array $courses = [];
|
|
public array $additionalServices = [];
|
|
public ?Service $skiPass = null;
|
|
public array $board = [];
|
|
public array $rentals = [];
|
|
public ?Service $transportationServiceTo = null;
|
|
public ?Service $transportationServiceFro = null;
|
|
public ?Pickup $pickup = null;
|
|
|
|
public static function fromPersonalData(PersonalData $personalData): static
|
|
{
|
|
$instance = new static();
|
|
|
|
$instance->status = $personalData->status;
|
|
$instance->addressId = $personalData->addressId;
|
|
$instance->personId = $personalData->personId;
|
|
$instance->mutable = $personalData->mutable;
|
|
$instance->firstName = $personalData->firstName;
|
|
$instance->lastName = $personalData->name;
|
|
$instance->gender = $personalData->gender;
|
|
$instance->nationality = $personalData->nationality;
|
|
$instance->email = $personalData->communication?->email;
|
|
$instance->mobile = $personalData->communication?->mobile;
|
|
$instance->dateOfBirth = $personalData->dateOfBirth;
|
|
$instance->height = $personalData->height;
|
|
$instance->weight = $personalData->weight;
|
|
$instance->shoeSize = $personalData->shoeSize;
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public function isCanceled(): bool
|
|
{
|
|
return 'S' === $this->status;
|
|
}
|
|
|
|
public function isOption(): bool
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|