aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php43
-rw-r--r--src/Wallabag/UserBundle/Repository/UserRepository.php6
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig8
3 files changed, 45 insertions, 12 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
diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php
index 66bbab39..6adbe329 100644
--- a/src/Wallabag/UserBundle/Repository/UserRepository.php
+++ b/src/Wallabag/UserBundle/Repository/UserRepository.php
@@ -60,11 +60,9 @@ class UserRepository extends EntityRepository
60 * 60 *
61 * @return QueryBuilder 61 * @return QueryBuilder
62 */ 62 */
63 public function getUsersForSearch($term) 63 public function getQueryBuilderForSearch($term)
64 { 64 {
65 return $this->createQueryBuilder('u') 65 return $this->createQueryBuilder('u')
66 ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%') 66 ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%');
67 ->getQuery()
68 ->getResult();
69 } 67 }
70} 68}
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
index abc02852..7a76f157 100644
--- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
@@ -7,6 +7,9 @@
7 <div class="row"> 7 <div class="row">
8 <div class="col s12"> 8 <div class="col s12">
9 <div class="card-panel"> 9 <div class="card-panel">
10 {% if users.getNbPages > 1 %}
11 {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }}
12 {% endif %}
10 <div class="row"> 13 <div class="row">
11 <div class="col s6"> 14 <div class="col s6">
12 <p class="help">{{ 'user.description'|trans|raw }}</p> 15 <p class="help">{{ 'user.description'|trans|raw }}</p>
@@ -22,7 +25,7 @@
22 <tr> 25 <tr>
23 <th>{{ 'user.form.username_label'|trans }}</th> 26 <th>{{ 'user.form.username_label'|trans }}</th>
24 <th>{{ 'user.form.email_label'|trans }}</th> 27 <th>{{ 'user.form.email_label'|trans }}</th>
25 <th>{{ 'user.form2017-03-10 16:51:07.last_login_label'|trans }}</th> 28 <th>{{ 'user.form.last_login_label'|trans }}</th>
26 <th>{{ 'user.list.actions'|trans }}</th> 29 <th>{{ 'user.list.actions'|trans }}</th>
27 </tr> 30 </tr>
28 </thead> 31 </thead>
@@ -43,6 +46,9 @@
43 <p> 46 <p>
44 <a href="{{ path('user_new') }}" class="waves-effect waves-light btn">{{ 'user.list.create_new_one'|trans }}</a> 47 <a href="{{ path('user_new') }}" class="waves-effect waves-light btn">{{ 'user.list.create_new_one'|trans }}</a>
45 </p> 48 </p>
49 {% if users.getNbPages > 1 %}
50 {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }}
51 {% endif %}
46 </div> 52 </div>
47 </div> 53 </div>
48 </div> 54 </div>