aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Controller/ManageController.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-10-23 11:09:17 +0200
committerGitHub <noreply@github.com>2017-10-23 11:09:17 +0200
commit1953a872932a63792293b4aec087880265ba89f7 (patch)
treefd16599e737fcdaf193c933ef3ec4a4ee248b117 /src/Wallabag/UserBundle/Controller/ManageController.php
parentd83d25dadec2c38460a32d96f5d2903426fec9d3 (diff)
parent702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff)
downloadwallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz
wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst
wallabag-1953a872932a63792293b4aec087880265ba89f7.zip
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'src/Wallabag/UserBundle/Controller/ManageController.php')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php89
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
5use FOS\UserBundle\Event\UserEvent; 5use FOS\UserBundle\Event\UserEvent;
6use FOS\UserBundle\FOSUserEvents; 6use FOS\UserBundle\FOSUserEvents;
7use Symfony\Component\HttpFoundation\Request; 7use Pagerfanta\Adapter\DoctrineORMAdapter;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Pagerfanta\Exception\OutOfRangeCurrentPageException;
9use Pagerfanta\Pagerfanta;
9use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 11use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13use Symfony\Component\HttpFoundation\Request;
11use Wallabag\UserBundle\Entity\User; 14use Wallabag\UserBundle\Entity\User;
12use Wallabag\CoreBundle\Entity\Config; 15use Wallabag\UserBundle\Form\SearchUserType;
13 16
14/** 17/**
15 * User controller. 18 * User controller.
@@ -17,23 +20,6 @@ use Wallabag\CoreBundle\Entity\Config;
17class ManageController extends Controller 20class 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 ;