feat: filter teamers by multiple job profiles

This commit is contained in:
Björn Fromme
2024-07-18 15:09:56 +02:00
parent ebf89d19c3
commit b563bf3059
5 changed files with 19 additions and 16 deletions
+3 -2
View File
@@ -40,11 +40,12 @@ class TeamerFilterType extends AbstractType
'label' => 'Snowboardlehrer:innen-Lizenz', 'label' => 'Snowboardlehrer:innen-Lizenz',
'required' => false, 'required' => false,
]) ])
->add('jobProfile', EntityType::class, [ ->add('jobProfiles', MultiselectEntityType::class, [
'label' => 'Job-Profil', 'label' => 'Job-Profile',
'class' => JobProfile::class, 'class' => JobProfile::class,
'required' => false, 'required' => false,
'choice_label' => 'name', 'choice_label' => 'name',
'empty_label' => 'nicht filtern',
'query_builder' => function (EntityRepository $repository) { 'query_builder' => function (EntityRepository $repository) {
return $repository->createQueryBuilder('job_profile') return $repository->createQueryBuilder('job_profile')
->orderBy('job_profile.name', 'ASC'); ->orderBy('job_profile.name', 'ASC');
+5 -5
View File
@@ -9,7 +9,7 @@ class TeamerFilterDto extends AbstractFilterDto
protected ?string $name = null; protected ?string $name = null;
protected ?\DateTimeImmutable $dateFrom = null; protected ?\DateTimeImmutable $dateFrom = null;
protected ?\DateTimeImmutable $dateTo = null; protected ?\DateTimeImmutable $dateTo = null;
protected ?JobProfile $jobProfile = null; protected array $jobProfiles = [];
protected string $pickupId = ''; protected string $pickupId = '';
protected bool $skiLicense = false; protected bool $skiLicense = false;
protected bool $snowboardLicense = false; protected bool $snowboardLicense = false;
@@ -51,14 +51,14 @@ class TeamerFilterDto extends AbstractFilterDto
return $this; return $this;
} }
public function getJobProfile(): ?JobProfile public function getJobProfiles(): array
{ {
return $this->jobProfile; return $this->jobProfiles;
} }
public function setJobProfile(?JobProfile $jobProfile): static public function setJobProfiles(array $jobProfiles): static
{ {
$this->jobProfile = $jobProfile; $this->jobProfiles = $jobProfiles;
return $this; return $this;
} }
+3 -3
View File
@@ -66,10 +66,10 @@ class TeamerRepository extends ServiceEntityRepository
; ;
} }
if (null !== $filterDto->getJobProfile()) { if (0 < count($filterDto->getJobProfiles())) {
$qb $qb
->andWhere($qb->expr()->eq('job_profile', ':jobProfile')) ->andWhere($qb->expr()->in('job_profile', ':jobProfiles'))
->setParameter('jobProfile', $filterDto->getJobProfile()) ->setParameter('jobProfiles', $filterDto->getJobProfiles())
; ;
} }
+7 -5
View File
@@ -63,13 +63,13 @@ class TeamerFilterHandler
->setNoTrainings($data['no_trainings']) ->setNoTrainings($data['no_trainings'])
; ;
if (0 < (int) $data['job_profile']) { if (0 < count($data['job_profiles'])) {
$jobProfile = $this $jobProfiles = $this
->entityManager ->entityManager
->getRepository(JobProfile::class) ->getRepository(JobProfile::class)
->find($data['job_profile']) ->findBy(['id' => $data['job_profiles']])
; ;
$filterDto->setJobProfile($jobProfile); $filterDto->setJobProfiles($jobProfiles);
} }
return $filterDto; return $filterDto;
@@ -84,8 +84,10 @@ class TeamerFilterHandler
'pickup_id' => $filterDto->getPickupId(), 'pickup_id' => $filterDto->getPickupId(),
'ski_license' => $filterDto->hasSkiLicense(), 'ski_license' => $filterDto->hasSkiLicense(),
'snowboard_license' => $filterDto->hasSnowboardLicense(), 'snowboard_license' => $filterDto->hasSnowboardLicense(),
'job_profile' => $filterDto->getJobProfile()?->getId(),
'no_trainings' => $filterDto->hasNoTrainings(), 'no_trainings' => $filterDto->hasNoTrainings(),
'job_profiles' => array_map(function (JobProfile $jobProfile) {
return $jobProfile->getId();
}, $filterDto->getJobProfiles()),
]); ]);
} }
@@ -8,7 +8,7 @@
{{ form_row(filterForm.name) }} {{ form_row(filterForm.name) }}
{{ form_row(filterForm.dateFrom) }} {{ form_row(filterForm.dateFrom) }}
{{ form_row(filterForm.dateTo) }} {{ form_row(filterForm.dateTo) }}
{{ form_row(filterForm.jobProfile) }} {{ form_row(filterForm.jobProfiles) }}
{{ form_row(filterForm.pickupId) }} {{ form_row(filterForm.pickupId) }}
{{ form_row(filterForm.skiLicense) }} {{ form_row(filterForm.skiLicense) }}
{{ form_row(filterForm.snowboardLicense) }} {{ form_row(filterForm.snowboardLicense) }}