mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add filter for generic doc + fix issues in filter
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Chill\DocStoreBundle\Controller;
|
||||
use Chill\DocStoreBundle\GenericDoc\Manager;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -25,9 +26,10 @@ use Symfony\Component\Templating\EngineInterface;
|
||||
final readonly class GenericDocForAccompanyingPeriodController
|
||||
{
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private FilterOrderHelperFactory $filterOrderHelperFactory,
|
||||
private Manager $manager,
|
||||
private PaginatorFactory $paginator,
|
||||
private Security $security,
|
||||
private EngineInterface $twig,
|
||||
) {
|
||||
}
|
||||
@@ -45,12 +47,41 @@ final readonly class GenericDocForAccompanyingPeriodController
|
||||
throw new AccessDeniedHttpException("not allowed to see the documents for accompanying period");
|
||||
}
|
||||
|
||||
$nb = $this->manager->countDocForAccompanyingPeriod($accompanyingPeriod);
|
||||
$filterBuilder = $this->filterOrderHelperFactory
|
||||
->create(self::class)
|
||||
->addSearchBox()
|
||||
->addDateRange('dateRange', 'generic_doc.filter.date-range');
|
||||
|
||||
if ([] !== $places = $this->manager->placesForAccompanyingPeriod($accompanyingPeriod)) {
|
||||
$filterBuilder->addCheckbox('places', $places, [], array_map(
|
||||
static fn (string $k) => 'generic_doc.filter.keys.' . $k,
|
||||
$places
|
||||
));
|
||||
}
|
||||
|
||||
$filter = $filterBuilder
|
||||
->build();
|
||||
|
||||
['to' => $endDate, 'from' => $startDate ] = $filter->getDateRangeData('dateRange');
|
||||
$content = $filter->getQueryString();
|
||||
|
||||
$nb = $this->manager->countDocForAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$content,
|
||||
$filter->hasCheckBox('places') ? array_values($filter->getCheckboxData('places')) : []
|
||||
);
|
||||
$paginator = $this->paginator->create($nb);
|
||||
|
||||
$documents = $this->manager->findDocForAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
$paginator->getCurrentPageFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
$paginator->getItemsPerPage(),
|
||||
$startDate,
|
||||
$endDate,
|
||||
$content,
|
||||
$filter->hasCheckBox('places') ? array_values($filter->getCheckboxData('places')) : []
|
||||
);
|
||||
|
||||
return new Response($this->twig->render(
|
||||
@@ -59,6 +90,7 @@ final readonly class GenericDocForAccompanyingPeriodController
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'pagination' => $paginator,
|
||||
'documents' => iterator_to_array($documents),
|
||||
'filter' => $filter,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
Reference in New Issue
Block a user