$filterManager = $this->get(FilterManager::class); | $filterManager = $this->get(FilterManager::class); | ||||
$this->filtersForm->handleRequest($searchDto->getRequest()); | $this->filtersForm->handleRequest($searchDto->getRequest()); | ||||
$this->isRepositoryQueryFiltered = $filterManager->handleFiltersForm($repositoryQuery, $this->filtersForm, $fields, $entityDto); | $this->isRepositoryQueryFiltered = $filterManager->handleFiltersForm($repositoryQuery, $this->filtersForm, $fields, $entityDto); | ||||
return $repositoryQuery; | return $repositoryQuery; | ||||
} | } |
{ | { | ||||
return [ | return [ | ||||
'id' => IdField::new('id') | 'id' => IdField::new('id') | ||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
->setSortable(true), | |||||
'createdAt' => DateTimeField::new('createdAt') | 'createdAt' => DateTimeField::new('createdAt') | ||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
->setSortable(true), | |||||
'visitorFirstname' => TextField::new('visitorFirstname') | 'visitorFirstname' => TextField::new('visitorFirstname') | ||||
->setTemplatePath('@LcSov/admin/ticket/field/firstname.html.twig') | ->setTemplatePath('@LcSov/admin/ticket/field/firstname.html.twig') | ||||
->setCustomOption('filter_fqcn', TicketFirstnameFilter::class) | |||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
->setCustomOption('filter_fqcn', TicketFirstnameFilter::class), | |||||
'visitorLastname' => TextField::new('visitorLastname') | 'visitorLastname' => TextField::new('visitorLastname') | ||||
->setTemplatePath('@LcSov/admin/ticket/field/lastname.html.twig') | ->setTemplatePath('@LcSov/admin/ticket/field/lastname.html.twig') | ||||
->setCustomOption('filter_fqcn', TicketLastnameFilter::class) | |||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
->setCustomOption('filter_fqcn', TicketLastnameFilter::class), | |||||
'visitorEmail' => TextField::new('visitorEmail') | 'visitorEmail' => TextField::new('visitorEmail') | ||||
->setTemplatePath('@LcSov/admin/ticket/field/email.html.twig') | ->setTemplatePath('@LcSov/admin/ticket/field/email.html.twig') | ||||
->setCustomOption('filter_fqcn', TicketEmailFilter::class) | |||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
'user' => AssociationField::new('user') | |||||
->hideOnIndex(), | |||||
->setCustomOption('filter_fqcn', TicketEmailFilter::class), | |||||
'user' => AssociationField::new('user'), | |||||
'subject' => TextField::new('subject') | 'subject' => TextField::new('subject') | ||||
->setSortable(true), | ->setSortable(true), | ||||
'updatedAt' => DateTimeField::new('updatedAt') | 'updatedAt' => DateTimeField::new('updatedAt') | ||||
->setTemplatePath('@LcSov/admin/ticket/field/lastmessage.html.twig') | ->setTemplatePath('@LcSov/admin/ticket/field/lastmessage.html.twig') | ||||
->setSortable(true) | |||||
->hideOnForm(), | |||||
->setSortable(true), | |||||
'type' => ChoiceField::new('type') | 'type' => ChoiceField::new('type') | ||||
->autocomplete() | ->autocomplete() | ||||
->setSortable(true) | ->setSortable(true) |
public function configureFields(): array | public function configureFields(): array | ||||
{ | { | ||||
return [ | return [ | ||||
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true), | |||||
'id' => IntegerField::new('id')->setSortable(true), | |||||
'gender' => ChoiceField::new('gender')->setChoices( | 'gender' => ChoiceField::new('gender')->setChoices( | ||||
$this->translatorAdmin->transChoices(UserSolver::getGenderChoices(), 'User', 'gender') | $this->translatorAdmin->transChoices(UserSolver::getGenderChoices(), 'User', 'gender') | ||||
) | ) |
<?php | |||||
namespace Lc\SovBundle\EventListener; | |||||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | |||||
use Symfony\Component\HttpKernel\Event\ExceptionEvent; | |||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; | |||||
class ExceptionListener | |||||
{ | |||||
public function __construct( | |||||
SessionInterface $session | |||||
) { | |||||
$this->session = $session; | |||||
} | |||||
public function onKernelException(ExceptionEvent $event) | |||||
{ | |||||
// You get the exception object from the received event | |||||
$exception = $event->getThrowable(); | |||||
// On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin | |||||
if ($exception instanceof HttpExceptionInterface != true) { | |||||
foreach ($this->session->all() as $key => $s) { | |||||
if (str_contains($key, "_filter")) { | |||||
$this->session->remove($key); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
use FilterTrait; | use FilterTrait; | ||||
public function __construct(SessionInterface $session, EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin) | |||||
{ | |||||
public function __construct( | |||||
SessionInterface $session, | |||||
EntityManagerInterface $entityManager, | |||||
TranslatorAdmin $translatorAdmin | |||||
) { | |||||
$this->session = $session; | $this->session = $session; | ||||
$this->em = $entityManager; | $this->em = $entityManager; | ||||
$this->translatorAdmin = $translatorAdmin; | $this->translatorAdmin = $translatorAdmin; | ||||
} | } | ||||
public function handleFiltersForm(RepositoryQueryInterface $repositoryQuery, Form $filtersForm, $fields, EntityDto $entityDto):bool | |||||
{ | |||||
public function handleFiltersForm( | |||||
RepositoryQueryInterface $repositoryQuery, | |||||
Form $filtersForm, | |||||
$fields, | |||||
EntityDto $entityDto | |||||
): bool { | |||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
$filteredValue = array(); | $filteredValue = array(); | ||||
if ($field instanceof FieldInterface) { | if ($field instanceof FieldInterface) { | ||||
} | } | ||||
if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | ||||
if ($filtersForm->has($this->getFieldPropertySnake($fieldDto->getProperty()))) { | if ($filtersForm->has($this->getFieldPropertySnake($fieldDto->getProperty()))) { | ||||
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType() === DateType::class) { | |||||
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType( | |||||
) === DateType::class) { | |||||
$filteredValue['dateStart'] = $this->getFilteredValue( | $filteredValue['dateStart'] = $this->getFilteredValue( | ||||
$filtersForm, | $filtersForm, | ||||
$entityDto->getFqcn(), | $entityDto->getFqcn(), | ||||
$fieldDto->getProperty(), | $fieldDto->getProperty(), | ||||
'dateEnd' | 'dateEnd' | ||||
); | ); | ||||
if($filteredValue['dateStart'] || $filteredValue['dateEnd']){ | |||||
if ($filteredValue['dateStart'] || $filteredValue['dateEnd']) { | |||||
$this->isFiltered = true; | $this->isFiltered = true; | ||||
} | } | ||||
} else { | } else { | ||||
$entityDto->getFqcn(), | $entityDto->getFqcn(), | ||||
$fieldDto->getProperty() | $fieldDto->getProperty() | ||||
); | ); | ||||
if($filteredValue['value'] ){ | |||||
if ($filteredValue['value']) { | |||||
$this->isFiltered = true; | $this->isFiltered = true; | ||||
} | } | ||||
} | } | ||||
$customFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | $customFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | ||||
} else { | } else { | ||||
switch ($fieldDto->getFormType()) { | switch ($fieldDto->getFormType()) { | ||||
case CheckboxType::class: | case CheckboxType::class: | ||||
$checkboxFilter = new CheckboxFilter(); | $checkboxFilter = new CheckboxFilter(); | ||||
$checkboxFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | $checkboxFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | ||||
} | } | ||||
public function getFilteredValue( | public function getFilteredValue( | ||||
Form $filtersForm, | |||||
Form $filtersForm, | |||||
string $entityFqcn, | string $entityFqcn, | ||||
string $field, | string $field, | ||||
string $dateExtraField = null | string $dateExtraField = null | ||||
) | |||||
{ | |||||
) { | |||||
$field = $this->getFieldPropertySnake($field); | $field = $this->getFieldPropertySnake($field); | ||||
$sessionParam = $entityFqcn . $field . $dateExtraField; | |||||
$sessionParam = "_filter/" . $entityFqcn . $field . $dateExtraField; | |||||
$formField = $this->getFormField($filtersForm, $field, $dateExtraField); | $formField = $this->getFormField($filtersForm, $field, $dateExtraField); | ||||
$value = $formField->getData(); | $value = $formField->getData(); | ||||
return $value; | return $value; | ||||
} | } | ||||
} | } | ||||
public function getFormField(Form $filtersForm, string $field, string $extraField = null): Form | public function getFormField(Form $filtersForm, string $field, string $extraField = null): Form |
Lc\SovBundle\Maker\: | Lc\SovBundle\Maker\: | ||||
resource: '../../Maker/' | resource: '../../Maker/' | ||||
tags: [ 'maker.command' ] | tags: [ 'maker.command' ] | ||||
Lc\SovBundle\EventListener\ExceptionListener: | |||||
tags: | |||||
- { name: kernel.event_listener, event: kernel.exception } |