From 44d130414cb3f1628e1a7686cb84660d9aabbc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 2 Dec 2024 14:19:35 +0100 Subject: [PATCH] feat: filter assignments by id --- src/Form/AssignmentFilterType.php | 31 ++++++++++++------- src/Model/AssignmentFilterDto.php | 13 ++++++++ src/Repository/AssignmentRepository.php | 7 +++++ .../Common/AssignmentFilterHandler.php | 4 +++ .../common/modal_assignment_filter.html.twig | 9 ++++-- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/Form/AssignmentFilterType.php b/src/Form/AssignmentFilterType.php index 0b20917..5f30d12 100644 --- a/src/Form/AssignmentFilterType.php +++ b/src/Form/AssignmentFilterType.php @@ -12,6 +12,7 @@ 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; @@ -27,6 +28,7 @@ class AssignmentFilterType extends AbstractType $builder ->add('dateFrom', DatepickerType::class, [ 'label' => 'Zeitraum von', + 'required' => false, 'min_date' => $options['min_date'], 'max_date' => $options['max_date'], 'attr' => [ @@ -35,6 +37,7 @@ class AssignmentFilterType extends AbstractType ]) ->add('dateTo', DatepickerType::class, [ 'label' => 'Zeitraum bis', + 'required' => false, 'min_date' => $options['min_date'], 'max_date' => $options['max_date'], 'attr' => [ @@ -65,17 +68,23 @@ class AssignmentFilterType extends AbstractType ; if ($this->security->isGranted('ROLE_ADMINISTRATIVE')) { - $builder->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, - ], - ]); + $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'])) { diff --git a/src/Model/AssignmentFilterDto.php b/src/Model/AssignmentFilterDto.php index 5d50392..4ca6c91 100644 --- a/src/Model/AssignmentFilterDto.php +++ b/src/Model/AssignmentFilterDto.php @@ -12,6 +12,7 @@ class AssignmentFilterDto extends AbstractFilterDto public const DURATION_FULL_WEEK = 3; public const DURATION_MORE = 4; + protected ?int $id = null; protected ?\DateTimeImmutable $dateFrom = null; protected ?\DateTimeImmutable $dateTo = null; protected array $jobProfiles = []; @@ -20,6 +21,18 @@ class AssignmentFilterDto extends AbstractFilterDto protected array $status = []; protected bool $includePast = false; + public function getId(): ?int + { + return $this->id; + } + + public function setId(?int $id): static + { + $this->id = $id; + + return $this; + } + public function getDateFrom(): ?\DateTimeImmutable { return $this->dateFrom; diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index 7e01eb4..4951af4 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -85,6 +85,13 @@ class AssignmentRepository extends ServiceEntityRepository private function applyFilterSettings(AssignmentFilterDto $filterDto, QueryBuilder $qb): void { + if (null !== $filterDto->getId()) { + $qb + ->andWhere($qb->expr()->eq('assignment.id', ':id')) + ->setParameter('id', $filterDto->getId()) + ; + } + if (false === $filterDto->isIncludePast()) { $qb ->andWhere($qb->expr()->gte('destination.dateFrom', ':now')) diff --git a/src/Service/Common/AssignmentFilterHandler.php b/src/Service/Common/AssignmentFilterHandler.php index 8d58a06..e0d1c19 100644 --- a/src/Service/Common/AssignmentFilterHandler.php +++ b/src/Service/Common/AssignmentFilterHandler.php @@ -18,6 +18,9 @@ class AssignmentFilterHandler extends AbstractFilterHandler $filterDto = new AssignmentFilterDto(); + if (isset($data['id'])) { + $filterDto->setId($data['id']); + } if (isset($data['date_from'])) { $filterDto->setDateFrom($data['date_from']); } @@ -52,6 +55,7 @@ class AssignmentFilterHandler extends AbstractFilterHandler { /** @var AssignmentFilterDto $filterDto */ $this->getSession()->set($this->namespace, [ + 'id' => $filterDto->getId(), 'date_from' => $filterDto->getDateFrom(), 'date_to' => $filterDto->getDateTo(), 'job_profiles' => array_map(function (JobProfile $jobProfile) { diff --git a/templates/common/modal_assignment_filter.html.twig b/templates/common/modal_assignment_filter.html.twig index f1afe0c..a155a01 100644 --- a/templates/common/modal_assignment_filter.html.twig +++ b/templates/common/modal_assignment_filter.html.twig @@ -5,11 +5,16 @@ {% block content %} {{ form_start(filterForm, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
+ {% if filterForm.id is defined %} + {{ form_row(filterForm.id) }} + {% endif %} {% if filterForm.status is defined %} {{ form_row(filterForm.status) }} {% endif %} - {{ form_row(filterForm.dateFrom) }} - {{ form_row(filterForm.dateTo) }} +
+ {{ form_row(filterForm.dateFrom) }} + {{ form_row(filterForm.dateTo) }} +
{{ form_row(filterForm.jobProfiles) }} {{ form_row(filterForm.hotels) }} {{ form_row(filterForm.duration) }}