wip: booking process

This commit is contained in:
Björn Fromme
2025-07-14 17:15:15 +02:00
parent a55e30e12d
commit bef18971c3
45 changed files with 688 additions and 270 deletions
+10 -9
View File
@@ -2,8 +2,9 @@
namespace App\Form;
use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\Form\Model\BookingData;
use App\Form\Model\BookingEditDto;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -16,7 +17,7 @@ final class BookingType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/** @var BookingData $data */
/** @var BookingEditDto $data */
$data = $event->getData();
$form = $event->getForm();
@@ -24,11 +25,11 @@ final class BookingType extends AbstractType
$form->add('participants', CollectionType::class, [
'entry_type' => ParticipantType::class,
'entry_options' => [
'selectable_courses' => $this->mergeSelectableServices($data, Service::TOKEN_COURSES),
'selectable_ski_passes' => $this->mergeSelectableServices($data, Service::TOKEN_SKI_PASS),
'selectable_services' => $this->mergeSelectableServices($data, Service::TOKEN_ADDITIONAL),
'selectable_board' => $this->mergeSelectableServices($data, Service::TOKEN_BOARD),
'selectable_rentals' => $this->mergeSelectableServices($data, Service::TOKEN_RENTALS),
'selectable_courses' => $this->mergeSelectableServices($data, Constants::TOKEN_COURSES),
'selectable_ski_passes' => $this->mergeSelectableServices($data, Constants::TOKEN_SKI_PASS),
'selectable_services' => $this->mergeSelectableServices($data, Constants::TOKEN_ADDITIONAL),
'selectable_board' => $this->mergeSelectableServices($data, Constants::TOKEN_BOARD),
'selectable_rentals' => $this->mergeSelectableServices($data, Constants::TOKEN_RENTALS),
'selectable_transportation_services_to' => $travelData
->getTransportationServicesByDirection('HIN', false),
'selectable_transportation_services_fro' => $travelData
@@ -46,7 +47,7 @@ final class BookingType extends AbstractType
});
}
private function mergeSelectableServices(BookingData $data, mixed $subType): array
private function mergeSelectableServices(BookingEditDto $data, mixed $subType): array
{
// combine selectable services from travel data with additional services
// from booking data
@@ -67,7 +68,7 @@ final class BookingType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => BookingData::class,
'data_class' => BookingEditDto::class,
'anti_xss' => true,
]);
}
@@ -2,13 +2,13 @@
namespace App\Form\Model;
use App\BusProNet\Constants;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\PersonalData;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use Symfony\Component\Validator\Constraints as Assert;
class BookingData
class BookingEditDto
{
public ?Booking $booking = null;
public ?Travel $travel = null;
@@ -25,19 +25,19 @@ class BookingData
foreach ($booking->participants as $index => $participant) {
/** @var PersonalData $participant */
$participantData = ParticipantData::fromPersonalData($participant);
$participantData = ParticipantDto::fromPersonalData($participant);
$participantData->index = $index;
$participantData->courses = $booking
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_COURSES);
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_COURSES);
$participantData->skiPass = $booking
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_SKI_PASS);
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_SKI_PASS);
$participantData->additionalServices = $booking
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_ADDITIONAL);
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_ADDITIONAL);
$participantData->board = $booking
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_BOARD);
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_BOARD);
$participantData->rentals = $booking
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_RENTALS);
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_RENTALS);
// Different keys for direction used in booking data (H <=> HIN, R <=> RUECK)!
$participantData->transportationServiceTo = $booking
->getTransportationServiceForParticipantAndDirection($index, 'H');
@@ -9,7 +9,7 @@ use App\Validator\Constraints as AppAssert;
use Symfony\Component\Validator\Constraints as Assert;
#[AppAssert\Participant]
class ParticipantData
class ParticipantDto
{
public ?int $index = null;
public ?int $addressId = null;
@@ -4,7 +4,7 @@ namespace App\Form\Model;
use Symfony\Component\Validator\Constraints as Assert;
class RegistrationData
class RegistrationDto
{
#[Assert\NotBlank(message: 'Bitte angeben')]
public ?string $firstName = null;
+10 -9
View File
@@ -2,10 +2,11 @@
namespace App\Form;
use App\BusProNet\Constants;
use App\BusProNet\Form\CountryType;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use App\Form\Model\ParticipantData;
use App\Form\Model\ParticipantDto;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -21,7 +22,7 @@ class ParticipantType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
/** @var ParticipantData $participantData */
/** @var ParticipantDto $participantData */
$participantData = $event->getData();
$participantIndex = $participantData->index;
@@ -166,12 +167,12 @@ class ParticipantType extends AbstractType
}
// disable selection of services only available in booking data
if (Service::SOURCE_BOOKING === $service->source) {
if (Constants::SOURCE_BOOKING === $service->source) {
$attributes['class'] = 'text-pink';
}
// disable selection of services that are unavailable according to their status
if (Service::STATUS_BLOCKED === $service->status) {
if (Constants::STATUS_BLOCKED === $service->status) {
$attributes['checked'] = false;
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar';
@@ -191,8 +192,8 @@ class ParticipantType extends AbstractType
// remove choices only available in booking data and
// which are not mapped to the current participant
if (
Service::SOURCE_TRAVEL === $service->source
|| Service::CATEGORY_ADDITIONAL !== $service->category
Constants::SOURCE_TRAVEL === $service->source
|| Constants::CATEGORY_ADDITIONAL !== $service->category
) {
return true;
}
@@ -249,7 +250,7 @@ class ParticipantType extends AbstractType
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden';
}
if (Service::STATUS_BLOCKED === $service->status) {
if (Constants::STATUS_BLOCKED === $service->status) {
$attributes['checked'] = false;
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar';
@@ -341,7 +342,7 @@ class ParticipantType extends AbstractType
$participantIndex = $form->getData()->index;
return true === $service->mandatory
|| (Service::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
|| (Constants::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
});
if (0 < count($mandatoryServices)) {
@@ -364,7 +365,7 @@ class ParticipantType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => ParticipantData::class,
'data_class' => ParticipantDto::class,
'selectable_courses' => [],
'selectable_ski_passes' => [],
'selectable_services' => [],
+2 -2
View File
@@ -2,7 +2,7 @@
namespace App\Form;
use App\Form\Model\RegistrationData;
use App\Form\Model\RegistrationDto;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
@@ -39,7 +39,7 @@ class RegistrationType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => RegistrationData::class,
'data_class' => RegistrationDto::class,
'anti_xss' => true,
]);
}