ControleOnline /
api-platform-people
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ControleOnline\Controller; |
||
| 4 | |||
| 5 | use ControleOnline\Entity\Config; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use ControleOnline\Entity\People; |
||
| 7 | use ControleOnline\Entity\PeopleDomain; |
||
| 8 | use ControleOnline\Entity\PeopleLink; |
||
| 9 | use ControleOnline\Entity\PeoplePackage; |
||
| 10 | use ControleOnline\Service\PeopleRoleService; |
||
| 11 | use ControleOnline\Entity\PackageModules; |
||
| 12 | use ControleOnline\Service\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...
|
|||
| 13 | use ControleOnline\Service\FileService; |
||
|
0 ignored issues
–
show
The type
ControleOnline\Service\FileService 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...
|
|||
| 14 | use Doctrine\ORM\EntityManagerInterface; |
||
|
0 ignored issues
–
show
The type
Doctrine\ORM\EntityManagerInterface 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...
|
|||
| 15 | 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...
|
|||
| 16 | AS Security; |
||
| 17 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\JsonResponse 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...
|
|||
| 18 | use Symfony\Component\HttpFoundation\Request; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Request 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...
|
|||
| 19 | |||
| 20 | class GetMyCompaniesAction |
||
| 21 | { |
||
| 22 | |||
| 23 | |||
| 24 | public function __construct( |
||
| 25 | private Security $security, |
||
| 26 | private EntityManagerInterface $em, |
||
| 27 | private DomainService $domainService, |
||
| 28 | private PeopleRoleService $roles, |
||
| 29 | private FileService $fileService |
||
| 30 | ) {} |
||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | public function __invoke(Request $request): JsonResponse |
||
| 36 | { |
||
| 37 | try { |
||
| 38 | $myCompanies = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \ControleOnline\Entity\User |
||
| 42 | */ |
||
| 43 | $currentUser = $this->security->getToken()->getUser(); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var \ControleOnline\Entity\People |
||
| 47 | */ |
||
| 48 | $userPeople = $currentUser->getPeople(); |
||
| 49 | $permissions = []; |
||
| 50 | |||
| 51 | |||
| 52 | $getPeopleCompanies = $userPeople->getLink(); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var \ControleOnline\Entity\PeopleLink $peopleCompany |
||
| 56 | */ |
||
| 57 | foreach ($getPeopleCompanies as $peopleCompany) { |
||
| 58 | |||
| 59 | $allConfigs = []; |
||
|
0 ignored issues
–
show
|
|||
| 60 | $configs = []; |
||
| 61 | $people = $peopleCompany->getCompany(); |
||
| 62 | |||
| 63 | //if ($peopleCompany->getEnabled() && $people->getEnabled()) { |
||
| 64 | |||
| 65 | $domains = $this->getPeopleDomains($people); |
||
| 66 | $packages = $this->getPeoplePackages($people); |
||
| 67 | |||
| 68 | |||
| 69 | $permissions[$people->getId()] = $this->roles->getAllRoles($people); |
||
| 70 | |||
| 71 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 72 | 'people' => $people->getId(), |
||
| 73 | 'visibility' => 'public' |
||
| 74 | ]); |
||
| 75 | foreach ($allConfigs as $config) { |
||
| 76 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | $myCompanies[$people->getId()] = [ |
||
| 81 | 'id' => $people->getId(), |
||
| 82 | 'enabled' => $people->getEnabled(), |
||
| 83 | 'alias' => $people->getAlias(), |
||
| 84 | 'logo' => $this->fileService->getFileUrl($people), |
||
| 85 | 'document' => $this->getDocument($people), |
||
| 86 | 'domains' => $domains, |
||
| 87 | 'configs' => $configs, |
||
| 88 | 'packages' => $packages, |
||
| 89 | 'user' => [ |
||
| 90 | 'id' => $userPeople->getId(), |
||
| 91 | 'name' => $userPeople->getName(), |
||
| 92 | 'alias' => $userPeople->getAlias(), |
||
| 93 | 'enabled' => $userPeople->getEnabled(), |
||
| 94 | 'employee_enabled' => $peopleCompany->getEnabled(), |
||
| 95 | 'salesman_enabled' => false |
||
| 96 | ] |
||
| 97 | ]; |
||
| 98 | //} |
||
| 99 | } |
||
| 100 | |||
| 101 | $peopleSalesman = $this->em->getRepository(People::class)->getPeopleLinks($userPeople, 'salesman'); |
||
| 102 | |||
| 103 | foreach ($peopleSalesman as $com) { |
||
| 104 | $company = $this->em->getRepository(People::class)->find($com['people_id']); |
||
| 105 | $allConfigs = []; |
||
| 106 | $configs = []; |
||
| 107 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 108 | 'people' => $company->getId(), |
||
| 109 | 'visibility' => 'public' |
||
| 110 | ]); |
||
| 111 | foreach ($allConfigs as $config) { |
||
| 112 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($company) { |
||
| 116 | $people_domains = $this->em->getRepository(PeopleDomain::class)->findBy(['people' => $com['people_id']]); |
||
| 117 | |||
| 118 | $domains = []; |
||
| 119 | |||
| 120 | if (!empty($people_domains)) { |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var PeopleDomain $company |
||
| 124 | */ |
||
| 125 | foreach ($people_domains as $domain) { |
||
| 126 | |||
| 127 | $domains[] = [ |
||
| 128 | 'id' => $domain->getId(), |
||
| 129 | 'domainType' => $domain->getDomainType(), |
||
| 130 | 'domain' => $domain->getDomain() |
||
| 131 | ]; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $peopleemployee = $this->em->getRepository(PeopleLink::class)->findOneBy(['company' => $company, 'employee' => $userPeople]); |
||
| 136 | |||
| 137 | $permissions[$company->getId()][] = 'salesman'; |
||
| 138 | $myCompanies[$company->getId()] = [ |
||
| 139 | 'id' => $company->getId(), |
||
| 140 | 'enabled' => $company->getEnabled(), |
||
| 141 | 'alias' => $company->getAlias(), |
||
| 142 | 'logo' => $this->fileService->getFileUrl($company), |
||
| 143 | 'document' => $this->getDocument($company), |
||
| 144 | 'commission' => $com['commission'], |
||
| 145 | 'domains' => $domains, |
||
| 146 | 'configs' => $configs, |
||
| 147 | 'user' => [ |
||
| 148 | 'id' => $userPeople->getId(), |
||
| 149 | 'name' => $userPeople->getName(), |
||
| 150 | 'alias' => $userPeople->getAlias(), |
||
| 151 | 'enabled' => $userPeople->getEnabled(), |
||
| 152 | 'employee_enabled' => $peopleemployee ? $peopleemployee->getEnabled() : $com['enable'], |
||
| 153 | 'salesman_enabled' => $com['enable'] |
||
| 154 | ] |
||
| 155 | ]; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | foreach ($permissions as $key => $permission) { |
||
| 160 | $myCompanies[$key]['permission'] = array_values($permission); |
||
| 161 | } |
||
| 162 | |||
| 163 | usort($myCompanies, function ($a, $b) { |
||
| 164 | |||
| 165 | if ($a['alias'] == $b['alias']) { |
||
| 166 | return 0; |
||
| 167 | } |
||
| 168 | return ($a['alias'] < $b['alias']) ? -1 : 1; |
||
| 169 | }); |
||
| 170 | |||
| 171 | return new JsonResponse([ |
||
| 172 | 'response' => [ |
||
| 173 | 'data' => $myCompanies, |
||
| 174 | 'count' => count($myCompanies), |
||
| 175 | 'error' => '', |
||
| 176 | 'success' => true, |
||
| 177 | ], |
||
| 178 | ]); |
||
| 179 | } catch (\Exception $e) { |
||
| 180 | |||
| 181 | return new JsonResponse([ |
||
| 182 | 'response' => [ |
||
| 183 | 'data' => [], |
||
| 184 | 'count' => 0, |
||
| 185 | 'error' => $e->getMessage(), |
||
| 186 | 'success' => false, |
||
| 187 | ], |
||
| 188 | ]); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | private function getPeoplePackages($people) |
||
| 192 | { |
||
| 193 | |||
| 194 | |||
| 195 | $people_packages = $this->em->getRepository(PeoplePackage::class)->findBy(['people' => $people]); |
||
| 196 | $packages = []; |
||
| 197 | $p_m = []; |
||
| 198 | |||
| 199 | |||
| 200 | foreach ($people_packages as $people_package) { |
||
| 201 | $package = $people_package->getPackage(); |
||
| 202 | $package_modules = $this->em->getRepository(PackageModules::class)->findBy(['package' => $package]); |
||
| 203 | |||
| 204 | foreach ($package_modules as $package_module) { |
||
| 205 | $p_m[$package_module->getId()]['users'] = $package_module->getUsers(); |
||
| 206 | $p_m[$package_module->getId()]['module'] = $package_module->getModule()->getName(); |
||
| 207 | } |
||
| 208 | |||
| 209 | $packages[$people_package->getId()]['id'] = $people_package->getId(); |
||
| 210 | $packages[$people_package->getId()]['package']['id'] = $package->getId(); |
||
| 211 | $packages[$people_package->getId()]['package']['name'] = $package->getName(); |
||
| 212 | $packages[$people_package->getId()]['package']['active'] = $package->isActive() ? true : false; |
||
| 213 | $packages[$people_package->getId()]['package']['modules'] = $p_m; |
||
| 214 | } |
||
| 215 | |||
| 216 | return $packages; |
||
| 217 | } |
||
| 218 | |||
| 219 | private function getPeopleDomains($people) |
||
| 220 | { |
||
| 221 | $people_domains = $this->em->getRepository(PeopleDomain::class)->findBy(['people' => $people->getId()]); |
||
| 222 | $domains = []; |
||
| 223 | |||
| 224 | if (!empty($people_domains)) { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @var PeopleDomain $company |
||
| 228 | */ |
||
| 229 | foreach ($people_domains as $domain) { |
||
| 230 | |||
| 231 | $domains[] = [ |
||
| 232 | 'id' => $domain->getId(), |
||
| 233 | 'domainType' => $domain->getDomainType(), |
||
| 234 | 'domain' => $domain->getDomain() |
||
| 235 | ]; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | return $domains; |
||
| 239 | } |
||
| 240 | |||
| 241 | private function getDocument(People $company): ?string |
||
| 242 | { |
||
| 243 | $documents = $company->getDocument(); |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @var \ControleOnline\Entity\Document $document |
||
| 247 | */ |
||
| 248 | $documents = $documents->filter(function ($document) { |
||
| 249 | return $document->getDocumentType()->getDocumentType() == 'CNPJ'; |
||
| 250 | }); |
||
| 251 | |||
| 252 | return $documents->first() !== false ? $documents->first()->getDocument() : null; |
||
| 253 | } |
||
| 254 | } |
||
| 255 |
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