diff options
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r-- | src/Wallabag/UserBundle/Controller/ManageController.php | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 92ee2b41..f3de656f 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php | |||
@@ -4,12 +4,15 @@ namespace Wallabag\UserBundle\Controller; | |||
4 | 4 | ||
5 | use FOS\UserBundle\Event\UserEvent; | 5 | use FOS\UserBundle\Event\UserEvent; |
6 | use FOS\UserBundle\FOSUserEvents; | 6 | use FOS\UserBundle\FOSUserEvents; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
9 | use Pagerfanta\Pagerfanta; | ||
9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | 10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 11 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
12 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
13 | use Symfony\Component\HttpFoundation\Request; | ||
11 | use Wallabag\UserBundle\Entity\User; | 14 | use Wallabag\UserBundle\Entity\User; |
12 | use Wallabag\CoreBundle\Entity\Config; | 15 | use Wallabag\UserBundle\Form\SearchUserType; |
13 | 16 | ||
14 | /** | 17 | /** |
15 | * User controller. | 18 | * User controller. |
@@ -17,23 +20,6 @@ use Wallabag\CoreBundle\Entity\Config; | |||
17 | class ManageController extends Controller | 20 | class ManageController extends Controller |
18 | { | 21 | { |
19 | /** | 22 | /** |
20 | * Lists all User entities. | ||
21 | * | ||
22 | * @Route("/", name="user_index") | ||
23 | * @Method("GET") | ||
24 | */ | ||
25 | public function indexAction() | ||
26 | { | ||
27 | $em = $this->getDoctrine()->getManager(); | ||
28 | |||
29 | $users = $em->getRepository('WallabagUserBundle:User')->findAll(); | ||
30 | |||
31 | return $this->render('WallabagUserBundle:Manage:index.html.twig', array( | ||
32 | 'users' => $users, | ||
33 | )); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * Creates a new User entity. | 23 | * Creates a new User entity. |
38 | * | 24 | * |
39 | * @Route("/new", name="user_new") | 25 | * @Route("/new", name="user_new") |
@@ -47,9 +33,7 @@ class ManageController extends Controller | |||
47 | // enable created user by default | 33 | // enable created user by default |
48 | $user->setEnabled(true); | 34 | $user->setEnabled(true); |
49 | 35 | ||
50 | $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [ | 36 | $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user); |
51 | 'validation_groups' => ['Profile'], | ||
52 | ]); | ||
53 | $form->handleRequest($request); | 37 | $form->handleRequest($request); |
54 | 38 | ||
55 | if ($form->isSubmitted() && $form->isValid()) { | 39 | if ($form->isSubmitted() && $form->isValid()) { |
@@ -64,13 +48,13 @@ class ManageController extends Controller | |||
64 | $this->get('translator')->trans('flashes.user.notice.added', ['%username%' => $user->getUsername()]) | 48 | $this->get('translator')->trans('flashes.user.notice.added', ['%username%' => $user->getUsername()]) |
65 | ); | 49 | ); |
66 | 50 | ||
67 | return $this->redirectToRoute('user_edit', array('id' => $user->getId())); | 51 | return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); |
68 | } | 52 | } |
69 | 53 | ||
70 | return $this->render('WallabagUserBundle:Manage:new.html.twig', array( | 54 | return $this->render('WallabagUserBundle:Manage:new.html.twig', [ |
71 | 'user' => $user, | 55 | 'user' => $user, |
72 | 'form' => $form->createView(), | 56 | 'form' => $form->createView(), |
73 | )); | 57 | ]); |
74 | } | 58 | } |
75 | 59 | ||
76 | /** | 60 | /** |
@@ -95,15 +79,15 @@ class ManageController extends Controller | |||
95 | $this->get('translator')->trans('flashes.user.notice.updated', ['%username%' => $user->getUsername()]) | 79 | $this->get('translator')->trans('flashes.user.notice.updated', ['%username%' => $user->getUsername()]) |
96 | ); | 80 | ); |
97 | 81 | ||
98 | return $this->redirectToRoute('user_edit', array('id' => $user->getId())); | 82 | return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); |
99 | } | 83 | } |
100 | 84 | ||
101 | return $this->render('WallabagUserBundle:Manage:edit.html.twig', array( | 85 | return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ |
102 | 'user' => $user, | 86 | 'user' => $user, |
103 | 'edit_form' => $editForm->createView(), | 87 | 'edit_form' => $editForm->createView(), |
104 | 'delete_form' => $deleteForm->createView(), | 88 | 'delete_form' => $deleteForm->createView(), |
105 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), | 89 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), |
106 | )); | 90 | ]); |
107 | } | 91 | } |
108 | 92 | ||
109 | /** | 93 | /** |
@@ -132,6 +116,51 @@ class ManageController extends Controller | |||
132 | } | 116 | } |
133 | 117 | ||
134 | /** | 118 | /** |
119 | * @param Request $request | ||
120 | * @param int $page | ||
121 | * | ||
122 | * @Route("/list/{page}", name="user_index", defaults={"page" = 1}) | ||
123 | * | ||
124 | * Default parameter for page is hardcoded (in duplication of the defaults from the Route) | ||
125 | * because this controller is also called inside the layout template without any page as argument | ||
126 | * | ||
127 | * @return \Symfony\Component\HttpFoundation\Response | ||
128 | */ | ||
129 | public function searchFormAction(Request $request, $page = 1) | ||
130 | { | ||
131 | $em = $this->getDoctrine()->getManager(); | ||
132 | $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); | ||
133 | |||
134 | $form = $this->createForm(SearchUserType::class); | ||
135 | $form->handleRequest($request); | ||
136 | |||
137 | if ($form->isSubmitted() && $form->isValid()) { | ||
138 | $this->get('logger')->info('searching users'); | ||
139 | |||
140 | $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); | ||
141 | |||
142 | $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); | ||
143 | } | ||
144 | |||
145 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); | ||
146 | $pagerFanta = new Pagerfanta($pagerAdapter); | ||
147 | $pagerFanta->setMaxPerPage(50); | ||
148 | |||
149 | try { | ||
150 | $pagerFanta->setCurrentPage($page); | ||
151 | } catch (OutOfRangeCurrentPageException $e) { | ||
152 | if ($page > 1) { | ||
153 | return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | return $this->render('WallabagUserBundle:Manage:index.html.twig', [ | ||
158 | 'searchForm' => $form->createView(), | ||
159 | 'users' => $pagerFanta, | ||
160 | ]); | ||
161 | } | ||
162 | |||
163 | /** | ||
135 | * Creates a form to delete a User entity. | 164 | * Creates a form to delete a User entity. |
136 | * | 165 | * |
137 | * @param User $user The User entity | 166 | * @param User $user The User entity |
@@ -141,7 +170,7 @@ class ManageController extends Controller | |||
141 | private function createDeleteForm(User $user) | 170 | private function createDeleteForm(User $user) |
142 | { | 171 | { |
143 | return $this->createFormBuilder() | 172 | return $this->createFormBuilder() |
144 | ->setAction($this->generateUrl('user_delete', array('id' => $user->getId()))) | 173 | ->setAction($this->generateUrl('user_delete', ['id' => $user->getId()])) |
145 | ->setMethod('DELETE') | 174 | ->setMethod('DELETE') |
146 | ->getForm() | 175 | ->getForm() |
147 | ; | 176 | ; |