1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\People; |
6
|
|
|
use ControleOnline\Entity\PeopleDomain; |
7
|
|
|
use ControleOnline\Entity\PeopleLink; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
10
|
|
|
use ControleOnline\Entity\User; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class PeopleRoleService |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
private static $mainCompany; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private EntityManagerInterface $manager, |
19
|
|
|
private Security $security, |
20
|
|
|
private DomainService $domainService |
|
|
|
|
21
|
|
|
) {} |
22
|
|
|
|
23
|
|
|
public function isFranchisee(People $people) |
24
|
|
|
{ |
25
|
|
|
$mainCompany = $this->getMainCompany(); |
26
|
|
|
$isFranchisee = false; |
27
|
|
|
|
28
|
|
|
$getPeopleCompanies = $this->manager->getRepository(PeopleLink::class)->findBy([ |
29
|
|
|
'people' => $people, |
30
|
|
|
'link_type' => 'employee' |
31
|
|
|
]); |
32
|
|
|
/** |
33
|
|
|
* @var \ControleOnline\Entity\PeopleLink $peopleCompany |
34
|
|
|
*/ |
35
|
|
|
foreach ($getPeopleCompanies as $peopleCompany) { |
36
|
|
|
$isFranchisee = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $peopleCompany->getCompany(), 'franchisee', 1); |
37
|
|
|
if ($isFranchisee) return true; |
38
|
|
|
} |
39
|
|
|
return $isFranchisee; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function isSalesman(People $people) |
44
|
|
|
{ |
45
|
|
|
$mainCompany = $this->getMainCompany(); |
46
|
|
|
$isSalesman = false; |
|
|
|
|
47
|
|
|
|
48
|
|
|
$isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'salesman', 1); |
49
|
|
|
if ($isSalesman) return true; |
50
|
|
|
|
51
|
|
|
$getPeopleCompanies = $this->manager->getRepository(PeopleLink::class)->findBy([ |
52
|
|
|
'people' => $people, |
53
|
|
|
'link_type' => 'employee' |
54
|
|
|
]); |
55
|
|
|
/** |
56
|
|
|
* @var \ControleOnline\Entity\PeopleLink $peopleCompany |
57
|
|
|
*/ |
58
|
|
|
foreach ($getPeopleCompanies as $peopleCompany) { |
59
|
|
|
$isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $peopleCompany->getCompany(), 'salesman', 1); |
60
|
|
|
if ($isSalesman) return true; |
61
|
|
|
} |
62
|
|
|
return $isSalesman; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function getAllRoles(People $people): array |
67
|
|
|
{ |
68
|
|
|
$peopleRole = []; |
69
|
|
|
$mainCompany = $this->getMainCompany(); |
70
|
|
|
|
71
|
|
|
$isSuper = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'employee', 1); |
72
|
|
|
if ($isSuper) |
73
|
|
|
$peopleRole[] = 'super'; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
$isFranchisee = $this->isFranchisee($people); |
78
|
|
|
if ($isFranchisee) { |
79
|
|
|
$peopleRole[] = 'franchisee'; |
80
|
|
|
$peopleRole[] = 'admin'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$isClient = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'client', 1); |
84
|
|
|
if ($isClient) |
85
|
|
|
$peopleRole[] = 'client'; |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
$isSalesman = $this->isSalesman($people); |
89
|
|
|
if ($isSalesman) |
90
|
|
|
$peopleRole[] = 'salesman'; |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
return array_values(array_unique(empty($peopleRole) ? ['guest'] : $peopleRole)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Retorna a people da empresa principal segundo o dominio da api |
98
|
|
|
* |
99
|
|
|
* @return People |
100
|
|
|
*/ |
101
|
|
|
public function getMainCompany(): People |
102
|
|
|
{ |
103
|
|
|
|
104
|
|
|
if (self::$mainCompany) return self::$mainCompany; |
105
|
|
|
|
106
|
|
|
$peopleDomain = $this->domainService->getPeopleDomain(); |
107
|
|
|
self::$mainCompany = $peopleDomain->getPeople(); |
108
|
|
|
|
109
|
|
|
return self::$mainCompany; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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