diff --git a/src/Controller/Common/AssignmentFilterController.php b/src/Controller/Common/AssignmentFilterController.php index 45d3e99..c39c24b 100644 --- a/src/Controller/Common/AssignmentFilterController.php +++ b/src/Controller/Common/AssignmentFilterController.php @@ -33,7 +33,7 @@ class AssignmentFilterController extends AbstractController 'min_date' => $filterOptions['minDate'], 'max_date' => $filterOptions['maxDate'], 'job_profiles' => $filterOptions['jobProfiles'], - 'destinations' => $filterOptions['destinations'], + 'hotels' => $filterOptions['hotels'], ]; $form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions); @@ -41,7 +41,7 @@ class AssignmentFilterController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $this->filterHandler->handleRequest($form); - $returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index'); + $returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index'); return new HxRedirectResponse($returnUrl); } @@ -56,7 +56,7 @@ class AssignmentFilterController extends AbstractController public function reset(Request $request): Response { $this->filterHandler->resetFilterSettings(); - $returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index'); + $returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index'); return $this->redirect($returnUrl); } diff --git a/src/Form/AssignmentFilterType.php b/src/Form/AssignmentFilterType.php index d6631f6..40cee25 100644 --- a/src/Form/AssignmentFilterType.php +++ b/src/Form/AssignmentFilterType.php @@ -66,16 +66,16 @@ class AssignmentFilterType extends AbstractType ]) ; } - if (0 < count($options['destinations'])) { + if (0 < count($options['hotels'])) { + $choices = []; + foreach ($options['hotels'] as $item) { + $choices[$item->getHotel()] = $item->getHotelCode(); + } $builder - ->add('destination', EntityType::class, [ - 'label' => 'Destination', - 'class' => Destination::class, + ->add('hotel', ChoiceType::class, [ + 'label' => 'Haus', 'required' => false, - 'choice_label' => function (Destination $destination) { - return $destination->getProduct(); - }, - 'choices' => $options['destinations'], + 'choices' => $choices, ]) ; } @@ -89,7 +89,7 @@ class AssignmentFilterType extends AbstractType 'min_date' => null, 'max_date' => null, 'job_profiles' => [], - 'destinations' => [], + 'hotels' => [], ]) ->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null']) ->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null']) diff --git a/src/Model/AssignmentFilterDto.php b/src/Model/AssignmentFilterDto.php index 242a0e1..8f2f1bd 100644 --- a/src/Model/AssignmentFilterDto.php +++ b/src/Model/AssignmentFilterDto.php @@ -15,7 +15,7 @@ class AssignmentFilterDto extends AbstractFilterDto protected ?\DateTimeImmutable $dateFrom = null; protected ?\DateTimeImmutable $dateTo = null; protected ?JobProfile $jobProfile = null; - protected ?Destination $destination = null; + protected ?string $hotel = null; protected ?int $duration = null; protected ?string $status = null; @@ -55,14 +55,14 @@ class AssignmentFilterDto extends AbstractFilterDto return $this; } - public function getDestination(): ?Destination + public function getHotel(): ?string { - return $this->destination; + return $this->hotel; } - public function setDestination(?Destination $destination): static + public function setHotel(?string $hotel): static { - $this->destination = $destination; + $this->hotel = $hotel; return $this; } diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index fe29019..62bb7a3 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -106,10 +106,10 @@ class AssignmentRepository extends ServiceEntityRepository ; } - if (null !== $destination = $filterDto->getDestination()) { + if (null !== $hotelCode = $filterDto->getHotel()) { $qb - ->andWhere($qb->expr()->eq('assignment.destination', ':destination')) - ->setParameter('destination', $destination) + ->andWhere($qb->expr()->eq('destination.hotelCode', ':hotelCode')) + ->setParameter('hotelCode', $hotelCode) ; } @@ -186,18 +186,18 @@ class AssignmentRepository extends ServiceEntityRepository return $assignment->getJobProfile(); }, $result); - // Destinations + // Hotels $qb = $this->createQueryBuilder('assignment'); $result = $qb ->select('assignment', 'destination') ->innerJoin('assignment.destination', 'destination') ->where($qb->expr()->isNull('assignment.deletedAt')) - ->orderBy('destination.product', 'ASC') - ->groupBy('destination.id') + ->groupBy('destination.hotelBusProId') + ->orderBy('destination.hotel', 'ASC') ->getQuery() ->getResult() ; - $options['destinations'] = array_map(function (Assignment $assignment) { + $options['hotels'] = array_map(function (Assignment $assignment) { return $assignment->getDestination(); }, $result); diff --git a/src/Repository/DestinationRepository.php b/src/Repository/DestinationRepository.php index 8ac8afb..195f0cd 100644 --- a/src/Repository/DestinationRepository.php +++ b/src/Repository/DestinationRepository.php @@ -71,4 +71,17 @@ class DestinationRepository extends ServiceEntityRepository return $data; } + + public function getHotels(): array + { + $qb = $this->createQueryBuilder('destination'); + + return $qb + ->select('destination.hotel', 'destination.hotelCode', 'destination.hotelBusProId') + ->groupBy('destination.hotelBusProId') + ->orderBy('destination.hotel', 'ASC') + ->getQuery() + ->getArrayResult() + ; + } } diff --git a/src/Service/Common/AssignmentFilterHandler.php b/src/Service/Common/AssignmentFilterHandler.php index c52d35f..8e3940b 100644 --- a/src/Service/Common/AssignmentFilterHandler.php +++ b/src/Service/Common/AssignmentFilterHandler.php @@ -2,7 +2,6 @@ namespace App\Service\Common; -use App\Entity\Destination; use App\Entity\JobProfile; use App\Model\AssignmentFilterDto; use Doctrine\ORM\EntityManagerInterface; @@ -68,13 +67,8 @@ class AssignmentFilterHandler ; $filterDto->setJobProfile($jobProfile); } - if (isset($data['destination']) && 0 < (int) $data['destination']) { - $destination = $this - ->entityManager - ->getRepository(Destination::class) - ->find($data['destination']) - ; - $filterDto->setDestination($destination); + if (isset($data['hotel'])) { + $filterDto->setHotel($data['hotel']); } if (isset($data['duration']) && 0 < (int) $data['duration']) { $filterDto->setDuration($data['duration']); @@ -92,7 +86,7 @@ class AssignmentFilterHandler 'date_from' => $filterDto->getDateFrom(), 'date_to' => $filterDto->getDateTo(), 'job_profile' => $filterDto->getJobProfile()?->getId(), - 'destination' => $filterDto->getDestination()?->getId(), + 'hotel' => $filterDto->getHotel(), 'duration' => $filterDto->getDuration(), 'status' => $filterDto->getStatus(), ]); diff --git a/templates/common/modal_assignment_filter.html.twig b/templates/common/modal_assignment_filter.html.twig index 437d39d..0f9997d 100644 --- a/templates/common/modal_assignment_filter.html.twig +++ b/templates/common/modal_assignment_filter.html.twig @@ -9,7 +9,7 @@ {{ form_row(filterForm.dateFrom) }} {{ form_row(filterForm.dateTo) }} {{ form_row(filterForm.jobProfile) }} - {{ form_row(filterForm.destination) }} + {{ form_row(filterForm.hotel) }} {{ form_row(filterForm.duration) }}