From f155b5ae52d31f5fcb783c621b33a4d188cbb601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 28 Oct 2024 09:09:17 +0100 Subject: [PATCH] feat: filter destinations by common name --- config/services.yaml | 25 +++++++++++++++- .../Common/AssignmentFilterController.php | 1 - src/Form/AssignmentFilterType.php | 29 +++++++++---------- src/Repository/AssignmentRepository.php | 22 ++------------ 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 2d634fe..49ffb34 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -7,6 +7,25 @@ parameters: default_email_from: '%env(APP_DEFAULT_EMAIL_FROM)%' default_email_to: '%env(APP_DEFAULT_EMAIL_TO)%' + destinations: + - Schwendi + - Waldschlössli + - Spinabad + - Schweizerhaus + - Weißfluh + - Victoria + - Klein Tirol + - Jürg-Jenatsch + - Lederer + - Steinachhof + - Val Thorens + - Les Deux Alpes + - Josefsheim + - Ranalt + - Jolimont + - Christiler + - Heuberghaus + services: _defaults: autowire: true @@ -141,4 +160,8 @@ services: arguments: $defaults: from: '%default_email_from%' - to: '%default_email_to%' \ No newline at end of file + to: '%default_email_to%' + + App\Form\AssignmentFilterType: + arguments: + $destinations: '%destinations%' \ No newline at end of file diff --git a/src/Controller/Common/AssignmentFilterController.php b/src/Controller/Common/AssignmentFilterController.php index c39c24b..cbb13cb 100644 --- a/src/Controller/Common/AssignmentFilterController.php +++ b/src/Controller/Common/AssignmentFilterController.php @@ -33,7 +33,6 @@ class AssignmentFilterController extends AbstractController 'min_date' => $filterOptions['minDate'], 'max_date' => $filterOptions['maxDate'], 'job_profiles' => $filterOptions['jobProfiles'], - 'hotels' => $filterOptions['hotels'], ]; $form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions); diff --git a/src/Form/AssignmentFilterType.php b/src/Form/AssignmentFilterType.php index 501fd72..0b20917 100644 --- a/src/Form/AssignmentFilterType.php +++ b/src/Form/AssignmentFilterType.php @@ -18,7 +18,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class AssignmentFilterType extends AbstractType { - public function __construct(private readonly Security $security) + public function __construct(private readonly Security $security, private readonly array $destinations) { } @@ -90,20 +90,20 @@ class AssignmentFilterType extends AbstractType ]) ; } - if (0 < count($options['hotels'])) { - $choices = []; - foreach ($options['hotels'] as $item) { - $choices[$item->getHotel()] = $item->getHotelCode(); - } - $builder - ->add('hotels', MultiselectType::class, [ - 'label' => 'Haus', - 'required' => false, - 'empty_label' => 'nicht filtern', - 'choices' => $choices, - ]) - ; + $hotelChoices = []; + $destinations = $this->destinations; + sort($destinations); + foreach ($destinations as $item) { + $hotelChoices[$item] = $item; } + $builder + ->add('hotels', MultiselectType::class, [ + 'label' => 'Haus/Destination', + 'required' => false, + 'empty_label' => 'nicht filtern', + 'choices' => $hotelChoices, + ]) + ; } public function configureOptions(OptionsResolver $resolver): void @@ -114,7 +114,6 @@ class AssignmentFilterType extends AbstractType 'min_date' => null, 'max_date' => null, 'job_profiles' => [], - 'hotels' => [], ]) ->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null']) ->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null']) diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index ee3ea3a..3ca0580 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -4,7 +4,6 @@ namespace App\Repository; use App\Entity\Application; use App\Entity\Assignment; -use App\Entity\Destination; use App\Entity\Teamer; use App\Model\AssignmentFilterDto; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; @@ -119,10 +118,10 @@ class AssignmentRepository extends ServiceEntityRepository ; } - if ($hotelCodes = $filterDto->getHotels()) { + foreach ($filterDto->getHotels() as $hotel) { $qb - ->andWhere($qb->expr()->in('destination.hotelCode', ':hotelCodes')) - ->setParameter('hotelCodes', $hotelCodes) + ->andWhere($qb->expr()->like('destination.product', ':hotel')) + ->setParameter('hotel', '%'.$hotel.'%') ; } @@ -205,21 +204,6 @@ class AssignmentRepository extends ServiceEntityRepository return $assignment->getJobProfile(); }, $result); - // Hotels - $qb = $this->createQueryBuilder('assignment'); - $result = $qb - ->select('assignment', 'destination') - ->innerJoin('assignment.destination', 'destination') - ->where($qb->expr()->isNull('assignment.deletedAt')) - ->groupBy('destination.hotelBusProId') - ->orderBy('destination.hotel', 'ASC') - ->getQuery() - ->getResult() - ; - $options['hotels'] = array_map(function (Assignment $assignment) { - return $assignment->getDestination(); - }, $result); - return $options; }