@@ -15,92 +15,92 @@ discard block |
||
15 | 15 | |
16 | 16 | class GetMenuByPeopleAction |
17 | 17 | { |
18 | - /** |
|
19 | - * Entity Manager |
|
20 | - * |
|
21 | - * @var EntityManagerInterface |
|
22 | - */ |
|
23 | - private $manager = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * Request |
|
27 | - * |
|
28 | - * @var Request |
|
29 | - */ |
|
30 | - private $request = null; |
|
31 | - |
|
32 | - /** |
|
33 | - * Security |
|
34 | - * |
|
35 | - * @var Security |
|
36 | - */ |
|
37 | - private $security = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var \ControleOnline\Repository\MenuRepository |
|
41 | - */ |
|
42 | - private $repository = null; |
|
43 | - |
|
44 | - |
|
45 | - public function __construct(Security $security, EntityManagerInterface $entityManager) |
|
46 | - { |
|
18 | + /** |
|
19 | + * Entity Manager |
|
20 | + * |
|
21 | + * @var EntityManagerInterface |
|
22 | + */ |
|
23 | + private $manager = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * Request |
|
27 | + * |
|
28 | + * @var Request |
|
29 | + */ |
|
30 | + private $request = null; |
|
31 | + |
|
32 | + /** |
|
33 | + * Security |
|
34 | + * |
|
35 | + * @var Security |
|
36 | + */ |
|
37 | + private $security = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var \ControleOnline\Repository\MenuRepository |
|
41 | + */ |
|
42 | + private $repository = null; |
|
43 | + |
|
44 | + |
|
45 | + public function __construct(Security $security, EntityManagerInterface $entityManager) |
|
46 | + { |
|
47 | 47 | $this->manager = $entityManager; |
48 | 48 | $this->security = $security; |
49 | 49 | $this->repository = $this->manager->getRepository(Menu::class); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - public function __invoke(Request $request): JsonResponse |
|
53 | - { |
|
52 | + public function __invoke(Request $request): JsonResponse |
|
53 | + { |
|
54 | 54 | try { |
55 | 55 | |
56 | - $menu = []; |
|
56 | + $menu = []; |
|
57 | 57 | |
58 | - $company = $request->query->get('myCompany', null); |
|
58 | + $company = $request->query->get('myCompany', null); |
|
59 | 59 | |
60 | - if ($company === null) |
|
60 | + if ($company === null) |
|
61 | 61 | throw new Exception("Company not found", 404); |
62 | 62 | |
63 | 63 | |
64 | - $myCompany = $this->manager->getRepository(People::class) |
|
64 | + $myCompany = $this->manager->getRepository(People::class) |
|
65 | 65 | ->find($company); |
66 | 66 | |
67 | - if ($myCompany === null) |
|
67 | + if ($myCompany === null) |
|
68 | 68 | throw new Exception("Company not found", 404); |
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - $currentUser = $this->security->getToken()->getUser(); |
|
73 | - /** |
|
74 | - * @var People |
|
75 | - */ |
|
76 | - $userPeople = $currentUser->getPeople(); |
|
72 | + $currentUser = $this->security->getToken()->getUser(); |
|
73 | + /** |
|
74 | + * @var People |
|
75 | + */ |
|
76 | + $userPeople = $currentUser->getPeople(); |
|
77 | 77 | |
78 | - $menu = $this->getMenuByPeople($userPeople, $myCompany); |
|
78 | + $menu = $this->getMenuByPeople($userPeople, $myCompany); |
|
79 | 79 | |
80 | 80 | |
81 | - return new JsonResponse([ |
|
81 | + return new JsonResponse([ |
|
82 | 82 | 'response' => [ |
83 | - 'data' => $menu, |
|
84 | - 'count' => 1, |
|
85 | - 'error' => '', |
|
86 | - 'success' => true, |
|
83 | + 'data' => $menu, |
|
84 | + 'count' => 1, |
|
85 | + 'error' => '', |
|
86 | + 'success' => true, |
|
87 | 87 | ], |
88 | - ]); |
|
88 | + ]); |
|
89 | 89 | } catch (\Exception $e) { |
90 | 90 | |
91 | - return new JsonResponse([ |
|
91 | + return new JsonResponse([ |
|
92 | 92 | 'response' => [ |
93 | - 'data' => [], |
|
94 | - 'count' => 0, |
|
95 | - 'error' => $e->getMessage(), |
|
96 | - 'success' => false, |
|
93 | + 'data' => [], |
|
94 | + 'count' => 0, |
|
95 | + 'error' => $e->getMessage(), |
|
96 | + 'success' => false, |
|
97 | 97 | ], |
98 | - ]); |
|
98 | + ]); |
|
99 | + } |
|
99 | 100 | } |
100 | - } |
|
101 | 101 | |
102 | - private function getMenuByPeople(People $userPeople, People $myCompany) |
|
103 | - { |
|
102 | + private function getMenuByPeople(People $userPeople, People $myCompany) |
|
103 | + { |
|
104 | 104 | |
105 | 105 | $return = []; |
106 | 106 | $connection = $this->manager->getConnection(); |
@@ -133,22 +133,22 @@ discard block |
||
133 | 133 | |
134 | 134 | foreach ($result as $menu) { |
135 | 135 | |
136 | - $return['modules'][$menu['category_id']]['id'] = $menu['category_id']; |
|
137 | - $return['modules'][$menu['category_id']]['label'] = $menu['category_label']; |
|
138 | - $return['modules'][$menu['category_id']]['color'] = $menu['category_color']; |
|
139 | - $return['modules'][$menu['category_id']]['icon'] = $menu['category_icon']; |
|
140 | - $return['modules'][$menu['category_id']]['menus'][] = [ |
|
136 | + $return['modules'][$menu['category_id']]['id'] = $menu['category_id']; |
|
137 | + $return['modules'][$menu['category_id']]['label'] = $menu['category_label']; |
|
138 | + $return['modules'][$menu['category_id']]['color'] = $menu['category_color']; |
|
139 | + $return['modules'][$menu['category_id']]['icon'] = $menu['category_icon']; |
|
140 | + $return['modules'][$menu['category_id']]['menus'][] = [ |
|
141 | 141 | 'id' => $menu['id'], |
142 | 142 | 'label' => $menu['menu'], |
143 | 143 | 'icon' => $menu['icon'], |
144 | 144 | 'color' => $menu['color'], |
145 | 145 | 'route' => $menu['route'], |
146 | 146 | 'module' => '/modules/' . $menu['module'], |
147 | - ]; |
|
147 | + ]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
151 | 151 | |
152 | 152 | return $return; |
153 | - } |
|
153 | + } |
|
154 | 154 | } |