ControleOnline /
api-platform-people
| 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; |
||
|
0 ignored issues
–
show
|
|||
| 9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Securi...e\TokenStorageInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 10 | AS Security; |
||
| 11 | use ControleOnline\Entity\User; |
||
|
0 ignored issues
–
show
The type
ControleOnline\Entity\User was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | |||
| 13 | class PeopleRoleService |
||
| 14 | { |
||
| 15 | |||
| 16 | private static $mainCompany; |
||
| 17 | |||
| 18 | public function __construct( |
||
| 19 | private EntityManagerInterface $manager, |
||
| 20 | private Security $security, |
||
| 21 | private DomainService $domainService |
||
|
0 ignored issues
–
show
The type
ControleOnline\Service\DomainService was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 22 | ) {} |
||
| 23 | |||
| 24 | public function isFranchisee(People $people) |
||
| 25 | { |
||
| 26 | $mainCompany = $this->getMainCompany(); |
||
| 27 | |||
| 28 | return $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'franchisee', 1); |
||
| 29 | } |
||
| 30 | |||
| 31 | |||
| 32 | public function isSalesman(People $people) |
||
| 33 | { |
||
| 34 | $mainCompany = $this->getMainCompany(); |
||
| 35 | $isSalesman = false; |
||
|
0 ignored issues
–
show
|
|||
| 36 | |||
| 37 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'salesman', 1); |
||
| 38 | if ($isSalesman) return true; |
||
| 39 | |||
| 40 | $getPeopleCompanies = $this->manager->getRepository(PeopleLink::class)->findBy([ |
||
| 41 | 'people' => $people, |
||
| 42 | 'link_type' => 'employee' |
||
| 43 | ]); |
||
| 44 | /** |
||
| 45 | * @var \ControleOnline\Entity\PeopleLink $peopleCompany |
||
| 46 | */ |
||
| 47 | foreach ($getPeopleCompanies as $peopleCompany) { |
||
| 48 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $peopleCompany->getCompany(), 'salesman', 1); |
||
| 49 | if ($isSalesman) return true; |
||
| 50 | } |
||
| 51 | return $isSalesman; |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | public function getAllRoles(People $people): array |
||
| 56 | { |
||
| 57 | $peopleRole = []; |
||
| 58 | $mainCompany = $this->getMainCompany(); |
||
| 59 | |||
| 60 | $isSuper = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'employee', 1); |
||
| 61 | if ($isSuper) |
||
| 62 | $peopleRole[] = 'super'; |
||
| 63 | |||
| 64 | $isFranchisee = $this->isFranchisee($people); |
||
| 65 | if ($isFranchisee) { |
||
| 66 | $peopleRole[] = 'franchisee'; |
||
| 67 | $peopleRole[] = 'admin'; |
||
| 68 | } |
||
| 69 | |||
| 70 | $isClient = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'client', 1); |
||
| 71 | if ($isClient) |
||
| 72 | $peopleRole[] = 'client'; |
||
| 73 | |||
| 74 | |||
| 75 | $isSalesman = $this->isSalesman($people); |
||
| 76 | if ($isSalesman) |
||
| 77 | $peopleRole[] = 'salesman'; |
||
| 78 | |||
| 79 | |||
| 80 | return array_values(array_unique(empty($peopleRole) ? ['guest'] : $peopleRole)); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Retorna a people da empresa principal segundo o dominio da api |
||
| 85 | * |
||
| 86 | * @return People |
||
| 87 | */ |
||
| 88 | public function getMainCompany(): People |
||
| 89 | { |
||
| 90 | |||
| 91 | if (self::$mainCompany) return self::$mainCompany; |
||
| 92 | |||
| 93 | $peopleDomain = $this->domainService->getPeopleDomain(); |
||
| 94 | self::$mainCompany = $peopleDomain->getPeople(); |
||
| 95 | |||
| 96 | return self::$mainCompany; |
||
| 97 | } |
||
| 98 | } |
||
| 99 |
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