feat: filter assignments by id

This commit is contained in:
Björn Fromme
2024-12-02 14:19:35 +01:00
parent a378bc2e41
commit 44d130414c
5 changed files with 51 additions and 13 deletions
+20 -11
View File
@@ -12,6 +12,7 @@ use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -27,6 +28,7 @@ class AssignmentFilterType extends AbstractType
$builder
->add('dateFrom', DatepickerType::class, [
'label' => 'Zeitraum von',
'required' => false,
'min_date' => $options['min_date'],
'max_date' => $options['max_date'],
'attr' => [
@@ -35,6 +37,7 @@ class AssignmentFilterType extends AbstractType
])
->add('dateTo', DatepickerType::class, [
'label' => 'Zeitraum bis',
'required' => false,
'min_date' => $options['min_date'],
'max_date' => $options['max_date'],
'attr' => [
@@ -65,17 +68,23 @@ class AssignmentFilterType extends AbstractType
;
if ($this->security->isGranted('ROLE_ADMINISTRATIVE')) {
$builder->add('status', MultiselectType::class, [
'label' => 'Status',
'required' => false,
'empty_label' => 'nicht filtern',
'choices' => [
'voll besetzt' => Assignment::STATUS_STAFFED,
'teilweise besetzt' => Assignment::STATUS_PARTLY_STAFFED,
'unbesetzt' => Assignment::STATUS_UNSTAFFED,
'mit Bewerbungen' => Assignment::STATUS_STAFFING,
],
]);
$builder
->add('id', IntegerType::class, [
'label' => 'ID',
'required' => false,
])
->add('status', MultiselectType::class, [
'label' => 'Status',
'required' => false,
'empty_label' => 'nicht filtern',
'choices' => [
'voll besetzt' => Assignment::STATUS_STAFFED,
'teilweise besetzt' => Assignment::STATUS_PARTLY_STAFFED,
'unbesetzt' => Assignment::STATUS_UNSTAFFED,
'mit Bewerbungen' => Assignment::STATUS_STAFFING,
],
])
;
}
if (0 < count($options['job_profiles'])) {
+13
View File
@@ -12,6 +12,7 @@ class AssignmentFilterDto extends AbstractFilterDto
public const DURATION_FULL_WEEK = 3;
public const DURATION_MORE = 4;
protected ?int $id = null;
protected ?\DateTimeImmutable $dateFrom = null;
protected ?\DateTimeImmutable $dateTo = null;
protected array $jobProfiles = [];
@@ -20,6 +21,18 @@ class AssignmentFilterDto extends AbstractFilterDto
protected array $status = [];
protected bool $includePast = false;
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): static
{
$this->id = $id;
return $this;
}
public function getDateFrom(): ?\DateTimeImmutable
{
return $this->dateFrom;
+7
View File
@@ -85,6 +85,13 @@ class AssignmentRepository extends ServiceEntityRepository
private function applyFilterSettings(AssignmentFilterDto $filterDto, QueryBuilder $qb): void
{
if (null !== $filterDto->getId()) {
$qb
->andWhere($qb->expr()->eq('assignment.id', ':id'))
->setParameter('id', $filterDto->getId())
;
}
if (false === $filterDto->isIncludePast()) {
$qb
->andWhere($qb->expr()->gte('destination.dateFrom', ':now'))
@@ -18,6 +18,9 @@ class AssignmentFilterHandler extends AbstractFilterHandler
$filterDto = new AssignmentFilterDto();
if (isset($data['id'])) {
$filterDto->setId($data['id']);
}
if (isset($data['date_from'])) {
$filterDto->setDateFrom($data['date_from']);
}
@@ -52,6 +55,7 @@ class AssignmentFilterHandler extends AbstractFilterHandler
{
/** @var AssignmentFilterDto $filterDto */
$this->getSession()->set($this->namespace, [
'id' => $filterDto->getId(),
'date_from' => $filterDto->getDateFrom(),
'date_to' => $filterDto->getDateTo(),
'job_profiles' => array_map(function (JobProfile $jobProfile) {
@@ -5,11 +5,16 @@
{% block content %}
{{ form_start(filterForm, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
<div class="flex flex-col space-y-2 pb-4">
{% if filterForm.id is defined %}
{{ form_row(filterForm.id) }}
{% endif %}
{% if filterForm.status is defined %}
{{ form_row(filterForm.status) }}
{% endif %}
{{ form_row(filterForm.dateFrom) }}
{{ form_row(filterForm.dateTo) }}
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
{{ form_row(filterForm.dateFrom) }}
{{ form_row(filterForm.dateTo) }}
</div>
{{ form_row(filterForm.jobProfiles) }}
{{ form_row(filterForm.hotels) }}
{{ form_row(filterForm.duration) }}