fix: properly filter by date range, improve filter handlers
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Model\TimelineFilterDto;
|
||||
use App\Service\Assignment\TimelineService;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -10,25 +11,24 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TimelineFilterType extends AbstractType
|
||||
{
|
||||
private array $hotelChoices = [];
|
||||
|
||||
public function __construct(private readonly array $destinations)
|
||||
{
|
||||
$destinations = $this->destinations;
|
||||
sort($destinations);
|
||||
foreach ($destinations as $item) {
|
||||
$this->hotelChoices[$item] = $item;
|
||||
}
|
||||
public function __construct(
|
||||
private readonly TimelineService $timelineService,
|
||||
private readonly array $destinations
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$period = $this->timelineService->getActiveWindow();
|
||||
$periodFrom = $period->first()->toDateTimeImmutable();
|
||||
$periodTo = $period->last()->toDateTimeImmutable();
|
||||
|
||||
$builder
|
||||
->add('dateFrom', DatepickerType::class, [
|
||||
'label' => 'Zeitraum von',
|
||||
'required' => false,
|
||||
'min_date' => $options['min_date'],
|
||||
'max_date' => $options['max_date'],
|
||||
'min_date' => $periodFrom,
|
||||
'max_date' => $periodTo,
|
||||
'attr' => [
|
||||
'placeholder' => 'nicht filtern',
|
||||
],
|
||||
@@ -36,8 +36,8 @@ class TimelineFilterType extends AbstractType
|
||||
->add('dateTo', DatepickerType::class, [
|
||||
'label' => 'Zeitraum bis',
|
||||
'required' => false,
|
||||
'min_date' => $options['min_date'],
|
||||
'max_date' => $options['max_date'],
|
||||
'min_date' => $periodFrom,
|
||||
'max_date' => $periodTo,
|
||||
'attr' => [
|
||||
'placeholder' => 'nicht filtern',
|
||||
],
|
||||
@@ -50,26 +50,27 @@ class TimelineFilterType extends AbstractType
|
||||
])
|
||||
;
|
||||
|
||||
$destinations = $this->destinations;
|
||||
$hotelChoices = [];
|
||||
sort($destinations);
|
||||
foreach ($destinations as $item) {
|
||||
$hotelChoices[$item] = $item;
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('hotels', MultiselectType::class, [
|
||||
'label' => 'Haus/Destination',
|
||||
'required' => false,
|
||||
'empty_label' => 'nicht filtern',
|
||||
'choices' => $this->hotelChoices,
|
||||
'choices' => $hotelChoices,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => TimelineFilterDto::class,
|
||||
'min_date' => null,
|
||||
'max_date' => null,
|
||||
])
|
||||
->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null'])
|
||||
->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null'])
|
||||
;
|
||||
$resolver->setDefaults([
|
||||
'data_class' => TimelineFilterDto::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user