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\Authentication\Token\Storage\TokenStorageInterface |
|
|
|
|
12
|
|
|
as Security; |
13
|
|
|
use ControleOnline\Repository\MenuRepository; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class GetMenuByPeopleAction |
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
|
|
|
{ |
47
|
|
|
$this->manager = $entityManager; |
48
|
|
|
$this->security = $security; |
49
|
|
|
$this->repository = $this->manager->getRepository(Menu::class); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __invoke(Request $request): JsonResponse |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
|
56
|
|
|
$menu = []; |
|
|
|
|
57
|
|
|
|
58
|
|
|
$company = $request->query->get('myCompany', null); |
59
|
|
|
|
60
|
|
|
if ($company === null) |
61
|
|
|
throw new Exception("Company not found", 404); |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
$myCompany = $this->manager->getRepository(People::class) |
65
|
|
|
->find($company); |
66
|
|
|
|
67
|
|
|
if ($myCompany === null) |
68
|
|
|
throw new Exception("Company not found", 404); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
|
72
|
|
|
$currentUser = $this->security->getToken()->getUser(); |
73
|
|
|
/** |
74
|
|
|
* @var People |
75
|
|
|
*/ |
76
|
|
|
$userPeople = $currentUser->getPeople(); |
77
|
|
|
|
78
|
|
|
$menu = $this->getMenuByPeople($userPeople, $myCompany); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
return new JsonResponse([ |
82
|
|
|
'response' => [ |
83
|
|
|
'data' => $menu, |
84
|
|
|
'count' => 1, |
85
|
|
|
'error' => '', |
86
|
|
|
'success' => true, |
87
|
|
|
], |
88
|
|
|
]); |
89
|
|
|
} catch (\Exception $e) { |
90
|
|
|
|
91
|
|
|
return new JsonResponse([ |
92
|
|
|
'response' => [ |
93
|
|
|
'data' => [], |
94
|
|
|
'count' => 0, |
95
|
|
|
'error' => $e->getMessage(), |
96
|
|
|
'success' => false, |
97
|
|
|
], |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function getMenuByPeople(People $userPeople, People $myCompany) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
|
105
|
|
|
$return = []; |
106
|
|
|
$connection = $this->manager->getConnection(); |
107
|
|
|
|
108
|
|
|
// build query |
109
|
|
|
|
110
|
|
|
$sql = 'SELECT menu.*, |
111
|
|
|
category.name AS category_label, |
112
|
|
|
category.color AS category_color, |
113
|
|
|
routes.route AS route, |
114
|
|
|
routes.color AS color, |
115
|
|
|
routes.icon AS icon, |
116
|
|
|
routes.module_id AS module, |
117
|
|
|
category.icon AS category_icon FROM menu |
118
|
|
|
INNER JOIN category ON category.id = menu.category_id |
119
|
|
|
INNER JOIN menu_role ON menu.id = menu_role.menu_id |
120
|
|
|
INNER JOIN people_role ON people_role.role_id = menu_role.role_id |
121
|
|
|
INNER JOIN routes ON routes.id = menu.route_id '; |
122
|
|
|
//$sql .= 'WHERE people_role.company_id=:myCompany AND people_role.people_id=:userPeople '; |
123
|
|
|
$sql .= 'GROUP BY menu.id'; |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
$params = []; |
127
|
|
|
|
128
|
|
|
//$params['myCompany'] = $myCompany->getId(); |
129
|
|
|
//$params['userPeople'] = $userPeople->getId(); |
130
|
|
|
// execute query |
131
|
|
|
|
132
|
|
|
$result = $connection->executeQuery($sql, $params)->fetchAllAssociative(); |
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
|
|
|
'module' => '/modules/' . $menu['module'], |
147
|
|
|
]; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
|
152
|
|
|
return $return; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
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