Passed
Push — master ( b24d1f...919982 )
by Anthony
03:12
created
Controller/UploaderController.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,125 +14,125 @@
 block discarded – undo
14 14
 
15 15
 class UploaderController extends AbstractController
16 16
 {
17
-    /**
18
-     * @Route("/upload", name="ribsadmin_upload")
19
-     * @param Request $request
20
-     * @param ParameterBagInterface $parameter
21
-     * @return JsonResponse
22
-     * @throws Exception
23
-     */
24
-    public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse
25
-    {
26
-        $success = false;
27
-        $new_filename = null;
28
-        $file = null;
29
-        $upload_dir = null;
30
-
31
-        if ($request->files && $request->files->has("file")) {
32
-            $upload_dir = $parameter->get("ribs_admin.upload_dir");
33
-            /** @var UploadedFile $file */
34
-            $file = $request->files->get("file");
35
-            $date = new \DateTime();
36
-            $extension = explode(".", $file->getFilename());
37
-            $new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension);
38
-
39
-            if (!is_dir($upload_dir)) {
40
-                $this->createRecursiveDirFromRoot($upload_dir);
41
-            }
42
-
43
-            if ($file->move($upload_dir, $new_filename)) {
44
-                $success = true;
45
-            }
46
-        }
47
-
48
-        return new JsonResponse([
49
-            "original_filename" => $file ? $file->getClientOriginalName() : null,
50
-            "new_filename" => $new_filename,
51
-            "file_path" => $upload_dir . "/" . $new_filename,
52
-            "success" => $success
53
-        ]);
54
-    }
55
-
56
-    /**
57
-     * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file")
58
-     * @param Request $request
59
-     * @param ParameterBagInterface $parameter
60
-     * @return JsonResponse
61
-     */
62
-    public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
63
-    {
64
-        $success = false;
65
-        if ($request->get("file_path") && $request->get("file_name")) {
66
-            $fs = new Filesystem();
67
-            $upload_dir = $parameter->get("ribs_admin.upload_dir");
68
-
69
-            if (is_file($request->get("file_path"))) {
70
-                $fs->remove($request->get("file_path"));
71
-            } elseif (is_file($upload_dir . "/" . $request->get("file_name"))) {
72
-                $fs->remove($upload_dir . "/" . $request->get("file_name"));
73
-            }
74
-            $success = true;
75
-        }
76
-
77
-        return new JsonResponse([
78
-            "success" => $success
79
-        ]);
80
-    }
81
-
82
-    /**
83
-     * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file")
84
-     * @param Request $request
85
-     * @param ParameterBagInterface $parameter
86
-     * @return JsonResponse
87
-     */
88
-    public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
89
-    {
90
-        $success = true;
91
-        $fs = new Filesystem();
92
-        $finder = new Finder();
93
-        $finder->files()->in($parameter->get("ribs_admin.upload_dir"));
94
-        $files = [];
95
-        $index = 0;
96
-
97
-        foreach ($finder as $file) {
98
-            $files[] = [
99
-                "file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(),
100
-                "filename" => $file->getFilename(),
101
-                "index" => $index
102
-            ];
103
-
104
-            $index++;
105
-        }
106
-
107
-        return new JsonResponse([
108
-            "success" => $success,
109
-            "files" => $files
110
-        ]);
111
-    }
112
-
113
-    /**
114
-     * method that create a tree of folders on each slash
115
-     * @param $path
116
-     * @return string
117
-     */
118
-    private function createRecursiveDirFromRoot($path)
119
-    {
120
-        $fs = new Filesystem();
121
-        $new_path = $path;
122
-        $folders = explode("/", $path);
123
-
124
-        foreach ($folders as $index => $folder) {
125
-            $new_path .= $folder;
126
-
127
-            if (!$fs->exists($new_path)) {
128
-                $fs->mkdir($new_path);
129
-            }
130
-
131
-            if ($index + 1 < count($folders)) {
132
-                $new_path .= "/";
133
-            }
134
-        }
135
-
136
-        return $new_path;
137
-    }
17
+				/**
18
+				 * @Route("/upload", name="ribsadmin_upload")
19
+				 * @param Request $request
20
+				 * @param ParameterBagInterface $parameter
21
+				 * @return JsonResponse
22
+				 * @throws Exception
23
+				 */
24
+				public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse
25
+				{
26
+								$success = false;
27
+								$new_filename = null;
28
+								$file = null;
29
+								$upload_dir = null;
30
+
31
+								if ($request->files && $request->files->has("file")) {
32
+												$upload_dir = $parameter->get("ribs_admin.upload_dir");
33
+												/** @var UploadedFile $file */
34
+												$file = $request->files->get("file");
35
+												$date = new \DateTime();
36
+												$extension = explode(".", $file->getFilename());
37
+												$new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension);
38
+
39
+												if (!is_dir($upload_dir)) {
40
+																$this->createRecursiveDirFromRoot($upload_dir);
41
+												}
42
+
43
+												if ($file->move($upload_dir, $new_filename)) {
44
+																$success = true;
45
+												}
46
+								}
47
+
48
+								return new JsonResponse([
49
+												"original_filename" => $file ? $file->getClientOriginalName() : null,
50
+												"new_filename" => $new_filename,
51
+												"file_path" => $upload_dir . "/" . $new_filename,
52
+												"success" => $success
53
+								]);
54
+				}
55
+
56
+				/**
57
+				 * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file")
58
+				 * @param Request $request
59
+				 * @param ParameterBagInterface $parameter
60
+				 * @return JsonResponse
61
+				 */
62
+				public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
63
+				{
64
+								$success = false;
65
+								if ($request->get("file_path") && $request->get("file_name")) {
66
+												$fs = new Filesystem();
67
+												$upload_dir = $parameter->get("ribs_admin.upload_dir");
68
+
69
+												if (is_file($request->get("file_path"))) {
70
+																$fs->remove($request->get("file_path"));
71
+												} elseif (is_file($upload_dir . "/" . $request->get("file_name"))) {
72
+																$fs->remove($upload_dir . "/" . $request->get("file_name"));
73
+												}
74
+												$success = true;
75
+								}
76
+
77
+								return new JsonResponse([
78
+												"success" => $success
79
+								]);
80
+				}
81
+
82
+				/**
83
+				 * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file")
84
+				 * @param Request $request
85
+				 * @param ParameterBagInterface $parameter
86
+				 * @return JsonResponse
87
+				 */
88
+				public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
89
+				{
90
+								$success = true;
91
+								$fs = new Filesystem();
92
+								$finder = new Finder();
93
+								$finder->files()->in($parameter->get("ribs_admin.upload_dir"));
94
+								$files = [];
95
+								$index = 0;
96
+
97
+								foreach ($finder as $file) {
98
+												$files[] = [
99
+																"file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(),
100
+																"filename" => $file->getFilename(),
101
+																"index" => $index
102
+												];
103
+
104
+												$index++;
105
+								}
106
+
107
+								return new JsonResponse([
108
+												"success" => $success,
109
+												"files" => $files
110
+								]);
111
+				}
112
+
113
+				/**
114
+				 * method that create a tree of folders on each slash
115
+				 * @param $path
116
+				 * @return string
117
+				 */
118
+				private function createRecursiveDirFromRoot($path)
119
+				{
120
+								$fs = new Filesystem();
121
+								$new_path = $path;
122
+								$folders = explode("/", $path);
123
+
124
+								foreach ($folders as $index => $folder) {
125
+												$new_path .= $folder;
126
+
127
+												if (!$fs->exists($new_path)) {
128
+																$fs->mkdir($new_path);
129
+												}
130
+
131
+												if ($index + 1 < count($folders)) {
132
+																$new_path .= "/";
133
+												}
134
+								}
135
+
136
+								return $new_path;
137
+				}
138 138
 }
