Feat: Refactor assignment filter to modal
This commit is contained in:
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace App\Service\Common;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\JobProfile;
|
||||
use App\Form\AssignmentFilterType;
|
||||
use App\Model\AssignmentFilterDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
@@ -20,8 +16,7 @@ class AssignmentFilterHandler
|
||||
|
||||
public function __construct(
|
||||
private readonly RequestStack $requestStack,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly FormFactoryInterface $formFactory,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -32,44 +27,21 @@ class AssignmentFilterHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getForm(): FormInterface
|
||||
public function handleRequest(FormInterface $form): AssignmentFilterDto
|
||||
{
|
||||
$filterDto = $this->getFilterSettings();
|
||||
|
||||
$assignmentRepository = $this
|
||||
->entityManager
|
||||
->getRepository(Assignment::class)
|
||||
;
|
||||
$filterOptions = $assignmentRepository->getFilterOptions();
|
||||
|
||||
return $this->formFactory->create(AssignmentFilterType::class, $filterDto, [
|
||||
'min_date' => $filterOptions['minDate'],
|
||||
'max_date' => $filterOptions['maxDate'],
|
||||
'job_profiles' => $filterOptions['jobProfiles'],
|
||||
'destinations' => $filterOptions['destinations'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function handleRequest(
|
||||
FormInterface $form,
|
||||
Request $request
|
||||
): AssignmentFilterDto {
|
||||
$form->handleRequest($request);
|
||||
$filterDto = $form->getData();
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if ($form->has('reset') && $form->get('reset')->isClicked()) {
|
||||
$filterDto = new AssignmentFilterDto(true);
|
||||
$this->getSession()->remove($this->namespace);
|
||||
} elseif ($form->has('apply') && $form->get('apply')->isClicked()) {
|
||||
$this->saveFilterSettings($filterDto);
|
||||
}
|
||||
if ($form->get('reset')->isClicked()) {
|
||||
$filterDto = new AssignmentFilterDto(true);
|
||||
$this->getSession()->remove($this->namespace);
|
||||
} elseif ($form->get('apply')->isClicked()) {
|
||||
$this->saveFilterSettings($filterDto);
|
||||
}
|
||||
|
||||
return $filterDto;
|
||||
}
|
||||
|
||||
private function getFilterSettings(): AssignmentFilterDto
|
||||
public function getFilterSettings(): AssignmentFilterDto
|
||||
{
|
||||
if (null === $data = $this->getSession()->get($this->namespace)) {
|
||||
return new AssignmentFilterDto();
|
||||
|
||||
Reference in New Issue
Block a user