feat: add filtering of applications

This commit is contained in:
Björn Fromme
2025-02-10 17:08:42 +01:00
parent 2c189de0c7
commit 3e2c5976aa
8 changed files with 514 additions and 7 deletions
+130
View File
@@ -0,0 +1,130 @@
<?php
namespace App\Form;
use App\Entity\Assignment;
use App\Entity\JobProfile;
use App\Model\ApplicationFilterDto;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ApplicationFilterType extends AbstractType
{
private array $hotelChoices = [];
public function __construct(private readonly Security $security, private readonly array $destinations)
{
$destinations = $this->destinations;
sort($destinations);
foreach ($destinations as $item) {
$this->hotelChoices[$item] = $item;
}
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('dateFrom', DatepickerType::class, [
'label' => 'Zeitraum von',
'required' => false,
'min_date' => $options['min_date'],
'max_date' => $options['max_date'],
'attr' => [
'placeholder' => 'nicht filtern',
],
])
->add('dateTo', DatepickerType::class, [
'label' => 'Zeitraum bis',
'required' => false,
'min_date' => $options['min_date'],
'max_date' => $options['max_date'],
'attr' => [
'placeholder' => 'nicht filtern',
],
])
->add('duration', ChoiceType::class, [
'label' => 'Einsatzdauer',
'required' => false,
'placeholder' => 'nicht filtern',
'choices' => [
'Wochenende (2-4 Tage)' => ApplicationFilterDto::DURATION_WEEKEND,
'Midweek (5-6 Tage)' => ApplicationFilterDto::DURATION_MID_WEEK,
'Ganze Woche (7 Tage)' => ApplicationFilterDto::DURATION_FULL_WEEK,
'Mehr als einen Woche' => ApplicationFilterDto::DURATION_MORE,
],
])
->add('includePast', CheckboxType::class, [
'label' => 'vergangene Einsätze anzeigen',
'required' => false,
])
->add('apply', SubmitType::class, [
'label' => 'filtern',
])
->add('reset', SubmitType::class, [
'label' => 'reset',
])
;
if ($this->security->isGranted('ROLE_ADMINISTRATIVE')) {
$builder
->add('id', IntegerType::class, [
'label' => 'ID',
'required' => false,
])
->add('status', MultiselectType::class, [
'label' => 'Status',
'required' => false,
'empty_label' => 'nicht filtern',
'choices' => [
'voll besetzt' => Assignment::STATUS_STAFFED,
'teilweise besetzt' => Assignment::STATUS_PARTLY_STAFFED,
'unbesetzt' => Assignment::STATUS_UNSTAFFED,
'mit Bewerbungen' => Assignment::STATUS_STAFFING,
],
])
;
}
if (0 < count($options['job_profiles'])) {
$builder
->add('jobProfiles', MultiselectEntityType::class, [
'label' => 'Job-Profil',
'class' => JobProfile::class,
'required' => false,
'empty_label' => 'nicht filtern',
'choice_label' => 'name',
'choices' => $options['job_profiles'],
])
;
}
$builder
->add('hotels', MultiselectType::class, [
'label' => 'Haus/Destination',
'required' => false,
'empty_label' => 'nicht filtern',
'choices' => $this->hotelChoices,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
'data_class' => ApplicationFilterDto::class,
'min_date' => null,
'max_date' => null,
'job_profiles' => [],
])
->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null'])
->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null'])
;
}
}