|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ribs\RibsAdminBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Ribs\RibsAdminBundle\Entity\AccessRight; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
7
|
|
|
use Symfony\Component\Form\Form; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
|
|
13
|
|
|
class AccessRightsController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
//---------------------------------------------- VIEWS METHODS ---------------------------------------------------------// |
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/access-rights-management/", name="ribsadmin_access_rights") |
|
18
|
|
|
* @return Response |
|
19
|
|
|
*/ |
|
20
|
|
|
public function listAction(): Response |
|
21
|
|
|
{ |
|
22
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
23
|
|
|
$acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll(); |
|
24
|
|
|
|
|
25
|
|
|
return $this->render("@RibsAdmin/access-rights/list-all-list.html.twig", [ |
|
26
|
|
|
"access_right" => $acces_right |
|
27
|
|
|
]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @Route("/access-rights-management/create/", name="ribsadmin_access_rights_create") |
|
32
|
|
|
* @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit") |
|
33
|
|
|
* @param Request $request |
|
34
|
|
|
* @param string|null $guid |
|
35
|
|
|
* @return Response |
|
36
|
|
|
*/ |
|
37
|
|
|
public function editAction(Request $request, string $guid = null): Response |
|
38
|
|
|
{ |
|
39
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
40
|
|
|
$list_rights_user = []; |
|
41
|
|
|
|
|
42
|
|
|
if ($guid === null) { |
|
43
|
|
|
$access_right = new AccessRight(); |
|
44
|
|
|
} else { |
|
45
|
|
|
$access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
46
|
|
|
$list_rights_user = explode(",", $access_right->getAccessRights()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$form = $this->createForm("Ribs\RibsAdminBundle\Form\AccessRight", $access_right); |
|
50
|
|
|
$form->handleRequest($request); |
|
51
|
|
|
|
|
52
|
|
|
if ($form->isValid() && $form->isSubmitted()) { |
|
53
|
|
|
return $this->handleEditForm($request, $form, $access_right); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->render("@RibsAdmin/access-rights/edit-list.html.twig", [ |
|
57
|
|
|
"access_right" => $access_right, |
|
58
|
|
|
"form" => $form->createView(), |
|
59
|
|
|
"list_rights_user" => $list_rights_user, |
|
60
|
|
|
"ribs_admin_rights" => json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json")) |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
//---------------------------------------------- END VIEWS METHODS ---------------------------------------------------------// |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param Request $request |
|
67
|
|
|
* @param Form $form |
|
68
|
|
|
* @param AccessRight $access_right |
|
69
|
|
|
* @return RedirectResponse function that handle the form request |
|
70
|
|
|
*/ |
|
71
|
|
|
private function handleEditForm(Request $request, Form $form, AccessRight $access_right): RedirectResponse |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
74
|
|
|
$rights = implode(",", $request->get("right")); |
|
75
|
|
|
|
|
76
|
|
|
$access_right->setAccessRights($rights); |
|
77
|
|
|
|
|
78
|
|
|
$em->persist($access_right); |
|
79
|
|
|
$em->flush(); |
|
80
|
|
|
|
|
81
|
|
|
$this->addFlash("success-flash", "The right list was correctly edited"); |
|
82
|
|
|
|
|
83
|
|
|
return $this->redirectToRoute("ribsadmin_access_rights"); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @Route("/access-rights-management/delete/{guid}", name="ribsadmin_access_rights_delete") |
|
88
|
|
|
* @param string $guid |
|
89
|
|
|
* @return RedirectResponse function that delete an access right list |
|
90
|
|
|
*/ |
|
91
|
|
|
public function deleteList(string $guid): RedirectResponse |
|
92
|
|
|
{ |
|
93
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
94
|
|
|
$list = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
95
|
|
|
|
|
96
|
|
|
if ($list) { |
|
97
|
|
|
$em->remove($list); |
|
98
|
|
|
$em->flush(); |
|
99
|
|
|
|
|
100
|
|
|
$this->addFlash("success-flash", "The right list was deleted"); |
|
101
|
|
|
} else { |
|
102
|
|
|
$this->addFlash("error-flash", "The right list wasn't found"); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $this->redirectToRoute("ribsadmin_access_rights"); |
|
106
|
|
|
} |
|
107
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.