wip: first working version

This commit is contained in:
Björn Fromme committed 2024-11-21 18:38:41 +01:00
1 parent d4c4e69d09
commit bd13ae6537
24 files changed
+590 -319

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ final class BookingType extends AbstractType
->getTransportationServicesByDirection('HIN'),
'selectable_transportation_services_fro' => $options['travel']
->getTransportationServicesByDirection('RUECK'),
'selectable_pickups' => $options['travel']->pickups,
],
'allow_add' => false,
'allow_delete' => false,
+2
View File
@@ -5,8 +5,10 @@ namespace App\Form\Model;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\PersonalData;
use App\BusProNet\Model\Service;
use App\Validator\Constraints as AppAssert;
use Symfony\Component\Validator\Constraints as Assert;
#[AppAssert\Booking]
class BookingData
{
public ?Booking $booking = null;
+16 -3
View File
@@ -3,6 +3,7 @@
namespace App\Form\Model;
use App\BusProNet\Model\PersonalData;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -47,9 +48,10 @@ class ParticipantData
public array $rentals = [];
public ?Service $transportationServiceTo = null;
public ?Service $transportationServiceFro = null;
public ?Pickup $pickup = null;
#[Assert\Callback]
public function assertBodyMeasurements(ExecutionContextInterface $context): void
public function assertBodyMeasurementsValid(ExecutionContextInterface $context): void
{
if (0 === count($this->rentals)) {
return;
@@ -63,20 +65,31 @@ class ParticipantData
}
if (empty($this->shoeSize)) {
$context->buildViolation('Bitte angeben Leihmaterial')
$context->buildViolation('Bitte angeben wegen Leihmaterial')
->atPath('shoeSize')
->addViolation()
;
}
if (empty($this->weight)) {
$context->buildViolation('Bitte angeben Leihmaterial')
$context->buildViolation('Bitte angeben wegen Leihmaterial')
->atPath('weight')
->addViolation()
;
}
}
#[Assert\Callback]
public function assertPickupSelected(ExecutionContextInterface $context): void
{
if (null !== $this->transportationServiceTo && null === $this->pickup) {
$context->buildViolation('Bitte auswählen')
->atPath('pickupTo')
->addViolation()
;
}
}
public static function fromPersonalData(PersonalData $personalData): static
{
$instance = new static();
+42 -3
View File
@@ -3,6 +3,7 @@
namespace App\Form;
use App\BusProNet\Form\CountryType;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use App\Form\Model\ParticipantData;
use Symfony\Component\Form\AbstractType;
@@ -35,6 +36,8 @@ class ParticipantType extends AbstractType
])
->add('gender', ChoiceType::class, [
'label' => 'Geschlecht',
'required' => false,
'placeholder' => 'keine Angabe',
'choices' => [
'männlich' => 'M',
'weiblich' => 'W',
@@ -65,9 +68,9 @@ class ParticipantType extends AbstractType
'required' => false,
])
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
/** @var ParticipantData $participant */
$participant = $event->getData();
$participantIndex = $participant->index;
/** @var ParticipantData $participantData */
$participantData = $event->getData();
$participantIndex = $participantData->index;
$form = $event->getForm();
@@ -139,8 +142,43 @@ class ParticipantType extends AbstractType
'multiple' => false,
'choices' => $options['selectable_transportation_services_fro'],
])
->add('pickup', ChoiceType::class, [
'label' => 'Zustieg (bei Busanreise)',
'multiple' => false,
'expanded' => false,
'choices' => $options['selectable_pickups'],
'choice_value' => 'id',
'choice_label' => function (?Pickup $pickup) {
if (null === $pickup) {
return null;
}
$price = $pickup->price;
if (null === $price || 0.0 === $price) {
return $pickup->city;
}
return sprintf('%s (%s€)',
$pickup->city,
number_format($price, 2, ',', '.')
);
},
])
;
})
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
$data = $event->getData();
$form = $event->getForm();
$transportationId = $data['transportationServiceTo'];
$transportation = $options['travel']->pickups[$transportationId] ?? null;
if (null !== $transportation && 'PKW' === $transportation->subType) {
$form->remove('pickup');
unset($data['pickup']);
}
})
;
}
@@ -155,6 +193,7 @@ class ParticipantType extends AbstractType
'selectable_rentals' => [],
'selectable_transportation_services_to' => [],
'selectable_transportation_services_fro' => [],
'selectable_pickups' => [],
]);
}
}