Please login to merge, or discard this patch.
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.
Repository/NavigationRepository.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,38 +7,38 @@
 block discarded – undo
7 7
 
8 8
 class NavigationRepository extends EntityRepository
9 9
 {
10
-    /**
11
-     * function that return all navigation links of pages and modules
12
-     * @return array
13
-     * @throws DBALException
14
-     */
15
-    public function findAllNavigation(): array
16
-    {
17
-        $query = $this->getEntityManager()->getConnection()->prepare("SELECT p.url, p.title, p.title_tag FROM navigation n
10
+				/**
11
+				 * function that return all navigation links of pages and modules
12
+				 * @return array
13
+				 * @throws DBALException
14
+				 */
15
+				public function findAllNavigation(): array
16
+				{
17
+								$query = $this->getEntityManager()->getConnection()->prepare("SELECT p.url, p.title, p.title_tag FROM navigation n
18 18
 			LEFT JOIN page p ON n.id_page = p.id AND p.displayed = 1
19 19
 			LEFT JOIN module m ON n.id_module = m.id AND m.displayed = 1
20 20
 		  	ORDER BY n.order ASC
21 21
  		");
22 22
 
23
-        $query->execute();
23
+								$query->execute();
24 24
 
25
-        return $query->fetchAll(\PDO::FETCH_ASSOC);
26
-    }
25
+								return $query->fetchAll(\PDO::FETCH_ASSOC);
26
+				}
27 27
 
28
-    /**
29
-     * function that return all navigation links of pages
30
-     * @return array
31
-     * @throws DBALException
32
-     */
33
-    public function findAllNavigationPage(): array
34
-    {
35
-        $query = $this->getEntityManager()->getConnection()->prepare("SELECT p.id, p.url, p.title, p.title_tag FROM navigation n
28
+				/**
29
+				 * function that return all navigation links of pages
30
+				 * @return array
31
+				 * @throws DBALException
32
+				 */
33
+				public function findAllNavigationPage(): array
34
+				{
35
+								$query = $this->getEntityManager()->getConnection()->prepare("SELECT p.id, p.url, p.title, p.title_tag FROM navigation n
36 36
 			INNER JOIN page p ON n.id_page = p.id AND p.displayed = 1
37 37
 		  	ORDER BY n.order ASC
38 38
  		");
39 39
 
40
-        $query->execute();
40
+								$query->execute();
41 41
 
42
-        return $query->fetchAll(\PDO::FETCH_ASSOC);
43
-    }
42
+								return $query->fetchAll(\PDO::FETCH_ASSOC);
43
+				}
44 44
 }
Please login to merge, or discard this patch.
Controller/PageController.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -8,28 +8,28 @@
 block discarded – undo
8 8
 
9 9
 class PageController extends AbstractController
10 10
 {
11
-    /**
12
-     * @Route("/contents", name="ribsadmin_contents")
13
-     * @return Response
14
-     */
15
-    public function index(): Response
16
-    {
17
-        $navigation = $this->getDoctrine()->getManager()->getRepository("RibsAdminBundle:Navigation")->findAllNavigationPage();
11
+				/**
12
+				 * @Route("/contents", name="ribsadmin_contents")
13
+				 * @return Response
14
+				 */
15
+				public function index(): Response
16
+				{
17
+								$navigation = $this->getDoctrine()->getManager()->getRepository("RibsAdminBundle:Navigation")->findAllNavigationPage();
18 18
 
19
-        return $this->render('@RibsAdmin/page/index.html.twig', ["navigation" => $navigation]);
20
-    }
19
+								return $this->render('@RibsAdmin/page/index.html.twig', ["navigation" => $navigation]);
20
+				}
21 21
 
22
-    /**
23
-     * @Route("/contents/edit-page/{page_id}", name="ribsadmin_contents_edit_page")
24
-     * @param int $page_id
25
-     * @return Response
26
-     */
27
-    public function editPage(int $page_id): Response
28
-    {
29
-        $em = $this->getDoctrine()->getManager();
30
-        $navigation = $em->getRepository("RibsAdminBundle:Navigation")->findAllNavigationPage();
31
-        $page = $em->getRepository("RibsAdminBundle:Page")->find($page_id);
22
+				/**
23
+				 * @Route("/contents/edit-page/{page_id}", name="ribsadmin_contents_edit_page")
24
+				 * @param int $page_id
25
+				 * @return Response
26
+				 */
27
+				public function editPage(int $page_id): Response
28
+				{
29
+								$em = $this->getDoctrine()->getManager();
30
+								$navigation = $em->getRepository("RibsAdminBundle:Navigation")->findAllNavigationPage();
31
+								$page = $em->getRepository("RibsAdminBundle:Page")->find($page_id);
32 32
 
33
-        return $this->render('@RibsAdmin/page/edit-page.html.twig', ["navigation" => $navigation, "page" => $page]);
34
-    }
33
+								return $this->render('@RibsAdmin/page/edit-page.html.twig', ["navigation" => $navigation, "page" => $page]);
34
+				}
35 35
 }
Please login to merge, or discard this patch.