|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @Security("has_role('ROLE_MANAGER')") |
|
15
|
|
|
* @Route("/admin") |
|
16
|
|
|
*/ |
|
17
|
|
|
class UserController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @Route("/users", name="admin_users") |
|
21
|
|
|
* @Method("GET") |
|
22
|
|
|
*/ |
|
23
|
1 |
View Code Duplication |
public function usersAction(Request $request) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
1 |
|
$users = $this->getDoctrine()->getRepository('AppBundle:User')->findAll(); |
|
26
|
1 |
|
$paginator = $this->get('knp_paginator'); |
|
27
|
1 |
|
$pagination = $paginator->paginate( |
|
28
|
1 |
|
$users, |
|
29
|
1 |
|
$request->query->getInt('page', 1), |
|
30
|
|
|
10 |
|
31
|
1 |
|
); |
|
32
|
1 |
|
return $this->render('@App/admin/user/users.html.twig', array('pagination' => $pagination)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @Route("/users/managers", name="admin_users_managers") |
|
37
|
|
|
* @Method("GET") |
|
38
|
|
|
*/ |
|
39
|
|
View Code Duplication |
public function usersManagersAction(Request $request) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$users = $this->getDoctrine()->getRepository('AppBundle:User')->findByRole('ROLE_MANAGER'); |
|
42
|
|
|
$paginator = $this->get('knp_paginator'); |
|
43
|
|
|
$pagination = $paginator->paginate( |
|
44
|
|
|
$users, |
|
45
|
|
|
$request->query->getInt('page', 1), |
|
46
|
|
|
10 |
|
47
|
|
|
); |
|
48
|
|
|
return $this->render('@App/admin/user/users.html.twig', array('pagination' => $pagination)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @Route("/estates/{slug}", name="admin_estates_manager") |
|
53
|
|
|
*/ |
|
54
|
1 |
View Code Duplication |
public function showEstatesManagerAction(Request $request, $slug) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
1 |
|
$estates = $this->getDoctrine()->getManager()->getRepository('AppBundle:Estate') |
|
57
|
1 |
|
->getEstatesOfManager($slug); |
|
58
|
1 |
|
$paginator = $this->get('knp_paginator'); |
|
59
|
1 |
|
$pagination = $paginator->paginate( |
|
60
|
1 |
|
$estates, |
|
61
|
1 |
|
$request->query->getInt('page', 1), |
|
62
|
|
|
10 |
|
63
|
1 |
|
); |
|
64
|
1 |
|
return $this->render('@App/admin/user/estates_manager.html.twig', array('pagination' => $pagination)); } |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @Route("/users/lock_user/{username}", name="lock_user") |
|
68
|
|
|
* @Method("GET") |
|
69
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
70
|
|
|
*/ |
|
71
|
1 |
View Code Duplication |
public function lockUserAction(Request $request, $username) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
1 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
74
|
1 |
|
$user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('username' => $username)); |
|
75
|
1 |
|
$user->setLocked(true); |
|
76
|
1 |
|
$entityManager->flush(); |
|
77
|
1 |
|
return $this->redirectToRoute('admin_users'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @Route("/users/unlock_user/{username}", name="unlock_user") |
|
82
|
|
|
* @Method("GET") |
|
83
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
84
|
|
|
*/ |
|
85
|
1 |
View Code Duplication |
public function unlockUserAction(Request $request, $username) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
1 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
88
|
1 |
|
$user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('username' => $username)); |
|
89
|
1 |
|
$user->setLocked(false); |
|
90
|
1 |
|
$entityManager->flush(); |
|
91
|
1 |
|
return $this->redirectToRoute('admin_users'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @Route("/users/do_manager/{username}", name="do_manager") |
|
96
|
|
|
* @Method("GET") |
|
97
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
98
|
|
|
*/ |
|
99
|
1 |
View Code Duplication |
public function doManagerAction(Request $request, $username) |
|
|
|
|
|
|
100
|
|
|
{ |
|
101
|
1 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
102
|
1 |
|
$user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('username' => $username)); |
|
103
|
1 |
|
$user->addRole('ROLE_MANAGER'); |
|
104
|
1 |
|
$entityManager->flush(); |
|
105
|
1 |
|
return $this->redirectToRoute('admin_users'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @Route("/users/do_user/{username}", name="do_user") |
|
110
|
|
|
* @Method("GET") |
|
111
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
112
|
|
|
*/ |
|
113
|
2 |
|
public function doUserAction(Request $request, $username) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
116
|
1 |
|
$user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('username' => $username)); |
|
117
|
1 |
|
if ($user->hasRole('ROLE_MANAGER')) { |
|
118
|
2 |
|
$user->removeRole('ROLE_MANAGER'); |
|
119
|
1 |
|
$entityManager->flush(); |
|
120
|
1 |
|
} |
|
121
|
1 |
|
return $this->redirectToRoute('admin_users'); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.