Create AccompanyingCourseDocumentRepository and use to add pagination

This commit is contained in:
2022-02-11 11:26:21 +01:00
committed by Julien Fastré
parent d6cc69b919
commit bf0b7f1bb2
2 changed files with 90 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\DocStoreBundle\Controller;
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
use Chill\DocStoreBundle\Form\AccompanyingCourseDocumentType;
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
@@ -38,6 +39,8 @@ class DocumentAccompanyingCourseController extends AbstractController
private PaginatorFactory $paginatorFactory;
private AccompanyingCourseDocumentRepository $courseRepository;
/**
* DocumentAccompanyingCourseController constructor.
*/
@@ -45,12 +48,14 @@ class DocumentAccompanyingCourseController extends AbstractController
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper,
PaginatorFactory $paginatorFactory
PaginatorFactory $paginatorFactory,
AccompanyingCourseDocumentRepository $courseRepository
) {
$this->translator = $translator;
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
$this->paginatorFactory = $paginatorFactory;
$this->courseRepository = $courseRepository;
}
/**
@@ -126,15 +131,17 @@ class DocumentAccompanyingCourseController extends AbstractController
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::SEE, $course);
$documents = $em
->getRepository('ChillDocStoreBundle:AccompanyingCourseDocument')
$total = $this->courseRepository->countByCourse($course);
$pagination = $this->paginatorFactory->create($total);
$documents = $this->courseRepository
->findBy(
['course' => $course],
['date' => 'DESC']
['date' => 'DESC'],
$pagination->getItemsPerPage(),
$pagination->getCurrentPageFirstItemNumber()
);
$total = count($documents);
$pagination = $this->paginatorFactory->create($total);
return $this->render(
'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig',