X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FUserBundle%2FController%2FManageController.php;h=f0e3d4dea8a183f2d8f2c06001da2f96872afc82;hb=c37515f880bd05b86e3e848cc184018295ec1920;hp=92ee2b4162649fad67e3158ca91c105d13e58ff4;hpb=e1d64050ad6f54e45d3954ffac21daaee58c6240;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 92ee2b41..f0e3d4de 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -10,6 +10,7 @@ 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; /** * User controller. @@ -146,4 +147,45 @@ class ManageController extends Controller ->getForm() ; } + + /** + * @param Request $request + * @param int $page + * + * @Route("/search/{page}", name="user-search", 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, $currentRoute = null) + { + // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template) + if (null === $currentRoute && $request->query->has('currentRoute')) { + $currentRoute = $request->query->get('currentRoute'); + } + + $form = $this->createForm(SearchUserType::class); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->get('logger')->info('searching users'); + $em = $this->getDoctrine()->getManager(); + + $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); + + $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm); + + return $this->render('WallabagUserBundle:Manage:index.html.twig', array( + 'users' => $users, + )); + } + + return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ + 'form' => $form->createView(), + 'currentRoute' => $currentRoute, + ]); + } }