Feat: Add teamer filter
This commit is contained in:
@@ -55,10 +55,10 @@ class AssignmentFilterHandler
|
||||
$filterDto = new AssignmentFilterDto();
|
||||
|
||||
if (isset($data['date_from'])) {
|
||||
$filterDto->setDateFrom(new \DateTimeImmutable($data['date_from']));
|
||||
$filterDto->setDateFrom($data['date_from']);
|
||||
}
|
||||
if (isset($data['date_to'])) {
|
||||
$filterDto->setDateTo(new \DateTimeImmutable($data['date_to']));
|
||||
$filterDto->setDateTo($data['date_to']);
|
||||
}
|
||||
if (isset($data['job_profile']) && 0 < (int) $data['job_profile']) {
|
||||
$jobProfile = $this
|
||||
@@ -86,8 +86,8 @@ class AssignmentFilterHandler
|
||||
private function saveFilterSettings(AssignmentFilterDto $filterDto): void
|
||||
{
|
||||
$this->getSession()->set($this->namespace, [
|
||||
'date_from' => $filterDto->getDateFrom()?->format('Y-m-d'),
|
||||
'date_to' => $filterDto->getDateTo()?->format('Y-m-d'),
|
||||
'date_from' => $filterDto->getDateFrom(),
|
||||
'date_to' => $filterDto->getDateTo(),
|
||||
'job_profile' => $filterDto->getJobProfile()?->getId(),
|
||||
'destination' => $filterDto->getDestination()?->getId(),
|
||||
'duration' => $filterDto->getDuration(),
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Common;
|
||||
|
||||
use App\Entity\JobProfile;
|
||||
use App\Model\TeamerFilterDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
class TeamerFilterHandler
|
||||
{
|
||||
private string $namespace = 'filter:teamer';
|
||||
|
||||
public function __construct(
|
||||
private readonly RequestStack $requestStack,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
public function setNamespace(string $namespace): static
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handleRequest(FormInterface $form): TeamerFilterDto
|
||||
{
|
||||
$filterDto = $form->getData();
|
||||
|
||||
if ($form->get('reset')->isClicked()) {
|
||||
$filterDto = new TeamerFilterDto();
|
||||
$this->resetFilterSettings();
|
||||
} elseif ($form->get('apply')->isClicked()) {
|
||||
$this->saveFilterSettings($filterDto);
|
||||
}
|
||||
|
||||
return $filterDto;
|
||||
}
|
||||
|
||||
public function resetFilterSettings(): void
|
||||
{
|
||||
$this->getSession()->remove($this->namespace);
|
||||
}
|
||||
|
||||
public function getFilterSettings(): TeamerFilterDto
|
||||
{
|
||||
if (null === $data = $this->getSession()->get($this->namespace)) {
|
||||
return new TeamerFilterDto();
|
||||
}
|
||||
|
||||
$filterDto = new TeamerFilterDto();
|
||||
|
||||
$filterDto
|
||||
->setName($data['name'])
|
||||
->setDateFrom($data['date_from'])
|
||||
->setDateTo($data['date_to'])
|
||||
->setPickupId($data['pickup_id'])
|
||||
->setSkiLicense($data['ski_license'])
|
||||
->setSnowboardLicense($data['snowboard_license'])
|
||||
;
|
||||
|
||||
if (0 < (int) $data['job_profile']) {
|
||||
$jobProfile = $this
|
||||
->entityManager
|
||||
->getRepository(JobProfile::class)
|
||||
->find($data['job_profile'])
|
||||
;
|
||||
$filterDto->setJobProfile($jobProfile);
|
||||
}
|
||||
|
||||
return $filterDto;
|
||||
}
|
||||
|
||||
private function saveFilterSettings(TeamerFilterDto $filterDto): void
|
||||
{
|
||||
$this->getSession()->set($this->namespace, [
|
||||
'name' => $filterDto->getName(),
|
||||
'date_from' => $filterDto->getDateFrom(),
|
||||
'date_to' => $filterDto->getDateTo(),
|
||||
'pickup_id' => $filterDto->getPickupId(),
|
||||
'ski_license' => $filterDto->hasSkiLicense(),
|
||||
'snowboard_license' => $filterDto->hasSnowboardLicense(),
|
||||
'job_profile' => $filterDto->getJobProfile()?->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getSession(): SessionInterface
|
||||
{
|
||||
return $this->requestStack->getSession();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user