1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Menu; |
6
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Exception; |
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
11
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
12
|
|
|
use ControleOnline\Repository\MenuRepository; |
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class GetMenuByPeopleAction |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Entity Manager |
19
|
|
|
* |
20
|
|
|
* @var EntityManagerInterface |
21
|
|
|
*/ |
22
|
|
|
private $manager = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Request |
26
|
|
|
* |
27
|
|
|
* @var Request |
28
|
|
|
*/ |
29
|
|
|
private $request = null; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Security |
33
|
|
|
* |
34
|
|
|
* @var Security |
35
|
|
|
*/ |
36
|
|
|
private $security = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \ControleOnline\Repository\MenuRepository |
40
|
|
|
*/ |
41
|
|
|
private $repository = null; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function __construct(Security $security, EntityManagerInterface $entityManager) |
45
|
|
|
{ |
46
|
|
|
$this->manager = $entityManager; |
47
|
|
|
$this->security = $security; |
48
|
|
|
$this->repository = $this->manager->getRepository(\ControleOnline\Entity\Menu::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function __invoke(Request $request): JsonResponse |
52
|
|
|
{ |
53
|
|
|
try { |
54
|
|
|
|
55
|
|
|
$menu = []; |
|
|
|
|
56
|
|
|
|
57
|
|
|
$company = $request->query->get('myCompany', null); |
58
|
|
|
|
59
|
|
|
if ($company === null) |
60
|
|
|
throw new Exception("Company not found", 404); |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
$myCompany = $this->manager->getRepository(People::class) |
64
|
|
|
->find($company); |
65
|
|
|
|
66
|
|
|
if ($myCompany === null) |
67
|
|
|
throw new Exception("Company not found", 404); |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$currentUser = $this->security->getUser(); |
72
|
|
|
/** |
73
|
|
|
* @var People |
74
|
|
|
*/ |
75
|
|
|
$userPeople = $currentUser->getPeople(); |
76
|
|
|
|
77
|
|
|
$menu = $this->getMenuByPeople($userPeople, $myCompany); |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
return new JsonResponse([ |
81
|
|
|
'response' => [ |
82
|
|
|
'data' => $menu, |
83
|
|
|
'count' => 1, |
84
|
|
|
'error' => '', |
85
|
|
|
'success' => true, |
86
|
|
|
], |
87
|
|
|
]); |
88
|
|
|
} catch (\Exception $e) { |
89
|
|
|
|
90
|
|
|
return new JsonResponse([ |
91
|
|
|
'response' => [ |
92
|
|
|
'data' => [], |
93
|
|
|
'count' => 0, |
94
|
|
|
'error' => $e->getMessage(), |
95
|
|
|
'success' => false, |
96
|
|
|
], |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function getMenuByPeople(People $userPeople, People $myCompany) |
102
|
|
|
{ |
103
|
|
|
|
104
|
|
|
$return = []; |
105
|
|
|
$connection = $this->manager->getConnection(); |
106
|
|
|
|
107
|
|
|
// build query |
108
|
|
|
|
109
|
|
|
$sql = 'SELECT menu.*, |
110
|
|
|
category.name AS category_label, |
111
|
|
|
category.color AS category_color, |
112
|
|
|
routes.route AS route, |
113
|
|
|
category.icon AS category_icon FROM menu |
114
|
|
|
INNER JOIN category ON category.id = menu.category_id |
115
|
|
|
INNER JOIN menu_role ON menu.id = menu_role.menu_id |
116
|
|
|
INNER JOIN people_role ON people_role.role_id = menu_role.role_id |
117
|
|
|
INNER JOIN routes ON routes.id = menu.route_id |
118
|
|
|
WHERE people_role.company_id=:myCompany AND people_role.people_id=:userPeople |
119
|
|
|
GROUP BY menu.id |
120
|
|
|
'; |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
$params = []; |
124
|
|
|
|
125
|
|
|
$params['myCompany'] = $myCompany->getId(); |
126
|
|
|
$params['userPeople'] = $userPeople->getId(); |
127
|
|
|
// execute query |
128
|
|
|
|
129
|
|
|
$statement = $connection->prepare($sql); |
130
|
|
|
$statement->execute($params); |
131
|
|
|
|
132
|
|
|
$result = $statement->fetchAll(); |
133
|
|
|
|
134
|
|
|
foreach ($result as $menu) { |
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'][] = [ |
141
|
|
|
'id' => $menu['id'], |
142
|
|
|
'label' => $menu['menu'], |
143
|
|
|
'icon' => $menu['icon'], |
144
|
|
|
'color' => $menu['color'], |
145
|
|
|
'route' => $menu['route'], |
146
|
|
|
]; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
151
|
|
|
return $return; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths