diff --git a/src/Bundle/ChillMainBundle/Pagination/ChillItemsPerPageTwig.php b/src/Bundle/ChillMainBundle/Pagination/ChillItemsPerPageTwig.php new file mode 100644 index 000000000..2cfb45d4a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Pagination/ChillItemsPerPageTwig.php @@ -0,0 +1,67 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\MainBundle\Pagination; + +use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +/** + * add twig function to render pagination + * + * @author Mathieu Jaumotte + * @author Champs Libres + */ +class ChillItemsPerPageTwig extends AbstractExtension +{ + public function getName() + { + return 'chill_items_per_page'; + } + + public function getFunctions() + { + return array( + new TwigFunction( + 'chill_items_per_page', + array($this, 'paginationRender'), + array( + 'needs_environment' => true, + 'is_safe' => ['html'] + ) + ) + ); + } + + public function paginationRender( + Environment $env, + PaginatorInterface $paginator, + $template = '@ChillMain/Pagination/items_per_page.html.twig' + ) { + + return $env->render($template, array( + 'paginator' => $paginator, + 'current' => $paginator->getItemsPerPage() + )); + } +} diff --git a/src/Bundle/ChillMainBundle/Pagination/PaginatorFactory.php b/src/Bundle/ChillMainBundle/Pagination/PaginatorFactory.php index 0e8338da3..c386a9757 100644 --- a/src/Bundle/ChillMainBundle/Pagination/PaginatorFactory.php +++ b/src/Bundle/ChillMainBundle/Pagination/PaginatorFactory.php @@ -61,7 +61,7 @@ class PaginatorFactory public function __construct( RequestStack $requestStack, RouterInterface $router, - $itemPerPage = 50 + $itemPerPage = 20 ) { $this->itemPerPage = $itemPerPage; $this->requestStack = $requestStack; diff --git a/src/Bundle/ChillMainBundle/Resources/views/Pagination/items_per_page.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Pagination/items_per_page.html.twig new file mode 100644 index 000000000..52b849163 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Pagination/items_per_page.html.twig @@ -0,0 +1,20 @@ + + diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index f6282a39f..aecf55fa5 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -8,8 +8,13 @@ services: - "%chill_main.pagination.item_per_page%" Chill\MainBundle\Pagination\PaginatorFactory: '@chill_main.paginator_factory' - + chill_main.paginator.twig_extensions: class: Chill\MainBundle\Pagination\ChillPaginationTwig tags: - { name: twig.extension } + + chill_main.paginator.items_per_page.twig_extensions: + class: Chill\MainBundle\Pagination\ChillItemsPerPageTwig + tags: + - { name: twig.extension } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index dc282ec52..b230b6ac1 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -85,6 +85,7 @@ Search %pattern%: Recherche de "%pattern%" Results %start%-%end% of %total%: Résultats %start%-%end% sur %total% See all results: Voir tous les résultats Advanced search: Recherche avancée +results: résultats # timeline Global timeline: Historique global diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php index 59a56af28..d16934b18 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php @@ -70,8 +70,6 @@ class ThirdPartyController extends Controller $nbThirdParties = $repository->countByMemberOfCenters($centers); $pagination = $this->paginatorFactory->create($nbThirdParties); - $pagination->setItemsPerPage(20); - $thirdParties = $repository->findByMemberOfCenters( $centers, $pagination->getCurrentPage()->getFirstItemNumber(), diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig index 12f4560c2..aa3f61088 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig @@ -15,6 +15,7 @@ @@ -23,7 +24,7 @@
@@ -82,11 +83,7 @@
  • - + {{ chill_items_per_page(pagination) }}
  • {% if is_granted('CHILL_3PARTY_3PARTY_CREATE') %}