feat: filter assignments by hotel in favor of destination

This commit is contained in:
Björn Fromme
2024-02-28 13:10:52 +01:00
parent e0522bdf53
commit a668dcb326
7 changed files with 41 additions and 34 deletions
@@ -33,7 +33,7 @@ class AssignmentFilterController extends AbstractController
'min_date' => $filterOptions['minDate'], 'min_date' => $filterOptions['minDate'],
'max_date' => $filterOptions['maxDate'], 'max_date' => $filterOptions['maxDate'],
'job_profiles' => $filterOptions['jobProfiles'], 'job_profiles' => $filterOptions['jobProfiles'],
'destinations' => $filterOptions['destinations'], 'hotels' => $filterOptions['hotels'],
]; ];
$form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions); $form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions);
@@ -41,7 +41,7 @@ class AssignmentFilterController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->filterHandler->handleRequest($form); $this->filterHandler->handleRequest($form);
$returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index'); $returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index');
return new HxRedirectResponse($returnUrl); return new HxRedirectResponse($returnUrl);
} }
@@ -56,7 +56,7 @@ class AssignmentFilterController extends AbstractController
public function reset(Request $request): Response public function reset(Request $request): Response
{ {
$this->filterHandler->resetFilterSettings(); $this->filterHandler->resetFilterSettings();
$returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index'); $returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index');
return $this->redirect($returnUrl); return $this->redirect($returnUrl);
} }
+9 -9
View File
@@ -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 $builder
->add('destination', EntityType::class, [ ->add('hotel', ChoiceType::class, [
'label' => 'Destination', 'label' => 'Haus',
'class' => Destination::class,
'required' => false, 'required' => false,
'choice_label' => function (Destination $destination) { 'choices' => $choices,
return $destination->getProduct();
},
'choices' => $options['destinations'],
]) ])
; ;
} }
@@ -89,7 +89,7 @@ class AssignmentFilterType extends AbstractType
'min_date' => null, 'min_date' => null,
'max_date' => null, 'max_date' => null,
'job_profiles' => [], 'job_profiles' => [],
'destinations' => [], 'hotels' => [],
]) ])
->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null']) ->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null'])
->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null']) ->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null'])
+5 -5
View File
@@ -15,7 +15,7 @@ class AssignmentFilterDto extends AbstractFilterDto
protected ?\DateTimeImmutable $dateFrom = null; protected ?\DateTimeImmutable $dateFrom = null;
protected ?\DateTimeImmutable $dateTo = null; protected ?\DateTimeImmutable $dateTo = null;
protected ?JobProfile $jobProfile = null; protected ?JobProfile $jobProfile = null;
protected ?Destination $destination = null; protected ?string $hotel = null;
protected ?int $duration = null; protected ?int $duration = null;
protected ?string $status = null; protected ?string $status = null;
@@ -55,14 +55,14 @@ class AssignmentFilterDto extends AbstractFilterDto
return $this; 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; return $this;
} }
+7 -7
View File
@@ -106,10 +106,10 @@ class AssignmentRepository extends ServiceEntityRepository
; ;
} }
if (null !== $destination = $filterDto->getDestination()) { if (null !== $hotelCode = $filterDto->getHotel()) {
$qb $qb
->andWhere($qb->expr()->eq('assignment.destination', ':destination')) ->andWhere($qb->expr()->eq('destination.hotelCode', ':hotelCode'))
->setParameter('destination', $destination) ->setParameter('hotelCode', $hotelCode)
; ;
} }
@@ -186,18 +186,18 @@ class AssignmentRepository extends ServiceEntityRepository
return $assignment->getJobProfile(); return $assignment->getJobProfile();
}, $result); }, $result);
// Destinations // Hotels
$qb = $this->createQueryBuilder('assignment'); $qb = $this->createQueryBuilder('assignment');
$result = $qb $result = $qb
->select('assignment', 'destination') ->select('assignment', 'destination')
->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.destination', 'destination')
->where($qb->expr()->isNull('assignment.deletedAt')) ->where($qb->expr()->isNull('assignment.deletedAt'))
->orderBy('destination.product', 'ASC') ->groupBy('destination.hotelBusProId')
->groupBy('destination.id') ->orderBy('destination.hotel', 'ASC')
->getQuery() ->getQuery()
->getResult() ->getResult()
; ;
$options['destinations'] = array_map(function (Assignment $assignment) { $options['hotels'] = array_map(function (Assignment $assignment) {
return $assignment->getDestination(); return $assignment->getDestination();
}, $result); }, $result);
+13
View File
@@ -71,4 +71,17 @@ class DestinationRepository extends ServiceEntityRepository
return $data; 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()
;
}
} }
@@ -2,7 +2,6 @@
namespace App\Service\Common; namespace App\Service\Common;
use App\Entity\Destination;
use App\Entity\JobProfile; use App\Entity\JobProfile;
use App\Model\AssignmentFilterDto; use App\Model\AssignmentFilterDto;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@@ -68,13 +67,8 @@ class AssignmentFilterHandler
; ;
$filterDto->setJobProfile($jobProfile); $filterDto->setJobProfile($jobProfile);
} }
if (isset($data['destination']) && 0 < (int) $data['destination']) { if (isset($data['hotel'])) {
$destination = $this $filterDto->setHotel($data['hotel']);
->entityManager
->getRepository(Destination::class)
->find($data['destination'])
;
$filterDto->setDestination($destination);
} }
if (isset($data['duration']) && 0 < (int) $data['duration']) { if (isset($data['duration']) && 0 < (int) $data['duration']) {
$filterDto->setDuration($data['duration']); $filterDto->setDuration($data['duration']);
@@ -92,7 +86,7 @@ class AssignmentFilterHandler
'date_from' => $filterDto->getDateFrom(), 'date_from' => $filterDto->getDateFrom(),
'date_to' => $filterDto->getDateTo(), 'date_to' => $filterDto->getDateTo(),
'job_profile' => $filterDto->getJobProfile()?->getId(), 'job_profile' => $filterDto->getJobProfile()?->getId(),
'destination' => $filterDto->getDestination()?->getId(), 'hotel' => $filterDto->getHotel(),
'duration' => $filterDto->getDuration(), 'duration' => $filterDto->getDuration(),
'status' => $filterDto->getStatus(), 'status' => $filterDto->getStatus(),
]); ]);
@@ -9,7 +9,7 @@
{{ form_row(filterForm.dateFrom) }} {{ form_row(filterForm.dateFrom) }}
{{ form_row(filterForm.dateTo) }} {{ form_row(filterForm.dateTo) }}
{{ form_row(filterForm.jobProfile) }} {{ form_row(filterForm.jobProfile) }}
{{ form_row(filterForm.destination) }} {{ form_row(filterForm.hotel) }}
{{ form_row(filterForm.duration) }} {{ form_row(filterForm.duration) }}
</div> </div>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">