+ /**
+ * @param Request $request
+ * @param int $page
+ *
+ * @Route("/list/{page}", name="user_index", defaults={"page" = 1})
+ *
+ * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
+ * because this controller is also called inside the layout template without any page as argument
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function searchFormAction(Request $request, $page = 1)
+ {
+ $em = $this->getDoctrine()->getManager();
+ $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u');
+
+ $form = $this->createForm(SearchUserType::class);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->get('logger')->info('searching users');
+
+ $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
+
+ $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', [
+ 'searchForm' => $form->createView(),
+ 'users' => $pagerFanta,
+ ]);
+ }
+