@@ -13,69 +13,69 @@ |
||
13 | 13 | |
14 | 14 | class ApiController extends AbstractController |
15 | 15 | { |
16 | - /** |
|
17 | - * this method is user to authenticate a user by an api request |
|
18 | - * if success it return a token api that expire in 20 minutes |
|
19 | - * @Route("/api/users/authenticate", name="ribsadmin_api_login", methods={"POST"}) |
|
20 | - * @param Request $request |
|
21 | - * @param Api $api |
|
22 | - * @param EncoderFactoryInterface $encoder |
|
23 | - * @return JsonResponse |
|
24 | - * @throws \Exception |
|
25 | - */ |
|
26 | - public function login(Request $request, Api $api, EncoderFactoryInterface $encoder): JsonResponse |
|
27 | - { |
|
28 | - $em = $this->getDoctrine()->getManager(); |
|
16 | + /** |
|
17 | + * this method is user to authenticate a user by an api request |
|
18 | + * if success it return a token api that expire in 20 minutes |
|
19 | + * @Route("/api/users/authenticate", name="ribsadmin_api_login", methods={"POST"}) |
|
20 | + * @param Request $request |
|
21 | + * @param Api $api |
|
22 | + * @param EncoderFactoryInterface $encoder |
|
23 | + * @return JsonResponse |
|
24 | + * @throws \Exception |
|
25 | + */ |
|
26 | + public function login(Request $request, Api $api, EncoderFactoryInterface $encoder): JsonResponse |
|
27 | + { |
|
28 | + $em = $this->getDoctrine()->getManager(); |
|
29 | 29 | |
30 | - $account = $em->getRepository(Account::class)->findOneBy([ |
|
31 | - "username" => $request->get("username"), |
|
32 | - ]); |
|
30 | + $account = $em->getRepository(Account::class)->findOneBy([ |
|
31 | + "username" => $request->get("username"), |
|
32 | + ]); |
|
33 | 33 | |
34 | - if ($account) { |
|
35 | - if ($encoder->getEncoder($account)->isPasswordValid($account->getPassword(), $request->get("password"), '') === true) { |
|
36 | - if ($account->getisActive() == false) { |
|
37 | - return new JsonResponse([ |
|
38 | - "success" => false, |
|
39 | - "error_message" => "You account is disabled" |
|
40 | - ]); |
|
41 | - } |
|
34 | + if ($account) { |
|
35 | + if ($encoder->getEncoder($account)->isPasswordValid($account->getPassword(), $request->get("password"), '') === true) { |
|
36 | + if ($account->getisActive() == false) { |
|
37 | + return new JsonResponse([ |
|
38 | + "success" => false, |
|
39 | + "error_message" => "You account is disabled" |
|
40 | + ]); |
|
41 | + } |
|
42 | 42 | |
43 | - return new JsonResponse([ |
|
44 | - "success" => true, |
|
45 | - "token" => $api->getToken($account) |
|
46 | - ]); |
|
47 | - } |
|
48 | - } |
|
43 | + return new JsonResponse([ |
|
44 | + "success" => true, |
|
45 | + "token" => $api->getToken($account) |
|
46 | + ]); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - return new JsonResponse([ |
|
51 | - "success" => false, |
|
52 | - "error_message" => "bad identifiant and/or password" |
|
53 | - ]); |
|
54 | - } |
|
50 | + return new JsonResponse([ |
|
51 | + "success" => false, |
|
52 | + "error_message" => "bad identifiant and/or password" |
|
53 | + ]); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * method that test if user steel logged and send token or new token if it was expired |
|
58 | - * @Route("/api/users/test-token", name="ribsadmin_api_test_token", methods={"POST"}) |
|
59 | - * @param Request $request |
|
60 | - * @param Api $api |
|
61 | - * @param Session $session |
|
62 | - * @return JsonResponse |
|
63 | - * @throws \Exception |
|
64 | - */ |
|
65 | - public function testUserToken(Request $request, Api $api, Session $session): JsonResponse |
|
66 | - { |
|
67 | - $test_logged = $api->userIslogged($request->get("infos"), $request->get("token")); |
|
56 | + /** |
|
57 | + * method that test if user steel logged and send token or new token if it was expired |
|
58 | + * @Route("/api/users/test-token", name="ribsadmin_api_test_token", methods={"POST"}) |
|
59 | + * @param Request $request |
|
60 | + * @param Api $api |
|
61 | + * @param Session $session |
|
62 | + * @return JsonResponse |
|
63 | + * @throws \Exception |
|
64 | + */ |
|
65 | + public function testUserToken(Request $request, Api $api, Session $session): JsonResponse |
|
66 | + { |
|
67 | + $test_logged = $api->userIslogged($request->get("infos"), $request->get("token")); |
|
68 | 68 | |
69 | - if ($test_logged === false) { |
|
70 | - return new JsonResponse([ |
|
71 | - "success" => $test_logged, |
|
72 | - "error_message" => "Votre compte a été archivé, vous ne pouvez plus vous connecter", |
|
73 | - ]); |
|
74 | - } |
|
69 | + if ($test_logged === false) { |
|
70 | + return new JsonResponse([ |
|
71 | + "success" => $test_logged, |
|
72 | + "error_message" => "Votre compte a été archivé, vous ne pouvez plus vous connecter", |
|
73 | + ]); |
|
74 | + } |
|
75 | 75 | |
76 | - return new JsonResponse([ |
|
77 | - "success" => $test_logged, |
|
78 | - "token" => $api->getToken($session->get("account")), |
|
79 | - ]); |
|
80 | - } |
|
76 | + return new JsonResponse([ |
|
77 | + "success" => $test_logged, |
|
78 | + "token" => $api->getToken($session->get("account")), |
|
79 | + ]); |
|
80 | + } |
|
81 | 81 | } |
@@ -7,13 +7,13 @@ |
||
7 | 7 | |
8 | 8 | class DefaultController extends AbstractController |
9 | 9 | { |
10 | - /** |
|
11 | - * @Route("/", name="ribsadmin") |
|
12 | - * @Route("/index", name="ribsadmin_index") |
|
13 | - * @Route("/navigation", name="ribsadmin_navigation") |
|
14 | - */ |
|
15 | - public function index() |
|
16 | - { |
|
17 | - return $this->render('@RibsAdmin/Default/index.html.twig'); |
|
18 | - } |
|
10 | + /** |
|
11 | + * @Route("/", name="ribsadmin") |
|
12 | + * @Route("/index", name="ribsadmin_index") |
|
13 | + * @Route("/navigation", name="ribsadmin_navigation") |
|
14 | + */ |
|
15 | + public function index() |
|
16 | + { |
|
17 | + return $this->render('@RibsAdmin/Default/index.html.twig'); |
|
18 | + } |
|
19 | 19 | } |
@@ -10,48 +10,48 @@ |
||
10 | 10 | |
11 | 11 | class NavigationBuilderController extends AbstractController |
12 | 12 | { |
13 | - private $nav = []; |
|
14 | - |
|
15 | - /** |
|
16 | - * function that display the left navigation mapped by user rights |
|
17 | - * @param Globals $globals |
|
18 | - * @param AccessRights $access_rights |
|
19 | - * @return Response |
|
20 | - */ |
|
21 | - public function getLeftNavigation(Globals $globals, AccessRights $access_rights): Response |
|
22 | - { |
|
23 | - $navigation = json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/navigation.json"), true); |
|
24 | - |
|
25 | - foreach ($navigation["items"] as $item) { |
|
26 | - if ($access_rights->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
27 | - $this->nav[] = $item; |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - $this->getModuleNavigation(); |
|
32 | - |
|
33 | - return $this->render("@RibsAdmin/navigation.html.twig", ["navigation" => $this->nav]); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * to get all modules navigation and test right navigation |
|
38 | - */ |
|
39 | - private function getModuleNavigation() |
|
40 | - { |
|
41 | - $modules = $this->getDoctrine()->getRepository(Module::class)->findBy([ |
|
42 | - "active" => true, |
|
43 | - "displayed" => true |
|
44 | - ]); |
|
45 | - |
|
46 | - foreach ($modules as $module) { |
|
47 | - $navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath |
|
48 | - ($module->getPackageName(), $module->getDevMode()) . "/Resources/json/navigation.json"), true); |
|
49 | - |
|
50 | - foreach ($navigation["items"] as $item) { |
|
51 | - if ($this->get("ribs_admin.acess_rights")->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
52 | - $this->nav[] = $item; |
|
53 | - } |
|
54 | - } |
|
55 | - } |
|
56 | - } |
|
13 | + private $nav = []; |
|
14 | + |
|
15 | + /** |
|
16 | + * function that display the left navigation mapped by user rights |
|
17 | + * @param Globals $globals |
|
18 | + * @param AccessRights $access_rights |
|
19 | + * @return Response |
|
20 | + */ |
|
21 | + public function getLeftNavigation(Globals $globals, AccessRights $access_rights): Response |
|
22 | + { |
|
23 | + $navigation = json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/navigation.json"), true); |
|
24 | + |
|
25 | + foreach ($navigation["items"] as $item) { |
|
26 | + if ($access_rights->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
27 | + $this->nav[] = $item; |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + $this->getModuleNavigation(); |
|
32 | + |
|
33 | + return $this->render("@RibsAdmin/navigation.html.twig", ["navigation" => $this->nav]); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * to get all modules navigation and test right navigation |
|
38 | + */ |
|
39 | + private function getModuleNavigation() |
|
40 | + { |
|
41 | + $modules = $this->getDoctrine()->getRepository(Module::class)->findBy([ |
|
42 | + "active" => true, |
|
43 | + "displayed" => true |
|
44 | + ]); |
|
45 | + |
|
46 | + foreach ($modules as $module) { |
|
47 | + $navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath |
|
48 | + ($module->getPackageName(), $module->getDevMode()) . "/Resources/json/navigation.json"), true); |
|
49 | + |
|
50 | + foreach ($navigation["items"] as $item) { |
|
51 | + if ($this->get("ribs_admin.acess_rights")->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
52 | + $this->nav[] = $item; |
|
53 | + } |
|
54 | + } |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |
@@ -44,8 +44,7 @@ |
||
44 | 44 | ]); |
45 | 45 | |
46 | 46 | foreach ($modules as $module) { |
47 | - $navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath |
|
48 | - ($module->getPackageName(), $module->getDevMode()) . "/Resources/json/navigation.json"), true); |
|
47 | + $navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath($module->getPackageName(), $module->getDevMode()) . "/Resources/json/navigation.json"), true); |
|
49 | 48 | |
50 | 49 | foreach ($navigation["items"] as $item) { |
51 | 50 | if ($this->get("ribs_admin.acess_rights")->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
@@ -8,14 +8,14 @@ |
||
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 | } |
@@ -12,126 +12,126 @@ |
||
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/edit/{guid}", name="ribsadmin_accounts_edit") |
|
36 | - * @param Request $request |
|
37 | - * @param string|null $guid |
|
38 | - * @return Response |
|
39 | - */ |
|
40 | - public function edit(Request $request, string $guid = null): Response |
|
41 | - { |
|
42 | - $em = $this->getDoctrine()->getManager(); |
|
43 | - |
|
44 | - if ($guid === null) { |
|
45 | - $account = new Account(); |
|
46 | - $old_password = null; |
|
47 | - $user = null; |
|
48 | - } else { |
|
49 | - $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]); |
|
50 | - $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]); |
|
51 | - $old_password = $account->getPassword(); |
|
52 | - } |
|
53 | - |
|
54 | - $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account); |
|
55 | - |
|
56 | - $form->handleRequest($request); |
|
57 | - |
|
58 | - if ($form->isSubmitted() && $form->isValid()) { |
|
59 | - /** |
|
60 | - * @var Account |
|
61 | - */ |
|
62 | - $data = $form->getData(); |
|
63 | - |
|
64 | - $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]); |
|
65 | - |
|
66 | - if ($account_exist && $account_exist === $account) { |
|
67 | - $account_exist = null; |
|
68 | - } |
|
69 | - |
|
70 | - if (!$account_exist) { |
|
71 | - if ($guid === null) { |
|
72 | - $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
73 | - $data->setPassword($temp_password); |
|
74 | - } else if ($form->get("password")->getData()) { |
|
75 | - $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
76 | - $data->setPassword($temp_password); |
|
77 | - } else { |
|
78 | - $data->setPassword($old_password); |
|
79 | - } |
|
80 | - |
|
81 | - $em->persist($data); |
|
82 | - $em->flush(); |
|
83 | - |
|
84 | - $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName(); |
|
85 | - |
|
86 | - if ($guid === null) { |
|
87 | - $this->addFlash("success-flash", "the account of " . $username . " was created"); |
|
88 | - } else { |
|
89 | - $this->addFlash("success-flash", "the account of " . $username . " was edited"); |
|
90 | - } |
|
91 | - |
|
92 | - return $this->redirectToRoute("ribsadmin_accounts"); |
|
93 | - } else { |
|
94 | - $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist"); |
|
95 | - return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - return $this->render("@RibsAdmin/accounts/edit.html.twig", [ |
|
100 | - "form" => $form->createView(), |
|
101 | - "form_errors" => $form->getErrors(), |
|
102 | - "user" => $user |
|
103 | - ]); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * method to disable or enable a user |
|
108 | - * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive") |
|
109 | - * @param string $guid |
|
110 | - * @param bool $activate |
|
111 | - * @return RedirectResponse |
|
112 | - */ |
|
113 | - public function archive(string $guid, bool $activate = false): RedirectResponse |
|
114 | - { |
|
115 | - $em = $this->getDoctrine()->getManager(); |
|
116 | - |
|
117 | - $user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
|
118 | - |
|
119 | - if ($user) { |
|
120 | - if ($activate === true) { |
|
121 | - $user->setArchived(false); |
|
122 | - $word = "activated"; |
|
123 | - } else { |
|
124 | - $user->setArchived(true); |
|
125 | - $word = "disabled"; |
|
126 | - } |
|
127 | - |
|
128 | - $em->persist($user); |
|
129 | - $em->flush(); |
|
130 | - |
|
131 | - $this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
|
132 | - " was " . $word . " sucessfuly"); |
|
133 | - } |
|
134 | - |
|
135 | - return $this->redirectToRoute("ribsadmin_accounts"); |
|
136 | - } |
|
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/edit/{guid}", name="ribsadmin_accounts_edit") |
|
36 | + * @param Request $request |
|
37 | + * @param string|null $guid |
|
38 | + * @return Response |
|
39 | + */ |
|
40 | + public function edit(Request $request, string $guid = null): Response |
|
41 | + { |
|
42 | + $em = $this->getDoctrine()->getManager(); |
|
43 | + |
|
44 | + if ($guid === null) { |
|
45 | + $account = new Account(); |
|
46 | + $old_password = null; |
|
47 | + $user = null; |
|
48 | + } else { |
|
49 | + $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]); |
|
50 | + $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]); |
|
51 | + $old_password = $account->getPassword(); |
|
52 | + } |
|
53 | + |
|
54 | + $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account); |
|
55 | + |
|
56 | + $form->handleRequest($request); |
|
57 | + |
|
58 | + if ($form->isSubmitted() && $form->isValid()) { |
|
59 | + /** |
|
60 | + * @var Account |
|
61 | + */ |
|
62 | + $data = $form->getData(); |
|
63 | + |
|
64 | + $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]); |
|
65 | + |
|
66 | + if ($account_exist && $account_exist === $account) { |
|
67 | + $account_exist = null; |
|
68 | + } |
|
69 | + |
|
70 | + if (!$account_exist) { |
|
71 | + if ($guid === null) { |
|
72 | + $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
73 | + $data->setPassword($temp_password); |
|
74 | + } else if ($form->get("password")->getData()) { |
|
75 | + $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
76 | + $data->setPassword($temp_password); |
|
77 | + } else { |
|
78 | + $data->setPassword($old_password); |
|
79 | + } |
|
80 | + |
|
81 | + $em->persist($data); |
|
82 | + $em->flush(); |
|
83 | + |
|
84 | + $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName(); |
|
85 | + |
|
86 | + if ($guid === null) { |
|
87 | + $this->addFlash("success-flash", "the account of " . $username . " was created"); |
|
88 | + } else { |
|
89 | + $this->addFlash("success-flash", "the account of " . $username . " was edited"); |
|
90 | + } |
|
91 | + |
|
92 | + return $this->redirectToRoute("ribsadmin_accounts"); |
|
93 | + } else { |
|
94 | + $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist"); |
|
95 | + return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + return $this->render("@RibsAdmin/accounts/edit.html.twig", [ |
|
100 | + "form" => $form->createView(), |
|
101 | + "form_errors" => $form->getErrors(), |
|
102 | + "user" => $user |
|
103 | + ]); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * method to disable or enable a user |
|
108 | + * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive") |
|
109 | + * @param string $guid |
|
110 | + * @param bool $activate |
|
111 | + * @return RedirectResponse |
|
112 | + */ |
|
113 | + public function archive(string $guid, bool $activate = false): RedirectResponse |
|
114 | + { |
|
115 | + $em = $this->getDoctrine()->getManager(); |
|
116 | + |
|
117 | + $user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
|
118 | + |
|
119 | + if ($user) { |
|
120 | + if ($activate === true) { |
|
121 | + $user->setArchived(false); |
|
122 | + $word = "activated"; |
|
123 | + } else { |
|
124 | + $user->setArchived(true); |
|
125 | + $word = "disabled"; |
|
126 | + } |
|
127 | + |
|
128 | + $em->persist($user); |
|
129 | + $em->flush(); |
|
130 | + |
|
131 | + $this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
|
132 | + " was " . $word . " sucessfuly"); |
|
133 | + } |
|
134 | + |
|
135 | + return $this->redirectToRoute("ribsadmin_accounts"); |
|
136 | + } |
|
137 | 137 | } |
@@ -11,79 +11,79 @@ |
||
11 | 11 | |
12 | 12 | class ModuleController extends AbstractController |
13 | 13 | { |
14 | - /** |
|
15 | - * @Route("/modules/", name="ribsadmin_modules") |
|
16 | - * @return Response |
|
17 | - */ |
|
18 | - public function list(): Response |
|
19 | - { |
|
20 | - $em = $this->getDoctrine()->getManager(); |
|
14 | + /** |
|
15 | + * @Route("/modules/", name="ribsadmin_modules") |
|
16 | + * @return Response |
|
17 | + */ |
|
18 | + public function list(): Response |
|
19 | + { |
|
20 | + $em = $this->getDoctrine()->getManager(); |
|
21 | 21 | |
22 | - $modules = $em->getRepository(Module::class)->findBy([], ['titleTag' => 'ASC']); |
|
22 | + $modules = $em->getRepository(Module::class)->findBy([], ['titleTag' => 'ASC']); |
|
23 | 23 | |
24 | - return $this->render('@RibsAdmin/modules/list.html.twig', [ |
|
25 | - "modules" => $modules, |
|
26 | - ]); |
|
27 | - } |
|
24 | + return $this->render('@RibsAdmin/modules/list.html.twig', [ |
|
25 | + "modules" => $modules, |
|
26 | + ]); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @Route("/modules/create/", name="ribsadmin_modules_create") |
|
31 | - * @Route("/modules/edit/{id}", name="ribsadmin_modules_edit") |
|
32 | - * @param Request $request |
|
33 | - * @param int|null $id |
|
34 | - * @return Response |
|
35 | - */ |
|
36 | - public function edit(Request $request, int $id = null): Response |
|
37 | - { |
|
38 | - $em = $this->getDoctrine()->getManager(); |
|
29 | + /** |
|
30 | + * @Route("/modules/create/", name="ribsadmin_modules_create") |
|
31 | + * @Route("/modules/edit/{id}", name="ribsadmin_modules_edit") |
|
32 | + * @param Request $request |
|
33 | + * @param int|null $id |
|
34 | + * @return Response |
|
35 | + */ |
|
36 | + public function edit(Request $request, int $id = null): Response |
|
37 | + { |
|
38 | + $em = $this->getDoctrine()->getManager(); |
|
39 | 39 | |
40 | - if (!$id) { |
|
41 | - $module = new Module(); |
|
42 | - $text = "created"; |
|
43 | - } else { |
|
44 | - $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
45 | - $text = "edited"; |
|
46 | - } |
|
40 | + if (!$id) { |
|
41 | + $module = new Module(); |
|
42 | + $text = "created"; |
|
43 | + } else { |
|
44 | + $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
45 | + $text = "edited"; |
|
46 | + } |
|
47 | 47 | |
48 | - $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Module::class, $module); |
|
49 | - $form->handleRequest($request); |
|
48 | + $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Module::class, $module); |
|
49 | + $form->handleRequest($request); |
|
50 | 50 | |
51 | - if ($form->isSubmitted() && $form->isValid()) { |
|
52 | - /** @var Module $data */ |
|
53 | - $data = $form->getData(); |
|
54 | - $em->persist($data); |
|
55 | - $em->flush(); |
|
56 | - $this->addFlash("success-flash", "Module " . $data->getTitleTag() . " was " . $text); |
|
51 | + if ($form->isSubmitted() && $form->isValid()) { |
|
52 | + /** @var Module $data */ |
|
53 | + $data = $form->getData(); |
|
54 | + $em->persist($data); |
|
55 | + $em->flush(); |
|
56 | + $this->addFlash("success-flash", "Module " . $data->getTitleTag() . " was " . $text); |
|
57 | 57 | |
58 | - return $this->redirectToRoute("ribsadmin_modules"); |
|
59 | - } |
|
58 | + return $this->redirectToRoute("ribsadmin_modules"); |
|
59 | + } |
|
60 | 60 | |
61 | - return $this->render("@RibsAdmin/modules/edit.html.twig", [ |
|
62 | - "form" => $form->createView(), |
|
63 | - "form_errors" => $form->getErrors(), |
|
64 | - "module" => $module |
|
65 | - ]); |
|
66 | - } |
|
61 | + return $this->render("@RibsAdmin/modules/edit.html.twig", [ |
|
62 | + "form" => $form->createView(), |
|
63 | + "form_errors" => $form->getErrors(), |
|
64 | + "module" => $module |
|
65 | + ]); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/modules/delete/{id}", name="ribsadmin_modules_delete") |
|
70 | - * @param int $id |
|
71 | - * @return RedirectResponse |
|
72 | - */ |
|
73 | - public function delete(int $id): RedirectResponse |
|
74 | - { |
|
75 | - $em = $this->getDoctrine()->getManager(); |
|
76 | - $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
68 | + /** |
|
69 | + * @Route("/modules/delete/{id}", name="ribsadmin_modules_delete") |
|
70 | + * @param int $id |
|
71 | + * @return RedirectResponse |
|
72 | + */ |
|
73 | + public function delete(int $id): RedirectResponse |
|
74 | + { |
|
75 | + $em = $this->getDoctrine()->getManager(); |
|
76 | + $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
77 | 77 | |
78 | - if ($module) { |
|
79 | - $name = $module->getTitle(); |
|
80 | - $em->remove($module); |
|
81 | - $em->flush(); |
|
82 | - $this->addFlash("success-flash", "Module " . $name . " was deleted"); |
|
83 | - } else { |
|
84 | - $this->addFlash("error-flash", "An error occured, module doesn't found"); |
|
85 | - } |
|
78 | + if ($module) { |
|
79 | + $name = $module->getTitle(); |
|
80 | + $em->remove($module); |
|
81 | + $em->flush(); |
|
82 | + $this->addFlash("success-flash", "Module " . $name . " was deleted"); |
|
83 | + } else { |
|
84 | + $this->addFlash("error-flash", "An error occured, module doesn't found"); |
|
85 | + } |
|
86 | 86 | |
87 | - return $this->redirectToRoute("ribsadmin_modules"); |
|
88 | - } |
|
87 | + return $this->redirectToRoute("ribsadmin_modules"); |
|
88 | + } |
|
89 | 89 | } |
@@ -9,22 +9,22 @@ |
||
9 | 9 | |
10 | 10 | class RenderPageController extends AbstractController |
11 | 11 | { |
12 | - /** |
|
13 | - * @Route("/page/{url}", name="page", requirements={"url" = "[a-zA-Z0-9\-\_\/]*"}) |
|
14 | - * @param string $url |
|
15 | - * @return Response |
|
16 | - */ |
|
17 | - public function renderPage(string $url): Response |
|
18 | - { |
|
19 | - $em = $this->getDoctrine()->getManager(); |
|
12 | + /** |
|
13 | + * @Route("/page/{url}", name="page", requirements={"url" = "[a-zA-Z0-9\-\_\/]*"}) |
|
14 | + * @param string $url |
|
15 | + * @return Response |
|
16 | + */ |
|
17 | + public function renderPage(string $url): Response |
|
18 | + { |
|
19 | + $em = $this->getDoctrine()->getManager(); |
|
20 | 20 | |
21 | - $page = $em->getRepository("RibsAdminBundle:Page")->findOneBy(["url" => $url]); |
|
22 | - $navigation = $em->getRepository("RibsAdminBundle:Navigation")->findAllNavigation(); |
|
21 | + $page = $em->getRepository("RibsAdminBundle:Page")->findOneBy(["url" => $url]); |
|
22 | + $navigation = $em->getRepository("RibsAdminBundle:Navigation")->findAllNavigation(); |
|
23 | 23 | |
24 | - if ($page) { |
|
25 | - return $this->render("@RibsAdmin/page.html.twig", ["page" => $page, "navigation" => $navigation]); |
|
26 | - } |
|
24 | + if ($page) { |
|
25 | + return $this->render("@RibsAdmin/page.html.twig", ["page" => $page, "navigation" => $navigation]); |
|
26 | + } |
|
27 | 27 | |
28 | - throw new NotFoundHttpException("The required page does not exist"); |
|
29 | - } |
|
28 | + throw new NotFoundHttpException("The required page does not exist"); |
|
29 | + } |
|
30 | 30 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | |
14 | 14 | class Account extends AbstractType |
15 | 15 | { |
16 | - /** |
|
17 | - * @param FormBuilderInterface $builder |
|
18 | - * @param array $options |
|
19 | - */ |
|
16 | + /** |
|
17 | + * @param FormBuilderInterface $builder |
|
18 | + * @param array $options |
|
19 | + */ |
|
20 | 20 | public function buildForm(FormBuilderInterface $builder, array $options) |
21 | 21 | { |
22 | 22 | $builder |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | $builder->add('user', User::class); |
50 | 50 | } |
51 | 51 | |
52 | - /** |
|
53 | - * @param OptionsResolver $resolver |
|
54 | - */ |
|
52 | + /** |
|
53 | + * @param OptionsResolver $resolver |
|
54 | + */ |
|
55 | 55 | public function configureOptions(OptionsResolver $resolver) |
56 | 56 | { |
57 | 57 | $resolver->setDefaults([ |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | |
13 | 13 | class Module extends AbstractType |
14 | 14 | { |
15 | - /** |
|
16 | - * @param FormBuilderInterface $builder |
|
17 | - * @param array $options |
|
18 | - */ |
|
15 | + /** |
|
16 | + * @param FormBuilderInterface $builder |
|
17 | + * @param array $options |
|
18 | + */ |
|
19 | 19 | public function buildForm(FormBuilderInterface $builder, array $options) |
20 | 20 | { |
21 | 21 | $builder |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | "label" => "Package name", |
28 | 28 | "required" => true |
29 | 29 | ]) |
30 | - ->add("titleTag", TextType::class, [ |
|
31 | - "label" => "Title tag", |
|
32 | - "required" => true |
|
33 | - ]) |
|
34 | - ->add("descriptionTag", TextareaType::class, [ |
|
35 | - "label" => "Description tag", |
|
36 | - "required" => true, |
|
37 | - ]) |
|
38 | - ->add("url", TextType::class, [ |
|
39 | - "label" => "Url", |
|
40 | - "required" => true |
|
41 | - ]) |
|
42 | - ->add("urlAdmin", TextType::class, [ |
|
43 | - "label" => "Admin url", |
|
44 | - "required" => true |
|
45 | - ]) |
|
30 | + ->add("titleTag", TextType::class, [ |
|
31 | + "label" => "Title tag", |
|
32 | + "required" => true |
|
33 | + ]) |
|
34 | + ->add("descriptionTag", TextareaType::class, [ |
|
35 | + "label" => "Description tag", |
|
36 | + "required" => true, |
|
37 | + ]) |
|
38 | + ->add("url", TextType::class, [ |
|
39 | + "label" => "Url", |
|
40 | + "required" => true |
|
41 | + ]) |
|
42 | + ->add("urlAdmin", TextType::class, [ |
|
43 | + "label" => "Admin url", |
|
44 | + "required" => true |
|
45 | + ]) |
|
46 | 46 | ->add("active", CheckboxType::class, [ |
47 | 47 | "label" => "Enable module", |
48 | 48 | "attr" => [ |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | ], |
51 | 51 | "required" => false |
52 | 52 | ]) |
53 | - ->add("displayed", CheckboxType::class, [ |
|
54 | - "label" => "Display module in navigation", |
|
55 | - "attr" => [ |
|
56 | - "class" => "ribs-checkbox switched cxs-2 no-pl" |
|
57 | - ], |
|
58 | - "required" => false |
|
59 | - ]) |
|
60 | - ->add('submit', SubmitType::class, [ |
|
61 | - 'label' => 'Validate', |
|
62 | - 'attr' => [] |
|
63 | - ]); |
|
53 | + ->add("displayed", CheckboxType::class, [ |
|
54 | + "label" => "Display module in navigation", |
|
55 | + "attr" => [ |
|
56 | + "class" => "ribs-checkbox switched cxs-2 no-pl" |
|
57 | + ], |
|
58 | + "required" => false |
|
59 | + ]) |
|
60 | + ->add('submit', SubmitType::class, [ |
|
61 | + 'label' => 'Validate', |
|
62 | + 'attr' => [] |
|
63 | + ]); |
|
64 | 64 | } |
65 | 65 | |
66 | - /** |
|
67 | - * @param OptionsResolver $resolver |
|
68 | - */ |
|
66 | + /** |
|
67 | + * @param OptionsResolver $resolver |
|
68 | + */ |
|
69 | 69 | public function configureOptions(OptionsResolver $resolver) |
70 | 70 | { |
71 | 71 | $resolver->setDefaults([ |