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',
'required' => false,
])
->add('jobProfile', EntityType::class, [
'label' => 'Job-Profil',
->add('jobProfiles', MultiselectEntityType::class, [
'label' => 'Job-Profile',
'class' => JobProfile::class,
'required' => false,
'choice_label' => 'name',
'empty_label' => 'nicht filtern',
'query_builder' => function (EntityRepository $repository) {
return $repository->createQueryBuilder('job_profile')
->orderBy('job_profile.name', 'ASC');
+5 -5
View File
@@ -9,7 +9,7 @@ class TeamerFilterDto extends AbstractFilterDto
protected ?string $name = null;
protected ?\DateTimeImmutable $dateFrom = null;
protected ?\DateTimeImmutable $dateTo = null;
protected ?JobProfile $jobProfile = null;
protected array $jobProfiles = [];
protected string $pickupId = '';
protected bool $skiLicense = false;
protected bool $snowboardLicense = false;
@@ -51,14 +51,14 @@ class TeamerFilterDto extends AbstractFilterDto
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;
}
+3 -3
View File
@@ -66,10 +66,10 @@ class TeamerRepository extends ServiceEntityRepository
;
}
if (null !== $filterDto->getJobProfile()) {
if (0 < count($filterDto->getJobProfiles())) {
$qb
->andWhere($qb->expr()->eq('job_profile', ':jobProfile'))
->setParameter('jobProfile', $filterDto->getJobProfile())
->andWhere($qb->expr()->in('job_profile', ':jobProfiles'))
->setParameter('jobProfiles', $filterDto->getJobProfiles())
;
}
+7 -5
View File
@@ -63,13 +63,13 @@ class TeamerFilterHandler
->setNoTrainings($data['no_trainings'])
;
if (0 < (int) $data['job_profile']) {
$jobProfile = $this
if (0 < count($data['job_profiles'])) {
$jobProfiles = $this
->entityManager
->getRepository(JobProfile::class)
->find($data['job_profile'])
->findBy(['id' => $data['job_profiles']])
;
$filterDto->setJobProfile($jobProfile);
$filterDto->setJobProfiles($jobProfiles);
}
return $filterDto;
@@ -84,8 +84,10 @@ class TeamerFilterHandler
'pickup_id' => $filterDto->getPickupId(),
'ski_license' => $filterDto->hasSkiLicense(),
'snowboard_license' => $filterDto->hasSnowboardLicense(),
'job_profile' => $filterDto->getJobProfile()?->getId(),
'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.dateFrom) }}
{{ form_row(filterForm.dateTo) }}
{{ form_row(filterForm.jobProfile) }}
{{ form_row(filterForm.jobProfiles) }}
{{ form_row(filterForm.pickupId) }}
{{ form_row(filterForm.skiLicense) }}
{{ form_row(filterForm.snowboardLicense) }}