feat: order and format the pickup fields
This commit is contained in:
1 parent
8da9af46f5
commit
392e67448e
9 files changed
+746
-21
No files matched your search
@@ -7,6 +7,7 @@ use App\Entity\Destination;
|
||||
use App\Entity\Fee;
|
||||
use App\Entity\JobProfile;
|
||||
use App\Entity\User;
|
||||
use App\Service\Common\PickupOptions;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
@@ -130,6 +131,11 @@ class AssignmentType extends AbstractType
|
||||
'label' => 'Busbegleitung ab',
|
||||
'required' => false,
|
||||
'placeholder' => 'Keine Busbegleitung',
|
||||
'expanded' => true,
|
||||
'block_prefix' => 'pickup_choice',
|
||||
// there is nothing to offer until a destination is picked, and an empty
|
||||
// select looks like a destination without boarding points
|
||||
'attr' => ['data-empty-text' => 'Bitte erst eine Destination wählen …'],
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
@@ -234,15 +240,16 @@ class AssignmentType extends AbstractType
|
||||
|
||||
private function addPickupField(Destination $destination, FormInterface $form): void
|
||||
{
|
||||
$choices = [];
|
||||
$options = PickupOptions::inDepartureOrder($destination);
|
||||
$labels = array_column($options, 'label', 'busProId');
|
||||
$attributes = [];
|
||||
|
||||
foreach ($destination->getPickups() as $pickup) {
|
||||
if ($pickup['time']) {
|
||||
$label = sprintf('%s, %s Uhr', trim($pickup['city']), trim($pickup['time']));
|
||||
} else {
|
||||
$label = trim($pickup['city']);
|
||||
}
|
||||
$choices[$label] = $pickup['busProId'];
|
||||
foreach ($options as $option) {
|
||||
// read back by the pickup_choice_widget block in templates/forms.html.twig
|
||||
$attributes[$option['busProId']] = [
|
||||
'data-departure' => $option['departure'] ?? '',
|
||||
'data-street' => $option['street'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
// Remove placeholder field first
|
||||
@@ -252,7 +259,14 @@ class AssignmentType extends AbstractType
|
||||
'label' => 'Busbegleitung ab',
|
||||
'required' => false,
|
||||
'placeholder' => 'Keine Busbegleitung',
|
||||
'choices' => $choices,
|
||||
'choices' => array_column($options, 'busProId'),
|
||||
'choice_label' => static fn (int $busProId): string => $labels[$busProId],
|
||||
'choice_attr' => static fn (int $busProId): array => $attributes[$busProId],
|
||||
// a radio list rather than a dropdown: the departure time and the street need
|
||||
// their own place in the row, which a single option label cannot give them
|
||||
'expanded' => true,
|
||||
'block_prefix' => 'pickup_choice',
|
||||
'attr' => ['data-empty-text' => 'Für diese Destination sind keine Zustiege hinterlegt.'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Service\Common\PickupOptions;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -44,14 +45,14 @@ class TeamerApplicationType extends AbstractType
|
||||
$teamer = $application->getTeamer();
|
||||
|
||||
if (0 === (int) $assignment->getPickup()) {
|
||||
$pickupChoices = [];
|
||||
foreach ($pickups as $pickup) {
|
||||
$pickupChoices[$pickup['city']] = $pickup['busProId'];
|
||||
}
|
||||
ksort($pickupChoices);
|
||||
// keyed by busProId, not by the town: two boarding points share a town
|
||||
// on six destinations, and keying on the label dropped the second one
|
||||
$options = PickupOptions::byTown($assignment->getDestination());
|
||||
$labels = array_column($options, 'label', 'busProId');
|
||||
$form->add('pickup', ChoiceType::class, [
|
||||
'label' => 'Zustieg in',
|
||||
'choices' => $pickupChoices,
|
||||
'choices' => array_column($options, 'busProId'),
|
||||
'choice_label' => static fn (int $busProId): string => $labels[$busProId],
|
||||
]);
|
||||
} elseif (false === in_array($assignment->getPickup(), $teamer->getPickups())) {
|
||||
$form->add('confirmPickup', CheckboxType::class, [
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Disposition;
|
||||
use App\Service\Common\PickupOptions;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -24,14 +25,14 @@ class TeamerDispositionType extends AbstractType
|
||||
|
||||
// Add pickup select field only to assignments that are not including bus chaperon
|
||||
if (0 === (int) $assignment->getPickup()) {
|
||||
$pickupChoices = [];
|
||||
foreach ($assignment->getDestination()->getPickups() as $pickup) {
|
||||
$pickupChoices[$pickup['city']] = $pickup['busProId'];
|
||||
}
|
||||
ksort($pickupChoices);
|
||||
// keyed by busProId, not by the town: two boarding points share a town
|
||||
// on six destinations, and keying on the label dropped the second one
|
||||
$options = PickupOptions::byTown($assignment->getDestination());
|
||||
$labels = array_column($options, 'label', 'busProId');
|
||||
$event->getForm()->add('pickup', ChoiceType::class, [
|
||||
'label' => 'Zustieg in',
|
||||
'choices' => $pickupChoices,
|
||||
'choices' => array_column($options, 'busProId'),
|
||||
'choice_label' => static fn (int $busProId): string => $labels[$busProId],
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user