1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
|
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
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class GetActionByPeopleAction |
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
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function __invoke(Request $request): JsonResponse |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
|
54
|
|
|
$menu = []; |
|
|
|
|
55
|
|
|
|
56
|
|
|
$company = $request->query->get('myCompany', null); |
57
|
|
|
|
58
|
|
|
if ($company === null) |
59
|
|
|
throw new Exception("Company not found", 404); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
$myCompany = $this->manager->getRepository(People::class) |
63
|
|
|
->find($company); |
64
|
|
|
|
65
|
|
|
if ($myCompany === null) |
66
|
|
|
throw new Exception("Company not found", 404); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
$currentUser = $this->security->getUser(); |
71
|
|
|
/** |
72
|
|
|
* @var People |
73
|
|
|
*/ |
74
|
|
|
$userPeople = $currentUser->getPeople(); |
75
|
|
|
|
76
|
|
|
$menu = $this->getMenuByPeople($userPeople, $myCompany); |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
return new JsonResponse([ |
80
|
|
|
'response' => [ |
81
|
|
|
'data' => $menu, |
82
|
|
|
'count' => 1, |
83
|
|
|
'error' => '', |
84
|
|
|
'success' => true, |
85
|
|
|
], |
86
|
|
|
]); |
87
|
|
|
} catch (\Exception $e) { |
88
|
|
|
|
89
|
|
|
return new JsonResponse([ |
90
|
|
|
'response' => [ |
91
|
|
|
'data' => [], |
92
|
|
|
'count' => 0, |
93
|
|
|
'error' => $e->getMessage(), |
94
|
|
|
'success' => false, |
95
|
|
|
], |
96
|
|
|
]); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
private function getMenuByPeople(People $userPeople, People $myCompany) |
101
|
|
|
{ |
102
|
|
|
|
103
|
|
|
$return = []; |
104
|
|
|
$connection = $this->manager->getConnection(); |
105
|
|
|
|
106
|
|
|
// build query |
107
|
|
|
|
108
|
|
|
$sql = 'SELECT action.*,routes.route |
109
|
|
|
|
110
|
|
|
FROM action |
111
|
|
|
INNER JOIN routes ON routes.id = action.route_id |
112
|
|
|
INNER JOIN action_role ON action_role.action_id = action.id |
113
|
|
|
INNER JOIN role ON role.id = action_role.role_id |
114
|
|
|
INNER JOIN people_role ON people_role.role_id = role.id |
115
|
|
|
WHERE people_role.company_id=:myCompany AND |
116
|
|
|
people_role.people_id=:userPeople AND |
117
|
|
|
routes.route=:route |
118
|
|
|
GROUP BY action.id |
119
|
|
|
'; |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
|
$params = []; |
124
|
|
|
|
125
|
|
|
$params['myCompany'] = $myCompany->getId(); |
126
|
|
|
$params['userPeople'] = $userPeople->getId(); |
127
|
|
|
$params['route'] = $this->route; |
|
|
|
|
128
|
|
|
// execute query |
129
|
|
|
|
130
|
|
|
$statement = $connection->prepare($sql); |
131
|
|
|
$statement->execute($params); |
132
|
|
|
|
133
|
|
|
$result = $statement->fetchAll(); |
134
|
|
|
|
135
|
|
|
foreach ($result as $action) { |
136
|
|
|
$return['routes'][trim($action['route'])]['actions'][$action['id']] = trim($action['action']); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $return; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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