aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Controller
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-05-02 15:27:58 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-05-02 15:30:32 +0200
commitb5b6877976bc32f23e51c2fb0f3f973f0d571b10 (patch)
treeba12ea034fa9cbef65858c0106e03fded3830649 /src/Wallabag/UserBundle/Controller
parentd01dc5a81e7fde37d98fe6b10b9329b53add5b6a (diff)
downloadwallabag-b5b6877976bc32f23e51c2fb0f3f973f0d571b10.tar.gz
wallabag-b5b6877976bc32f23e51c2fb0f3f973f0d571b10.tar.zst
wallabag-b5b6877976bc32f23e51c2fb0f3f973f0d571b10.zip
Merged list and search methods
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php72
1 files changed, 16 insertions, 56 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php
index 3ea773ee..1c5c86d4 100644
--- a/src/Wallabag/UserBundle/Controller/ManageController.php
+++ b/src/Wallabag/UserBundle/Controller/ManageController.php
@@ -20,38 +20,6 @@ use Wallabag\UserBundle\Form\SearchUserType;
20class ManageController extends Controller 20class ManageController extends Controller
21{ 21{
22 /** 22 /**
23 * Lists all User entities.
24 *
25 * @Route("/list/{page}", name="user_index")
26 * @Method("GET")
27 *
28 * @param int $page
29 *
30 * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
31 */
32 public function indexAction($page = 1)
33 {
34 $em = $this->getDoctrine()->getManager();
35
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 }
48
49 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
50 'users' => $pagerFanta,
51 ));
52 }
53
54 /**
55 * Creates a new User entity. 23 * Creates a new User entity.
56 * 24 *
57 * @Route("/new", name="user_new") 25 * @Route("/new", name="user_new")
@@ -169,52 +137,44 @@ class ManageController extends Controller
169 * @param Request $request 137 * @param Request $request
170 * @param int $page 138 * @param int $page
171 * 139 *
172 * @Route("/search/{page}", name="user-search", defaults={"page" = 1}) 140 * @Route("/list/{page}", name="user_index", defaults={"page" = 1})
173 * 141 *
174 * Default parameter for page is hardcoded (in duplication of the defaults from the Route) 142 * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
175 * because this controller is also called inside the layout template without any page as argument 143 * because this controller is also called inside the layout template without any page as argument
176 * 144 *
177 * @return \Symfony\Component\HttpFoundation\Response 145 * @return \Symfony\Component\HttpFoundation\Response
178 */ 146 */
179 public function searchFormAction(Request $request, $page = 1, $currentRoute = null) 147 public function searchFormAction(Request $request, $page = 1)
180 { 148 {
181 // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template) 149 $em = $this->getDoctrine()->getManager();
182 if (null === $currentRoute && $request->query->has('currentRoute')) { 150 $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u');
183 $currentRoute = $request->query->get('currentRoute');
184 }
185 151
186 $form = $this->createForm(SearchUserType::class); 152 $form = $this->createForm(SearchUserType::class);
187
188 $form->handleRequest($request); 153 $form->handleRequest($request);
189 154
190 if ($form->isSubmitted() && $form->isValid()) { 155 if ($form->isSubmitted() && $form->isValid()) {
191 $this->get('logger')->info('searching users'); 156 $this->get('logger')->info('searching users');
192 $em = $this->getDoctrine()->getManager();
193 157
194 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); 158 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
195 159
196 $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); 160 $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm);
161 }
197 162
198 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); 163 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
199 $pagerFanta = new Pagerfanta($pagerAdapter); 164 $pagerFanta = new Pagerfanta($pagerAdapter);
200 $pagerFanta->setMaxPerPage(50); 165 $pagerFanta->setMaxPerPage(50);
201 166
202 try { 167 try {
203 $pagerFanta->setCurrentPage($page); 168 $pagerFanta->setCurrentPage($page);
204 } catch (OutOfRangeCurrentPageException $e) { 169 } catch (OutOfRangeCurrentPageException $e) {
205 if ($page > 1) { 170 if ($page > 1) {
206 return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); 171 return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
207 }
208 } 172 }
209
210 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
211 'users' => $pagerFanta,
212 ));
213 } 173 }
214 174
215 return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ 175 return $this->render('WallabagUserBundle:Manage:index.html.twig', [
216 'form' => $form->createView(), 176 'searchForm' => $form->createView(),
217 'currentRoute' => $currentRoute, 177 'users' => $pagerFanta,
218 ]); 178 ]);
219 } 179 }
220} 180}