@@ -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['ddi'], $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->setDdi((int) $phone_number['ddi']); |
@@ -109,16 +109,16 @@ discard block |
||
109 | 109 | |
110 | 110 | return $phone; |
111 | 111 | } |
112 | - public function addDocument(People $people, string|int $document_number, ?string $document_type = null): Document |
|
112 | + public function addDocument(People $people, string | int $document_number, ?string $document_type = null): Document |
|
113 | 113 | { |
114 | 114 | $document = $this->getDocument($document_number, $document_type); |
115 | 115 | if ($document) { |
116 | 116 | if ($document->getPeople()->getId() != $people->getId()) |
117 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
117 | + throw new Exception("Document is in use by people ".$people->getId(), 1); |
|
118 | 118 | } else { |
119 | 119 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
120 | 120 | $document = new Document(); |
121 | - $document->setDocument((int)$document_number); |
|
121 | + $document->setDocument((int) $document_number); |
|
122 | 122 | $document->setDocumentType($document_type); |
123 | 123 | $document->setPeople($people); |
124 | 124 | $this->manager->persist($document); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $email = $this->getEmail($email_str); |
134 | 134 | if ($email && $email->getPeople()) { |
135 | 135 | if ($email->getPeople()->getId() != $people->getId()) |
136 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
136 | + throw new Exception("Email is in use by people ".$people->getId(), 1); |
|
137 | 137 | } else { |
138 | 138 | $email = new Email(); |
139 | 139 | $email->setEmail($email_str); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | |
163 | 163 | public function discoveryDocumentType(string $document_type): DocumentType |
164 | 164 | { |
165 | - $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
165 | + $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
166 | 166 | |
167 | 167 | if (!$documentType) { |
168 | 168 | $documentType = new DocumentType(); |
@@ -244,29 +244,29 @@ discard block |
||
244 | 244 | public function checkLink(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
245 | 245 | { |
246 | 246 | |
247 | - $link = $this->request->query->get('link', null); |
|
247 | + $link = $this->request->query->get('link', null); |
|
248 | 248 | $company = $this->request->query->get('company', null); |
249 | 249 | $link_type = $this->request->query->get('link_type', null); |
250 | 250 | |
251 | 251 | if ($link_type) { |
252 | - $queryBuilder->join(sprintf('%s.' . ($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
252 | + $queryBuilder->join(sprintf('%s.'.($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
253 | 253 | $queryBuilder->andWhere('PeopleLink.link_type IN(:link_type)'); |
254 | 254 | $queryBuilder->setParameter('link_type', $link_type); |
255 | 255 | } |
256 | 256 | |
257 | 257 | if ($company || $link) { |
258 | - $queryBuilder->andWhere('PeopleLink.' . ($link ? 'people' : 'company') . ' IN(:people)'); |
|
258 | + $queryBuilder->andWhere('PeopleLink.'.($link ? 'people' : 'company').' IN(:people)'); |
|
259 | 259 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", ($link ?: $company))); |
260 | 260 | } |
261 | 261 | } |
262 | 262 | public function checkCompany($type, QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
263 | 263 | { |
264 | - $companies = $this->getMyCompanies(); |
|
265 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:companies)', $rootAlias, $rootAlias)); |
|
264 | + $companies = $this->getMyCompanies(); |
|
265 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:companies)', $rootAlias, $rootAlias)); |
|
266 | 266 | $queryBuilder->setParameter('companies', $companies); |
267 | 267 | |
268 | 268 | if ($payer = $this->request->query->get('company', null)) { |
269 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:people)', $rootAlias)); |
|
269 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:people)', $rootAlias)); |
|
270 | 270 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", $payer)); |
271 | 271 | } |
272 | 272 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | $token = $this->security->getToken(); |
280 | 280 | if (!$token) return []; |
281 | - $currentUser = $token->getUser(); |
|
281 | + $currentUser = $token->getUser(); |
|
282 | 282 | $companies = []; |
283 | 283 | if (!$currentUser) return []; |
284 | 284 |
@@ -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['ddi'], $phone['ddd'], $phone['phone'])?->getPeople(); |
|
74 | + if (!$people && !empty($phone)) { |
|
75 | + $people = $this->getPhone($phone['ddi'], $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['ddi'], $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->setDdi((int) $phone_number['ddi']); |
@@ -113,8 +121,9 @@ discard block |
||
113 | 121 | { |
114 | 122 | $document = $this->getDocument($document_number, $document_type); |
115 | 123 | if ($document) { |
116 | - if ($document->getPeople()->getId() != $people->getId()) |
|
117 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
124 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
125 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
126 | + } |
|
118 | 127 | } else { |
119 | 128 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
120 | 129 | $document = new Document(); |
@@ -132,8 +141,9 @@ discard block |
||
132 | 141 | { |
133 | 142 | $email = $this->getEmail($email_str); |
134 | 143 | if ($email && $email->getPeople()) { |
135 | - if ($email->getPeople()->getId() != $people->getId()) |
|
136 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
144 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
145 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
146 | + } |
|
137 | 147 | } else { |
138 | 148 | $email = new Email(); |
139 | 149 | $email->setEmail($email_str); |
@@ -176,8 +186,9 @@ discard block |
||
176 | 186 | |
177 | 187 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
178 | 188 | { |
179 | - if (!$document_type) |
|
180 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
189 | + if (!$document_type) { |
|
190 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
191 | + } |
|
181 | 192 | return $this->manager->getRepository(Document::class)->findOneBy([ |
182 | 193 | 'document' => $document_number, |
183 | 194 | 'documentType' => |
@@ -198,18 +209,21 @@ discard block |
||
198 | 209 | public function postPersist(People $people) |
199 | 210 | { |
200 | 211 | $request = $this->requestStack->getCurrentRequest(); |
201 | - if (!$request) return; |
|
212 | + if (!$request) { |
|
213 | + return; |
|
214 | + } |
|
202 | 215 | $payload = json_decode($request->getContent()); |
203 | 216 | if (isset($payload->link_type)) { |
204 | 217 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
205 | - if ($company) |
|
206 | - $this->discoveryLink($company, $people, $payload->link_type); |
|
207 | - else { |
|
218 | + if ($company) { |
|
219 | + $this->discoveryLink($company, $people, $payload->link_type); |
|
220 | + } else { |
|
208 | 221 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
209 | 222 | if ($payload->link_type == 'employee' && $link) { |
210 | 223 | $this->discoveryLink($people, $link, $payload->link_type); |
211 | - if ($payload->people_document) |
|
212 | - $this->addDocument($people, $payload->people_document); |
|
224 | + if ($payload->people_document) { |
|
225 | + $this->addDocument($people, $payload->people_document); |
|
226 | + } |
|
213 | 227 | } |
214 | 228 | } |
215 | 229 | } |
@@ -224,8 +238,9 @@ discard block |
||
224 | 238 | 'link_type' => $link_type |
225 | 239 | ]); |
226 | 240 | |
227 | - if (!$peopleLink) |
|
228 | - $peopleLink = new PeopleLink(); |
|
241 | + if (!$peopleLink) { |
|
242 | + $peopleLink = new PeopleLink(); |
|
243 | + } |
|
229 | 244 | |
230 | 245 | $peopleLink->setCompany($company); |
231 | 246 | $peopleLink->setPeople($people); |
@@ -277,10 +292,14 @@ discard block |
||
277 | 292 | * @var \ControleOnline\Entity\User $currentUser |
278 | 293 | */ |
279 | 294 | $token = $this->security->getToken(); |
280 | - if (!$token) return []; |
|
295 | + if (!$token) { |
|
296 | + return []; |
|
297 | + } |
|
281 | 298 | $currentUser = $token->getUser(); |
282 | 299 | $companies = []; |
283 | - if (!$currentUser) return []; |
|
300 | + if (!$currentUser) { |
|
301 | + return []; |
|
302 | + } |
|
284 | 303 | |
285 | 304 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
286 | 305 | foreach ($currentUser->getPeople()->getLink() as $company) { |