From 10ea0c77e7cb2abd57cd135a4c16ca8e47442389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 25 Aug 2016 22:16:46 +0200 Subject: [PATCH] adding pagination on search + renaming option --- Resources/views/Person/list.html.twig | 5 +++++ Search/PersonSearch.php | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Resources/views/Person/list.html.twig b/Resources/views/Person/list.html.twig index 04b06b9d9..dc90de4bd 100644 --- a/Resources/views/Person/list.html.twig +++ b/Resources/views/Person/list.html.twig @@ -74,3 +74,8 @@ {% endif %} + +{% if preview == false %} +{{ chill_pagination(paginator) }} +{% endif %} + diff --git a/Search/PersonSearch.php b/Search/PersonSearch.php index 922d35d3a..e2678cb6c 100644 --- a/Search/PersonSearch.php +++ b/Search/PersonSearch.php @@ -36,7 +36,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface use ContainerAwareTrait; /** - * + * * @var EntityManagerInterface */ private $em; @@ -49,7 +49,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface /** * - * @var AuthorizationHelper + * @var AuthorizationHelper */ private $helper; @@ -63,8 +63,8 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface public function __construct( - EntityManagerInterface $em, - TokenStorage $tokenStorage, + EntityManagerInterface $em, + TokenStorage $tokenStorage, AuthorizationHelper $helper, PaginatorFactory $paginatorFactory) { @@ -112,20 +112,21 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface $total = $this->count($terms); $paginator = $this->paginatorFactory->create($total); - return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', - array( + return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', + array( 'persons' => $this->search($terms, $start, $limit, $options), 'pattern' => $this->recomposePattern($terms, array('nationality', 'firstname', 'lastname', 'birthdate', 'gender'), $terms['_domain']), 'total' => $total, 'start' => $start, 'search_name' => self::NAME, - 'preview' => $options[SearchInterface::SEARCH_PREVIEW] + 'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION], + 'paginator' => $paginator )); } /** - * + * * @param string $pattern * @param int $start * @param int $limit @@ -161,11 +162,11 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface private $_cacheQuery = array(); /** - * + * * @param array $terms * @return \Doctrine\ORM\QueryBuilder */ - protected function createQuery(array $terms) + protected function createQuery(array $terms) { //get from cache $cacheKey = md5(serialize($terms)); @@ -237,7 +238,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface } //restraint center for security - $reachableCenters = $this->helper->getReachableCenters($this->user, + $reachableCenters = $this->helper->getReachableCenters($this->user, new Role('CHILL_PERSON_SEE')); $qb->andWhere($qb->expr() ->in('p.center', ':centers'))