feat: multiselect field for filtering
This commit is contained in:
@@ -80,11 +80,11 @@ class AssignmentFilterType extends AbstractType
|
||||
|
||||
if (0 < count($options['job_profiles'])) {
|
||||
$builder
|
||||
->add('jobProfile', EntityType::class, [
|
||||
->add('jobProfiles', MultiselectEntityType::class, [
|
||||
'label' => 'Job-Profil',
|
||||
'class' => JobProfile::class,
|
||||
'required' => false,
|
||||
'placeholder' => 'nicht filtern',
|
||||
'empty_label' => 'nicht filtern',
|
||||
'choice_label' => 'name',
|
||||
'choices' => $options['job_profiles'],
|
||||
])
|
||||
@@ -96,10 +96,10 @@ class AssignmentFilterType extends AbstractType
|
||||
$choices[$item->getHotel()] = $item->getHotelCode();
|
||||
}
|
||||
$builder
|
||||
->add('hotel', ChoiceType::class, [
|
||||
->add('hotels', MultiselectType::class, [
|
||||
'label' => 'Haus',
|
||||
'required' => false,
|
||||
'placeholder' => 'nicht filtern',
|
||||
'empty_label' => 'nicht filtern',
|
||||
'choices' => $choices,
|
||||
])
|
||||
;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MultiselectEntityType extends AbstractType
|
||||
{
|
||||
public function getParent(): string
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
$view->vars['empty_label'] = $options['empty_label'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'empty_label' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'multiselect';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MultiselectType extends AbstractType
|
||||
{
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
$view->vars['empty_label'] = $options['empty_label'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'empty_label' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'multiselect';
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ class AssignmentFilterDto extends AbstractFilterDto
|
||||
|
||||
protected ?\DateTimeImmutable $dateFrom = null;
|
||||
protected ?\DateTimeImmutable $dateTo = null;
|
||||
protected ?JobProfile $jobProfile = null;
|
||||
protected ?string $hotel = null;
|
||||
protected array $jobProfiles = [];
|
||||
protected array $hotels = [];
|
||||
protected ?int $duration = null;
|
||||
protected ?string $status = null;
|
||||
protected bool $includePast = false;
|
||||
@@ -44,26 +44,26 @@ class AssignmentFilterDto 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;
|
||||
}
|
||||
|
||||
public function getHotel(): ?string
|
||||
public function getHotels(): ?array
|
||||
{
|
||||
return $this->hotel;
|
||||
return $this->hotels;
|
||||
}
|
||||
|
||||
public function setHotel(?string $hotel): static
|
||||
public function setHotels(array $hotels): static
|
||||
{
|
||||
$this->hotel = $hotel;
|
||||
$this->hotels = $hotels;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -154,17 +154,17 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $jobProfile = $filterDto->getJobProfile()) {
|
||||
if ($jobProfiles = $filterDto->getJobProfiles()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('assignment.jobProfile', ':jobProfile'))
|
||||
->setParameter('jobProfile', $jobProfile)
|
||||
->andWhere($qb->expr()->in('assignment.jobProfile', ':jobProfiles'))
|
||||
->setParameter('jobProfiles', $jobProfiles)
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $hotelCode = $filterDto->getHotel()) {
|
||||
if ($hotelCodes = $filterDto->getHotels()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('destination.hotelCode', ':hotelCode'))
|
||||
->setParameter('hotelCode', $hotelCode)
|
||||
->andWhere($qb->expr()->in('destination.hotelCode', ':hotelCodes'))
|
||||
->setParameter('hotelCodes', $hotelCodes)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,16 +59,16 @@ class AssignmentFilterHandler
|
||||
if (isset($data['date_to'])) {
|
||||
$filterDto->setDateTo($data['date_to']);
|
||||
}
|
||||
if (isset($data['job_profile']) && 0 < (int) $data['job_profile']) {
|
||||
$jobProfile = $this
|
||||
if (isset($data['job_profiles']) && 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);
|
||||
}
|
||||
if (isset($data['hotel'])) {
|
||||
$filterDto->setHotel($data['hotel']);
|
||||
if (isset($data['hotels']) && 0 < count($data['hotels'])) {
|
||||
$filterDto->setHotels($data['hotels']);
|
||||
}
|
||||
if (isset($data['duration']) && 0 < (int) $data['duration']) {
|
||||
$filterDto->setDuration($data['duration']);
|
||||
@@ -88,8 +88,10 @@ class AssignmentFilterHandler
|
||||
$this->getSession()->set($this->namespace, [
|
||||
'date_from' => $filterDto->getDateFrom(),
|
||||
'date_to' => $filterDto->getDateTo(),
|
||||
'job_profile' => $filterDto->getJobProfile()?->getId(),
|
||||
'hotel' => $filterDto->getHotel(),
|
||||
'job_profiles' => array_map(function (JobProfile $jobProfile) {
|
||||
return $jobProfile->getId();
|
||||
}, $filterDto->getJobProfiles()),
|
||||
'hotels' => $filterDto->getHotels(),
|
||||
'duration' => $filterDto->getDuration(),
|
||||
'status' => $filterDto->getStatus(),
|
||||
'include_past' => $filterDto->isIncludePast(),
|
||||
|
||||
Reference in New Issue
Block a user