aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Controller
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-04-27 16:23:54 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-05-02 15:28:39 +0200
commit50cfd8108b8e318fd28564d2e9d30943ab12aac0 (patch)
treee5b5da24c787d2278e8c2771f00686311be11504 /src/Wallabag/UserBundle/Controller
parentc37515f880bd05b86e3e848cc184018295ec1920 (diff)
downloadwallabag-50cfd8108b8e318fd28564d2e9d30943ab12aac0.tar.gz
wallabag-50cfd8108b8e318fd28564d2e9d30943ab12aac0.tar.zst
wallabag-50cfd8108b8e318fd28564d2e9d30943ab12aac0.zip
Add pagination
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php
index f0e3d4de..86fcd431 100644
--- a/src/Wallabag/UserBundle/Controller/ManageController.php
+++ b/src/Wallabag/UserBundle/Controller/ManageController.php
@@ -4,12 +4,14 @@ namespace Wallabag\UserBundle\Controller;
4 4
5use FOS\UserBundle\Event\UserEvent; 5use FOS\UserBundle\Event\UserEvent;
6use FOS\UserBundle\FOSUserEvents; 6use FOS\UserBundle\FOSUserEvents;
7use Pagerfanta\Adapter\DoctrineORMAdapter;
8use Pagerfanta\Exception\OutOfRangeCurrentPageException;
9use Pagerfanta\Pagerfanta;
7use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller; 11use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 12use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 13use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11use Wallabag\UserBundle\Entity\User; 14use Wallabag\UserBundle\Entity\User;
12use Wallabag\CoreBundle\Entity\Config;
13use Wallabag\UserBundle\Form\SearchUserType; 15use Wallabag\UserBundle\Form\SearchUserType;
14 16
15/** 17/**
@@ -20,17 +22,32 @@ class ManageController extends Controller
20 /** 22 /**
21 * Lists all User entities. 23 * Lists all User entities.
22 * 24 *
23 * @Route("/", name="user_index") 25 * @Route("/index/{page}", name="user_index")
24 * @Method("GET") 26 * @Method("GET")
27 *
28 * @param int $page
29 *
30 * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
25 */ 31 */
26 public function indexAction() 32 public function indexAction($page = 1)
27 { 33 {
28 $em = $this->getDoctrine()->getManager(); 34 $em = $this->getDoctrine()->getManager();
29 35
30 $users = $em->getRepository('WallabagUserBundle:User')->findAll(); 36 $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u');
37 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
38 $pagerFanta = new Pagerfanta($pagerAdapter);
39 $pagerFanta->setMaxPerPage(50);
40
41 try {
42 $pagerFanta->setCurrentPage($page);
43 } catch (OutOfRangeCurrentPageException $e) {
44 if ($page > 1) {
45 return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
46 }
47 }
31 48
32 return $this->render('WallabagUserBundle:Manage:index.html.twig', array( 49 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
33 'users' => $users, 50 'users' => $pagerFanta,
34 )); 51 ));
35 } 52 }
36 53
@@ -176,10 +193,22 @@ class ManageController extends Controller
176 193
177 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); 194 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
178 195
179 $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm); 196 $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm);
197
198 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
199 $pagerFanta = new Pagerfanta($pagerAdapter);
200 $pagerFanta->setMaxPerPage(50);
201
202 try {
203 $pagerFanta->setCurrentPage($page);
204 } catch (OutOfRangeCurrentPageException $e) {
205 if ($page > 1) {
206 return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
207 }
208 }
180 209
181 return $this->render('WallabagUserBundle:Manage:index.html.twig', array( 210 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
182 'users' => $users, 211 'users' => $pagerFanta,
183 )); 212 ));
184 } 213 }
185 214