use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\FOSUserEvents;
+use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Exception\OutOfRangeCurrentPageException;
+use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Wallabag\UserBundle\Entity\User;
-use Wallabag\CoreBundle\Entity\Config;
use Wallabag\UserBundle\Form\SearchUserType;
/**
/**
* Lists all User entities.
*
- * @Route("/", name="user_index")
+ * @Route("/index/{page}", name="user_index")
* @Method("GET")
+ *
+ * @param int $page
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
- public function indexAction()
+ public function indexAction($page = 1)
{
$em = $this->getDoctrine()->getManager();
- $users = $em->getRepository('WallabagUserBundle:User')->findAll();
+ $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u');
+ $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
+ $pagerFanta = new Pagerfanta($pagerAdapter);
+ $pagerFanta->setMaxPerPage(50);
+
+ try {
+ $pagerFanta->setCurrentPage($page);
+ } catch (OutOfRangeCurrentPageException $e) {
+ if ($page > 1) {
+ return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
+ }
+ }
return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
- 'users' => $users,
+ 'users' => $pagerFanta,
));
}
$searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
- $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm);
+ $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm);
+
+ $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
+ $pagerFanta = new Pagerfanta($pagerAdapter);
+ $pagerFanta->setMaxPerPage(50);
+
+ try {
+ $pagerFanta->setCurrentPage($page);
+ } catch (OutOfRangeCurrentPageException $e) {
+ if ($page > 1) {
+ return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
+ }
+ }
return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
- 'users' => $users,
+ 'users' => $pagerFanta,
));
}
<div class="row">
<div class="col s12">
<div class="card-panel">
+ {% if users.getNbPages > 1 %}
+ {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }}
+ {% endif %}
<div class="row">
<div class="col s6">
<p class="help">{{ 'user.description'|trans|raw }}</p>
<tr>
<th>{{ 'user.form.username_label'|trans }}</th>
<th>{{ 'user.form.email_label'|trans }}</th>
- <th>{{ 'user.form2017-03-10 16:51:07.last_login_label'|trans }}</th>
+ <th>{{ 'user.form.last_login_label'|trans }}</th>
<th>{{ 'user.list.actions'|trans }}</th>
</tr>
</thead>
<p>
<a href="{{ path('user_new') }}" class="waves-effect waves-light btn">{{ 'user.list.create_new_one'|trans }}</a>
</p>
+ {% if users.getNbPages > 1 %}
+ {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }}
+ {% endif %}
</div>
</div>
</div>