aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php72
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig14
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig15
3 files changed, 29 insertions, 72 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}
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
index 7a76f157..15002632 100644
--- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
@@ -16,7 +16,19 @@
16 </div> 16 </div>
17 <div class="col s6"> 17 <div class="col s6">
18 <div class="input-field"> 18 <div class="input-field">
19 {{ render(controller("WallabagUserBundle:Manage:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} 19 <form name="search_users" method="GET" action="{{ path('user_index')}}">
20 {% if form_errors(searchForm) %}
21 <span class="black-text">{{ form_errors(searchForm) }}</span>
22 {% endif %}
23
24 {% if form_errors(searchForm.term) %}
25 <span class="black-text">{{ form_errors(searchForm.term) }}</span>
26 {% endif %}
27
28 {{ form_widget(searchForm.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }}
29
30 {{ form_rest(searchForm) }}
31 </form>
20 </div> 32 </div>
21 </div> 33 </div>
22 34
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig
deleted file mode 100644
index 1d4df204..00000000
--- a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig
+++ /dev/null
@@ -1,15 +0,0 @@
1<form name="search_users" method="GET" action="{{ path('user-search')}}">
2 {% if form_errors(form) %}
3 <span class="black-text">{{ form_errors(form) }}</span>
4 {% endif %}
5
6 {% if form_errors(form.term) %}
7 <span class="black-text">{{ form_errors(form.term) }}</span>
8 {% endif %}
9
10 <i class="material-icons prefix">search</i>
11 {{ form_widget(form.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }}
12 <label for="search_user_term" class="active">{{ 'user.search.label' | trans }}</label>
13
14 {{ form_rest(form) }}
15</form>