Passed
Push — master ( e3ed0d...0fc967 )
by Anthony
08:34
created
Controller/AccessRightsController.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,120 +13,120 @@
 block discarded – undo
13 13
 
14 14
 class AccessRightsController extends AbstractController
15 15
 {
16
-    /**
17
-     * @Route("/access-rights-management/", name="ribsadmin_access_rights")
18
-     * @return Response
19
-     */
20
-    public function list(): Response
21
-    {
22
-        $em = $this->getDoctrine()->getManager();
23
-        $acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll();
24
-
25
-        return $this->render("@RibsAdmin/access-rights/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/show/{guid}", name="ribsadmin_access_rights_show")
33
-     * @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit")
34
-     * @param Request $request
35
-     * @param Globals $globals
36
-     * @param ModuleService $module
37
-     * @param string|null $guid
38
-     * @return Response
39
-     */
40
-    public function edit(Request $request, Globals $globals, ModuleService $module, string $guid = null): Response
41
-    {
42
-        $em = $this->getDoctrine()->getManager();
43
-        $list_rights_user = [];
44
-        $disabled_form = strpos($request->get("_route"), "_show") ? true : false;
45
-
46
-        if ($guid === null) {
47
-            $access_right = new AccessRight();
48
-        } else {
49
-            $access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]);
50
-            $list_rights_user = explode(",", $access_right->getAccessRights());
51
-        }
52
-
53
-        $admins = $em->getRepository("RibsAdminBundle:User")->findBy(["admin" => true, "archived" => false]);
54
-
55
-        $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\AccessRight", $access_right, ["disabled" => $disabled_form]);
56
-        $form->handleRequest($request);
57
-
58
-        if ($form->isSubmitted() && $form->isValid()) {
59
-            return $this->handleEditForm($request, $access_right);
60
-        }
61
-
62
-        return $this->render("@RibsAdmin/access-rights/edit.html.twig", [
63
-            "access_right" => $access_right,
64
-            "form" => $form->createView(),
65
-            "form_errors" => $form->getErrors(),
66
-            "list_rights_user" => $list_rights_user,
67
-            "admins" => $admins,
68
-            "ribs_admin_rights" => json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json")),
69
-            "modules" => $module->getAllInfosModules(),
70
-            "disabled_form" => $disabled_form
71
-        ]);
72
-    }
73
-
74
-    /**
75
-     * @Route("/access-rights-management/delete/{guid}", name="ribsadmin_access_rights_delete")
76
-     * @param string $guid
77
-     * @return RedirectResponse function that delete an access right list
78
-     */
79
-    public function delete(string $guid): RedirectResponse
80
-    {
81
-        $em = $this->getDoctrine()->getManager();
82
-        $list = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]);
83
-
84
-        if ($list) {
85
-            foreach ($list->getUsers() as $user) {
86
-                $user->setAccessRightList(null);
87
-            }
88
-
89
-            $em->remove($list);
90
-            $em->flush();
91
-
92
-            $this->addFlash("success-flash", "The right list was deleted");
93
-        } else {
94
-            $this->addFlash("error-flash", "The right list wasn't found");
95
-        }
96
-
97
-        return $this->redirectToRoute("ribsadmin_access_rights");
98
-    }
99
-
100
-    /**
101
-     * @param Request $request
102
-     * @param AccessRight $access_right
103
-     * @return RedirectResponse function that handle the form request
104
-     */
105
-    private function handleEditForm(Request $request, AccessRight $access_right): RedirectResponse
106
-    {
107
-        $em = $this->getDoctrine()->getManager();
108
-
109
-        if ($request->get("right") === null) {
110
-            $rights = "";
111
-        } else {
112
-            $rights = implode(",", $request->get("right"));
113
-        }
114
-
115
-        $access_right->setAccessRights($rights);
116
-        $em->persist($access_right);
117
-        $em->flush();
118
-
119
-        $em->getRepository("RibsAdminBundle:AccessRight")->deleteAllUsersList($access_right);
120
-        $admins = $request->get("admins");
121
-
122
-        if ($admins !== null) {
123
-            foreach ($admins as $admin) {
124
-                $em->getRepository("RibsAdminBundle:AccessRight")->setAccessRightListUser($access_right->getId(), $admin);
125
-            }
126
-        }
127
-
128
-        $this->addFlash("success-flash", "The right list was correctly edited");
129
-
130
-        return $this->redirectToRoute("ribsadmin_access_rights");
131
-    }
16
+				/**
17
+				 * @Route("/access-rights-management/", name="ribsadmin_access_rights")
18
+				 * @return Response
19
+				 */
20
+				public function list(): Response
21
+				{
22
+								$em = $this->getDoctrine()->getManager();
23
+								$acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll();
24
+
25
+								return $this->render("@RibsAdmin/access-rights/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/show/{guid}", name="ribsadmin_access_rights_show")
33
+				 * @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit")
34
+				 * @param Request $request
35
+				 * @param Globals $globals
36
+				 * @param ModuleService $module
37
+				 * @param string|null $guid
38
+				 * @return Response
39
+				 */
40
+				public function edit(Request $request, Globals $globals, ModuleService $module, string $guid = null): Response
41
+				{
42
+								$em = $this->getDoctrine()->getManager();
43
+								$list_rights_user = [];
44
+								$disabled_form = strpos($request->get("_route"), "_show") ? true : false;
45
+
46
+								if ($guid === null) {
47
+												$access_right = new AccessRight();
48
+								} else {
49
+												$access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]);
50
+												$list_rights_user = explode(",", $access_right->getAccessRights());
51
+								}
52
+
53
+								$admins = $em->getRepository("RibsAdminBundle:User")->findBy(["admin" => true, "archived" => false]);
54
+
55
+								$form = $this->createForm("PiouPiou\RibsAdminBundle\Form\AccessRight", $access_right, ["disabled" => $disabled_form]);
56
+								$form->handleRequest($request);
57
+
58
+								if ($form->isSubmitted() && $form->isValid()) {
59
+												return $this->handleEditForm($request, $access_right);
60
+								}
61
+
62
+								return $this->render("@RibsAdmin/access-rights/edit.html.twig", [
63
+												"access_right" => $access_right,
64
+												"form" => $form->createView(),
65
+												"form_errors" => $form->getErrors(),
66
+												"list_rights_user" => $list_rights_user,
67
+												"admins" => $admins,
68
+												"ribs_admin_rights" => json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json")),
69
+												"modules" => $module->getAllInfosModules(),
70
+												"disabled_form" => $disabled_form
71
+								]);
72
+				}
73
+
74
+				/**
75
+				 * @Route("/access-rights-management/delete/{guid}", name="ribsadmin_access_rights_delete")
76
+				 * @param string $guid
77
+				 * @return RedirectResponse function that delete an access right list
78
+				 */
79
+				public function delete(string $guid): RedirectResponse
80
+				{
81
+								$em = $this->getDoctrine()->getManager();
82
+								$list = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]);
83
+
84
+								if ($list) {
85
+												foreach ($list->getUsers() as $user) {
86
+																$user->setAccessRightList(null);
87
+												}
88
+
89
+												$em->remove($list);
90
+												$em->flush();
91
+
92
+												$this->addFlash("success-flash", "The right list was deleted");
93
+								} else {
94
+												$this->addFlash("error-flash", "The right list wasn't found");
95
+								}
96
+
97
+								return $this->redirectToRoute("ribsadmin_access_rights");
98
+				}
99
+
100
+				/**
101
+				 * @param Request $request
102
+				 * @param AccessRight $access_right
103
+				 * @return RedirectResponse function that handle the form request
104
+				 */
105
+				private function handleEditForm(Request $request, AccessRight $access_right): RedirectResponse
106
+				{
107
+								$em = $this->getDoctrine()->getManager();
108
+
109
+								if ($request->get("right") === null) {
110
+												$rights = "";
111
+								} else {
112
+												$rights = implode(",", $request->get("right"));
113
+								}
114
+
115
+								$access_right->setAccessRights($rights);
116
+								$em->persist($access_right);
117
+								$em->flush();
118
+
119
+								$em->getRepository("RibsAdminBundle:AccessRight")->deleteAllUsersList($access_right);
120
+								$admins = $request->get("admins");
121
+
122
+								if ($admins !== null) {
123
+												foreach ($admins as $admin) {
124
+																$em->getRepository("RibsAdminBundle:AccessRight")->setAccessRightListUser($access_right->getId(), $admin);
125
+												}
126
+								}
127
+
128
+								$this->addFlash("success-flash", "The right list was correctly edited");
129
+
130
+								return $this->redirectToRoute("ribsadmin_access_rights");
131
+				}
132 132
 }
