@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | private Security $security, |
| 28 | 28 | private RequestStack $requestStack, |
| 29 | 29 | ) { |
| 30 | - $this->request = $requestStack->getCurrentRequest(); |
|
| 30 | + $this->request = $requestStack->getCurrentRequest(); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function prePersist(People $people) |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function discoveryLink(People $company, People $people, $linkType): PeopleLink |
| 49 | 49 | { |
| 50 | - $peopleLink = $this->manager->getRepository(PeopleLink::class)->findOneBy([ |
|
| 50 | + $peopleLink = $this->manager->getRepository(PeopleLink::class)->findOneBy([ |
|
| 51 | 51 | 'company' => $company, |
| 52 | 52 | 'people' => $people, |
| 53 | 53 | 'link_type' => $linkType |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
| 97 | 97 | if ($phone && $phone->getPeople()) { |
| 98 | 98 | if ($phone->getPeople()->getId() != $people->getId()) |
| 99 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 99 | + throw new Exception("Phone is in use by people ".$people->getId(), 1); |
|
| 100 | 100 | } else { |
| 101 | 101 | $phone = new Phone(); |
| 102 | 102 | $phone->setDdd((int) $phone_number['ddd']); |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | return $phone; |
| 110 | 110 | } |
| 111 | - public function addDocument(People $people, string|int $document_number, ?string $document_type = null): Document |
|
| 111 | + public function addDocument(People $people, string | int $document_number, ?string $document_type = null): Document |
|
| 112 | 112 | { |
| 113 | 113 | $document = $this->getDocument($document_number, $document_type); |
| 114 | 114 | if ($document) { |
| 115 | 115 | if ($document->getPeople()->getId() != $people->getId()) |
| 116 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 116 | + throw new Exception("Document is in use by people ".$people->getId(), 1); |
|
| 117 | 117 | } else { |
| 118 | 118 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
| 119 | 119 | $document = new Document(); |
| 120 | - $document->setDocument((int)$document_number); |
|
| 120 | + $document->setDocument((int) $document_number); |
|
| 121 | 121 | $document->setDocumentType($document_type); |
| 122 | 122 | $document->setPeople($people); |
| 123 | 123 | $this->manager->persist($document); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $email = $this->getEmail($email_str); |
| 133 | 133 | if ($email && $email->getPeople()) { |
| 134 | 134 | if ($email->getPeople()->getId() != $people->getId()) |
| 135 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 135 | + throw new Exception("Email is in use by people ".$people->getId(), 1); |
|
| 136 | 136 | } else { |
| 137 | 137 | $email = new Email(); |
| 138 | 138 | $email->setEmail($email_str); |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | public function discoveryDocumentType(string $document_type): DocumentType |
| 159 | 159 | { |
| 160 | - $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
| 160 | + $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
| 161 | 161 | |
| 162 | 162 | if (!$documentType) { |
| 163 | 163 | $documentType = new DocumentType(); |
@@ -239,29 +239,29 @@ discard block |
||
| 239 | 239 | public function checkLink(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
| 240 | 240 | { |
| 241 | 241 | |
| 242 | - $link = $this->request->query->get('link', null); |
|
| 242 | + $link = $this->request->query->get('link', null); |
|
| 243 | 243 | $company = $this->request->query->get('company', null); |
| 244 | 244 | $link_type = $this->request->query->get('link_type', null); |
| 245 | 245 | |
| 246 | 246 | if ($link_type) { |
| 247 | - $queryBuilder->join(sprintf('%s.' . ($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
| 247 | + $queryBuilder->join(sprintf('%s.'.($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
| 248 | 248 | $queryBuilder->andWhere('PeopleLink.link_type IN(:link_type)'); |
| 249 | 249 | $queryBuilder->setParameter('link_type', $link_type); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | if ($company || $link) { |
| 253 | - $queryBuilder->andWhere('PeopleLink.' . ($link ? 'people' : 'company') . ' IN(:people)'); |
|
| 253 | + $queryBuilder->andWhere('PeopleLink.'.($link ? 'people' : 'company').' IN(:people)'); |
|
| 254 | 254 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", ($link ?: $company))); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | public function checkCompany($type, QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
| 258 | 258 | { |
| 259 | - $companies = $this->getMyCompanies(); |
|
| 260 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:companies)', $rootAlias, $rootAlias)); |
|
| 259 | + $companies = $this->getMyCompanies(); |
|
| 260 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:companies)', $rootAlias, $rootAlias)); |
|
| 261 | 261 | $queryBuilder->setParameter('companies', $companies); |
| 262 | 262 | |
| 263 | 263 | if ($payer = $this->request->query->get('company', null)) { |
| 264 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:people)', $rootAlias)); |
|
| 264 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:people)', $rootAlias)); |
|
| 265 | 265 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", $payer)); |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | $token = $this->security->getToken(); |
| 275 | 275 | if (!$token) return []; |
| 276 | - $currentUser = $token->getUser(); |
|
| 276 | + $currentUser = $token->getUser(); |
|
| 277 | 277 | $companies = []; |
| 278 | 278 | if (!$currentUser) return []; |
| 279 | 279 | |
@@ -53,8 +53,9 @@ discard block |
||
| 53 | 53 | 'link_type' => $linkType |
| 54 | 54 | ]); |
| 55 | 55 | |
| 56 | - if (!$peopleLink) |
|
| 57 | - $peopleLink = $this->addLink($company, $people, $linkType); |
|
| 56 | + if (!$peopleLink) { |
|
| 57 | + $peopleLink = $this->addLink($company, $people, $linkType); |
|
| 58 | + } |
|
| 58 | 59 | |
| 59 | 60 | return $peopleLink; |
| 60 | 61 | } |
@@ -62,14 +63,17 @@ discard block |
||
| 62 | 63 | public function discoveryPeople(?string $document = null, ?string $email = null, ?array $phone = [], ?string $name = null, ?string $peopleType = null): People |
| 63 | 64 | { |
| 64 | 65 | |
| 65 | - if (!empty($document)) |
|
| 66 | - $people = $this->getDocument($document)?->getPeople(); |
|
| 66 | + if (!empty($document)) { |
|
| 67 | + $people = $this->getDocument($document)?->getPeople(); |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | - if (!$people && !empty($email)) |
|
| 69 | - $people = $this->getEmail($email)?->getPeople(); |
|
| 70 | + if (!$people && !empty($email)) { |
|
| 71 | + $people = $this->getEmail($email)?->getPeople(); |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | - if (!$people && !empty($phone)) |
|
| 72 | - $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
| 74 | + if (!$people && !empty($phone)) { |
|
| 75 | + $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
| 76 | + } |
|
| 73 | 77 | |
| 74 | 78 | if (!$people) { |
| 75 | 79 | $people = new People(); |
@@ -80,12 +84,15 @@ discard block |
||
| 80 | 84 | $this->manager->flush(); |
| 81 | 85 | } |
| 82 | 86 | |
| 83 | - if ($document) |
|
| 84 | - $this->addDocument($people, $document); |
|
| 85 | - if ($email) |
|
| 86 | - $this->addEmail($people, $email); |
|
| 87 | - if ($phone) |
|
| 88 | - $this->addPhone($people, $phone); |
|
| 87 | + if ($document) { |
|
| 88 | + $this->addDocument($people, $document); |
|
| 89 | + } |
|
| 90 | + if ($email) { |
|
| 91 | + $this->addEmail($people, $email); |
|
| 92 | + } |
|
| 93 | + if ($phone) { |
|
| 94 | + $this->addPhone($people, $phone); |
|
| 95 | + } |
|
| 89 | 96 | |
| 90 | 97 | |
| 91 | 98 | return $people; |
@@ -95,8 +102,9 @@ discard block |
||
| 95 | 102 | { |
| 96 | 103 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
| 97 | 104 | if ($phone && $phone->getPeople()) { |
| 98 | - if ($phone->getPeople()->getId() != $people->getId()) |
|
| 99 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 105 | + if ($phone->getPeople()->getId() != $people->getId()) { |
|
| 106 | + throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 107 | + } |
|
| 100 | 108 | } else { |
| 101 | 109 | $phone = new Phone(); |
| 102 | 110 | $phone->setDdd((int) $phone_number['ddd']); |
@@ -112,8 +120,9 @@ discard block |
||
| 112 | 120 | { |
| 113 | 121 | $document = $this->getDocument($document_number, $document_type); |
| 114 | 122 | if ($document) { |
| 115 | - if ($document->getPeople()->getId() != $people->getId()) |
|
| 116 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 123 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
| 124 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 125 | + } |
|
| 117 | 126 | } else { |
| 118 | 127 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
| 119 | 128 | $document = new Document(); |
@@ -131,8 +140,9 @@ discard block |
||
| 131 | 140 | { |
| 132 | 141 | $email = $this->getEmail($email_str); |
| 133 | 142 | if ($email && $email->getPeople()) { |
| 134 | - if ($email->getPeople()->getId() != $people->getId()) |
|
| 135 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 143 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
| 144 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 145 | + } |
|
| 136 | 146 | } else { |
| 137 | 147 | $email = new Email(); |
| 138 | 148 | $email->setEmail($email_str); |
@@ -171,8 +181,9 @@ discard block |
||
| 171 | 181 | |
| 172 | 182 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
| 173 | 183 | { |
| 174 | - if (!$document_type) |
|
| 175 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
| 184 | + if (!$document_type) { |
|
| 185 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
| 186 | + } |
|
| 176 | 187 | return $this->manager->getRepository(Document::class)->findOneBy([ |
| 177 | 188 | 'document' => $document_number, |
| 178 | 189 | 'documentType' => |
@@ -193,18 +204,21 @@ discard block |
||
| 193 | 204 | public function postPersist(People $people) |
| 194 | 205 | { |
| 195 | 206 | $request = $this->requestStack->getCurrentRequest(); |
| 196 | - if (!$request) return; |
|
| 207 | + if (!$request) { |
|
| 208 | + return; |
|
| 209 | + } |
|
| 197 | 210 | $payload = json_decode($request->getContent()); |
| 198 | 211 | if (isset($payload->link_type)) { |
| 199 | 212 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
| 200 | - if ($company) |
|
| 201 | - $this->discoveryLink($company, $people, $payload->link_type); |
|
| 202 | - else { |
|
| 213 | + if ($company) { |
|
| 214 | + $this->discoveryLink($company, $people, $payload->link_type); |
|
| 215 | + } else { |
|
| 203 | 216 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
| 204 | 217 | if ($payload->link_type == 'employee' && $link) { |
| 205 | 218 | $this->discoveryLink($people, $link, $payload->link_type); |
| 206 | - if ($payload->people_document) |
|
| 207 | - $this->addDocument($people, $payload->people_document); |
|
| 219 | + if ($payload->people_document) { |
|
| 220 | + $this->addDocument($people, $payload->people_document); |
|
| 221 | + } |
|
| 208 | 222 | } |
| 209 | 223 | } |
| 210 | 224 | } |
@@ -219,8 +233,9 @@ discard block |
||
| 219 | 233 | 'link_type' => $link_type |
| 220 | 234 | ]); |
| 221 | 235 | |
| 222 | - if (!$peopleLink) |
|
| 223 | - $peopleLink = new PeopleLink(); |
|
| 236 | + if (!$peopleLink) { |
|
| 237 | + $peopleLink = new PeopleLink(); |
|
| 238 | + } |
|
| 224 | 239 | |
| 225 | 240 | $peopleLink->setCompany($company); |
| 226 | 241 | $peopleLink->setPeople($people); |
@@ -272,10 +287,14 @@ discard block |
||
| 272 | 287 | * @var \ControleOnline\Entity\User $currentUser |
| 273 | 288 | */ |
| 274 | 289 | $token = $this->security->getToken(); |
| 275 | - if (!$token) return []; |
|
| 290 | + if (!$token) { |
|
| 291 | + return []; |
|
| 292 | + } |
|
| 276 | 293 | $currentUser = $token->getUser(); |
| 277 | 294 | $companies = []; |
| 278 | - if (!$currentUser) return []; |
|
| 295 | + if (!$currentUser) { |
|
| 296 | + return []; |
|
| 297 | + } |
|
| 279 | 298 | |
| 280 | 299 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
| 281 | 300 | foreach ($currentUser->getPeople()->getLink() as $company) { |