X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FUserBundle%2FController%2FManageController.php;h=f3de656f979d1b16891a2c9bea394bf8439a1272;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=3ea773eeb26f4d7ff688fe8c3eefa9a242538867;hpb=d01dc5a81e7fde37d98fe6b10b9329b53add5b6a;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 3ea773ee..f3de656f 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -7,10 +7,10 @@ use FOS\UserBundle\FOSUserEvents; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Pagerfanta\Pagerfanta; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Form\SearchUserType; @@ -19,38 +19,6 @@ use Wallabag\UserBundle\Form\SearchUserType; */ class ManageController extends Controller { - /** - * Lists all User entities. - * - * @Route("/list/{page}", name="user_index") - * @Method("GET") - * - * @param int $page - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function indexAction($page = 1) - { - $em = $this->getDoctrine()->getManager(); - - $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); - $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); - $pagerFanta = new Pagerfanta($pagerAdapter); - $pagerFanta->setMaxPerPage(50); - - try { - $pagerFanta->setCurrentPage($page); - } catch (OutOfRangeCurrentPageException $e) { - if ($page > 1) { - return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); - } - } - - return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $pagerFanta, - )); - } - /** * Creates a new User entity. * @@ -65,9 +33,7 @@ class ManageController extends Controller // enable created user by default $user->setEnabled(true); - $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [ - 'validation_groups' => ['Profile'], - ]); + $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -82,13 +48,13 @@ class ManageController extends Controller $this->get('translator')->trans('flashes.user.notice.added', ['%username%' => $user->getUsername()]) ); - return $this->redirectToRoute('user_edit', array('id' => $user->getId())); + return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); } - return $this->render('WallabagUserBundle:Manage:new.html.twig', array( + return $this->render('WallabagUserBundle:Manage:new.html.twig', [ 'user' => $user, 'form' => $form->createView(), - )); + ]); } /** @@ -113,15 +79,15 @@ class ManageController extends Controller $this->get('translator')->trans('flashes.user.notice.updated', ['%username%' => $user->getUsername()]) ); - return $this->redirectToRoute('user_edit', array('id' => $user->getId())); + return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); } - return $this->render('WallabagUserBundle:Manage:edit.html.twig', array( + return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ 'user' => $user, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), 'twofactor_auth' => $this->getParameter('twofactor_auth'), - )); + ]); } /** @@ -149,72 +115,64 @@ class ManageController extends Controller return $this->redirectToRoute('user_index'); } - /** - * Creates a form to delete a User entity. - * - * @param User $user The User entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createDeleteForm(User $user) - { - return $this->createFormBuilder() - ->setAction($this->generateUrl('user_delete', array('id' => $user->getId()))) - ->setMethod('DELETE') - ->getForm() - ; - } - /** * @param Request $request * @param int $page * - * @Route("/search/{page}", name="user-search", defaults={"page" = 1}) + * @Route("/list/{page}", name="user_index", 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) + public function searchFormAction(Request $request, $page = 1) { - // 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'); - } + $em = $this->getDoctrine()->getManager(); + $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); $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'] : ''); $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); + } - $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); - $pagerFanta = new Pagerfanta($pagerAdapter); - $pagerFanta->setMaxPerPage(50); + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + $pagerFanta = new Pagerfanta($pagerAdapter); + $pagerFanta->setMaxPerPage(50); - try { - $pagerFanta->setCurrentPage($page); - } catch (OutOfRangeCurrentPageException $e) { - if ($page > 1) { - return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); - } + try { + $pagerFanta->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); } - - return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $pagerFanta, - )); } - return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ - 'form' => $form->createView(), - 'currentRoute' => $currentRoute, + return $this->render('WallabagUserBundle:Manage:index.html.twig', [ + 'searchForm' => $form->createView(), + 'users' => $pagerFanta, ]); } + + /** + * Creates a form to delete a User entity. + * + * @param User $user The User entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(User $user) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('user_delete', ['id' => $user->getId()])) + ->setMethod('DELETE') + ->getForm() + ; + } }