Please login to merge, or discard this patch.
Controller/AccountsController.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -12,129 +12,129 @@
 block discarded – undo
12 12
 
13 13
 class AccountsController extends AbstractController
14 14
 {
15
-    /**
16
-     * @Route("/accounts/", name="ribsadmin_accounts")
17
-     * @return Response
18
-     */
19
-    public function list(): Response
20
-    {
21
-        $em = $this->getDoctrine()->getManager();
22
-        $current_account = $this->getUser()->getUser();
23
-
24
-        $users = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account);
25
-        $users_archived = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account, true);
26
-
27
-        return $this->render('@RibsAdmin/accounts/list.html.twig', [
28
-            "users" => $users,
29
-            "users_archived" => $users_archived
30
-        ]);
31
-    }
32
-
33
-    /**
34
-     * @Route("/accounts/create/", name="ribsadmin_accounts_create")
35
-     * @Route("/accounts/show/{guid}", name="ribsadmin_accounts_show")
36
-     * @Route("/accounts/edit/{guid}", name="ribsadmin_accounts_edit")
37
-     * @param Request $request
38
-     * @param string|null $guid
39
-     * @return Response
40
-     */
41
-    public function edit(Request $request, string $guid = null): Response
42
-    {
43
-        $em = $this->getDoctrine()->getManager();
44
-        $disabled_form = strpos($request->get("_route"), "_show") ? true : false;
45
-
46
-        if ($guid === null) {
47
-            $account = new Account();
48
-            $old_password = null;
49
-            $user = null;
50
-        } else {
51
-            $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]);
52
-            $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]);
53
-            $old_password = $account->getPassword();
54
-        }
55
-
56
-        $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account,  ["disabled" => $disabled_form]);
57
-
58
-        $form->handleRequest($request);
59
-
60
-        if ($form->isSubmitted() && $form->isValid()) {
61
-            /**
62
-             * @var Account
63
-             */
64
-            $data = $form->getData();
65
-
66
-            $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]);
67
-
68
-            if ($account_exist && $account_exist === $account) {
69
-                $account_exist = null;
70
-            }
71
-
72
-            if (!$account_exist) {
73
-                if ($guid === null) {
74
-                    $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData());
75
-                    $data->setPassword($temp_password);
76
-                } else if ($form->get("password")->getData()) {
77
-                    $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData());
78
-                    $data->setPassword($temp_password);
79
-                } else {
80
-                    $data->setPassword($old_password);
81
-                }
82
-
83
-                $em->persist($data);
84
-                $em->flush();
85
-
86
-                $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName();
87
-
88
-                if ($guid === null) {
89
-                    $this->addFlash("success-flash", "the account of " . $username . " was created");
90
-                } else {
91
-                    $this->addFlash("success-flash", "the account of " . $username . " was edited");
92
-                }
93
-
94
-                return $this->redirectToRoute("ribsadmin_accounts");
95
-            } else {
96
-                $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist");
97
-                return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]);
98
-            }
99
-        }
100
-
101
-        return $this->render("@RibsAdmin/accounts/edit.html.twig", [
102
-            "form" => $form->createView(),
103
-            "form_errors" => $form->getErrors(),
104
-            "user" => $user,
105
-            "disabled_form" => $disabled_form
106
-        ]);
107
-    }
108
-
109
-    /**
110
-     * method to disable or enable a user
111
-     * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive")
112
-     * @param string $guid
113
-     * @param bool $activate
114
-     * @return RedirectResponse
115
-     */
116
-    public function archive(string $guid, bool $activate = false): RedirectResponse
117
-    {
118
-        $em = $this->getDoctrine()->getManager();
119
-
120
-        $user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]);
121
-
122
-        if ($user) {
123
-            if ($activate === true) {
124
-                $user->setArchived(false);
125
-                $word = "activated";
126
-            } else {
127
-                $user->setArchived(true);
128
-                $word = "disabled";
129
-            }
130
-
131
-            $em->persist($user);
132
-            $em->flush();
133
-
134
-            $this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() .
135
-                " was " . $word . " sucessfuly");
136
-        }
137
-
138
-        return $this->redirectToRoute("ribsadmin_accounts");
139
-    }
15
+				/**
16
+				 * @Route("/accounts/", name="ribsadmin_accounts")
17
+				 * @return Response
18
+				 */
19
+				public function list(): Response
20
+				{
21
+								$em = $this->getDoctrine()->getManager();
22
+								$current_account = $this->getUser()->getUser();
23
+
24
+								$users = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account);
25
+								$users_archived = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account, true);
26
+
27
+								return $this->render('@RibsAdmin/accounts/list.html.twig', [
28
+												"users" => $users,
29
+												"users_archived" => $users_archived
30
+								]);
31
+				}
32
+
33
+				/**
34
+				 * @Route("/accounts/create/", name="ribsadmin_accounts_create")
35
+				 * @Route("/accounts/show/{guid}", name="ribsadmin_accounts_show")
36
+				 * @Route("/accounts/edit/{guid}", name="ribsadmin_accounts_edit")
37
+				 * @param Request $request
38
+				 * @param string|null $guid
39
+				 * @return Response
40
+				 */
41
+				public function edit(Request $request, string $guid = null): Response
42
+				{
43
+								$em = $this->getDoctrine()->getManager();
44
+								$disabled_form = strpos($request->get("_route"), "_show") ? true : false;
45
+
46
+								if ($guid === null) {
47
+												$account = new Account();
48
+												$old_password = null;
49
+												$user = null;
50
+								} else {
51
+												$user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]);
52
+												$account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]);
53
+												$old_password = $account->getPassword();
54
+								}
55
+
56
+								$form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account,  ["disabled" => $disabled_form]);
57
+
58
+								$form->handleRequest($request);
59
+
60
+								if ($form->isSubmitted() && $form->isValid()) {
61
+												/**
62
+												 * @var Account
63
+												 */
64
+												$data = $form->getData();
65
+
66
+												$account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]);
67
+
68
+												if ($account_exist && $account_exist === $account) {
69
+																$account_exist = null;
70
+												}
71
+
72
+												if (!$account_exist) {
73
+																if ($guid === null) {
74
+																				$temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData());
75
+																				$data->setPassword($temp_password);
76
+																} else if ($form->get("password")->getData()) {
77
+																				$temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData());
78
+																				$data->setPassword($temp_password);
79
+																} else {
80
+																				$data->setPassword($old_password);
81
+																}
82
+
83
+																$em->persist($data);
84
+																$em->flush();
85
+
86
+																$username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName();
87
+
88
+																if ($guid === null) {
89
+																				$this->addFlash("success-flash", "the account of " . $username . " was created");
90
+																} else {
91
+																				$this->addFlash("success-flash", "the account of " . $username . " was edited");
92
+																}
93
+
94
+																return $this->redirectToRoute("ribsadmin_accounts");
95
+												} else {
96
+																$this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist");
97
+																return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]);
98
+												}
99
+								}
100
+
101
+								return $this->render("@RibsAdmin/accounts/edit.html.twig", [
102
+												"form" => $form->createView(),
103
+												"form_errors" => $form->getErrors(),
104
+												"user" => $user,
105
+												"disabled_form" => $disabled_form
106
+								]);
107
+				}
108
+
109
+				/**
110
+				 * method to disable or enable a user
111
+				 * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive")
112
+				 * @param string $guid
113
+				 * @param bool $activate
114
+				 * @return RedirectResponse
115
+				 */
116
+				public function archive(string $guid, bool $activate = false): RedirectResponse
117
+				{
118
+								$em = $this->getDoctrine()->getManager();
119
+
120
+								$user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]);
121
+
122
+								if ($user) {
123
+												if ($activate === true) {
124
+																$user->setArchived(false);
125
+																$word = "activated";
126
+												} else {
127
+																$user->setArchived(true);
128
+																$word = "disabled";
129
+												}
130
+
131
+												$em->persist($user);
132
+												$em->flush();
133
+
134
+												$this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() .
135
+																" was " . $word . " sucessfuly");
136
+								}
137
+
138
+								return $this->redirectToRoute("ribsadmin_accounts");
139
+				}
140 140
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
             $old_password = $account->getPassword();
54 54
         }
55 55
 
56
-        $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account,  ["disabled" => $disabled_form]);
56
+        $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]);
57 57
 
58 58
         $form->handleRequest($request);
59 59
 
Please login to merge, or discard this patch.