mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-31 15:55:06 +01:00
Add pagination
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
c37515f880
commit
50cfd8108b
@ -4,12 +4,14 @@ namespace Wallabag\UserBundle\Controller;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -20,17 +22,32 @@ class ManageController extends Controller
|
||||
/**
|
||||
* 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,
|
||||
));
|
||||
}
|
||||
|
||||
@ -176,10 +193,22 @@ class ManageController extends Controller
|
||||
|
||||
$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,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,9 @@ class UserRepository extends EntityRepository
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getUsersForSearch($term)
|
||||
public function getQueryBuilderForSearch($term)
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%');
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
<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>
|
||||
@ -22,7 +25,7 @@
|
||||
<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>
|
||||
@ -43,6 +46,9 @@
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user