diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-04-27 15:58:32 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2017-05-02 15:28:39 +0200 |
commit | c37515f880bd05b86e3e848cc184018295ec1920 (patch) | |
tree | c64785ee1bce798fe05d6b06e63abff0a41ffcea /src/Wallabag/UserBundle/Controller/ManageController.php | |
parent | e1d64050ad6f54e45d3954ffac21daaee58c6240 (diff) | |
download | wallabag-c37515f880bd05b86e3e848cc184018295ec1920.tar.gz wallabag-c37515f880bd05b86e3e848cc184018295ec1920.tar.zst wallabag-c37515f880bd05b86e3e848cc184018295ec1920.zip |
Add filter to users management page
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/UserBundle/Controller/ManageController.php')
-rw-r--r-- | src/Wallabag/UserBundle/Controller/ManageController.php | 42 |
1 files changed, 42 insertions, 0 deletions
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; | |||
10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
11 | use Wallabag\UserBundle\Entity\User; | 11 | use Wallabag\UserBundle\Entity\User; |
12 | use Wallabag\CoreBundle\Entity\Config; | 12 | use Wallabag\CoreBundle\Entity\Config; |
13 | use Wallabag\UserBundle\Form\SearchUserType; | ||
13 | 14 | ||
14 | /** | 15 | /** |
15 | * User controller. | 16 | * User controller. |
@@ -146,4 +147,45 @@ class ManageController extends Controller | |||
146 | ->getForm() | 147 | ->getForm() |
147 | ; | 148 | ; |
148 | } | 149 | } |
150 | |||
151 | /** | ||
152 | * @param Request $request | ||
153 | * @param int $page | ||
154 | * | ||
155 | * @Route("/search/{page}", name="user-search", defaults={"page" = 1}) | ||
156 | * | ||
157 | * Default parameter for page is hardcoded (in duplication of the defaults from the Route) | ||
158 | * because this controller is also called inside the layout template without any page as argument | ||
159 | * | ||
160 | * @return \Symfony\Component\HttpFoundation\Response | ||
161 | */ | ||
162 | public function searchFormAction(Request $request, $page = 1, $currentRoute = null) | ||
163 | { | ||
164 | // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template) | ||
165 | if (null === $currentRoute && $request->query->has('currentRoute')) { | ||
166 | $currentRoute = $request->query->get('currentRoute'); | ||
167 | } | ||
168 | |||
169 | $form = $this->createForm(SearchUserType::class); | ||
170 | |||
171 | $form->handleRequest($request); | ||
172 | |||
173 | if ($form->isSubmitted() && $form->isValid()) { | ||
174 | $this->get('logger')->info('searching users'); | ||
175 | $em = $this->getDoctrine()->getManager(); | ||
176 | |||
177 | $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); | ||
178 | |||
179 | $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm); | ||
180 | |||
181 | return $this->render('WallabagUserBundle:Manage:index.html.twig', array( | ||
182 | 'users' => $users, | ||
183 | )); | ||
184 | } | ||
185 | |||
186 | return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ | ||
187 | 'form' => $form->createView(), | ||
188 | 'currentRoute' => $currentRoute, | ||
189 | ]); | ||
190 | } | ||
149 | } | 191 | } |