@@ -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) |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
80 | 80 | if ($phone && $phone->getPeople()) { |
81 | 81 | if ($phone->getPeople()->getId() != $people->getId()) |
82 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
82 | + throw new Exception("Phone is in use by people ".$people->getId(), 1); |
|
83 | 83 | } else { |
84 | 84 | $phone = new Phone(); |
85 | 85 | $phone->setDdd((int) $phone_number['ddd']); |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | |
92 | 92 | return $phone; |
93 | 93 | } |
94 | - public function addDocument(People $people, string|int $document_number, ?string $document_type = null): Document |
|
94 | + public function addDocument(People $people, string | int $document_number, ?string $document_type = null): Document |
|
95 | 95 | { |
96 | 96 | $document = $this->getDocument($document_number, $document_type); |
97 | 97 | if ($document) { |
98 | 98 | if ($document->getPeople()->getId() != $people->getId()) |
99 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
99 | + throw new Exception("Document is in use by people ".$people->getId(), 1); |
|
100 | 100 | } else { |
101 | 101 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
102 | 102 | $document = new Document(); |
103 | - $document->setDocument((int)$document_number); |
|
103 | + $document->setDocument((int) $document_number); |
|
104 | 104 | $document->setDocumentType($document_type); |
105 | 105 | $document->setPeople($people); |
106 | 106 | $this->manager->persist($document); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $email = $this->getEmail($email_str); |
116 | 116 | if ($email && $email->getPeople()) { |
117 | 117 | if ($email->getPeople()->getId() != $people->getId()) |
118 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
118 | + throw new Exception("Email is in use by people ".$people->getId(), 1); |
|
119 | 119 | } else { |
120 | 120 | $email = new Email(); |
121 | 121 | $email->setEmail($email_str); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | public function discoveryDocumentType(string $document_type): DocumentType |
142 | 142 | { |
143 | - $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
143 | + $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
144 | 144 | |
145 | 145 | if (!$documentType) { |
146 | 146 | $documentType = new DocumentType(); |
@@ -222,29 +222,29 @@ discard block |
||
222 | 222 | public function checkLink(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
223 | 223 | { |
224 | 224 | |
225 | - $link = $this->request->query->get('link', null); |
|
225 | + $link = $this->request->query->get('link', null); |
|
226 | 226 | $company = $this->request->query->get('company', null); |
227 | 227 | $link_type = $this->request->query->get('link_type', null); |
228 | 228 | |
229 | 229 | if ($link_type) { |
230 | - $queryBuilder->join(sprintf('%s.' . ($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
230 | + $queryBuilder->join(sprintf('%s.'.($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
231 | 231 | $queryBuilder->andWhere('PeopleLink.link_type IN(:link_type)'); |
232 | 232 | $queryBuilder->setParameter('link_type', $link_type); |
233 | 233 | } |
234 | 234 | |
235 | 235 | if ($company || $link) { |
236 | - $queryBuilder->andWhere('PeopleLink.' . ($link ? 'people' : 'company') . ' IN(:people)'); |
|
236 | + $queryBuilder->andWhere('PeopleLink.'.($link ? 'people' : 'company').' IN(:people)'); |
|
237 | 237 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", ($link ?: $company))); |
238 | 238 | } |
239 | 239 | } |
240 | 240 | public function checkCompany($type, QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
241 | 241 | { |
242 | - $companies = $this->getMyCompanies(); |
|
243 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:companies)', $rootAlias, $rootAlias)); |
|
242 | + $companies = $this->getMyCompanies(); |
|
243 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:companies)', $rootAlias, $rootAlias)); |
|
244 | 244 | $queryBuilder->setParameter('companies', $companies); |
245 | 245 | |
246 | 246 | if ($payer = $this->request->query->get('company', null)) { |
247 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:people)', $rootAlias)); |
|
247 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:people)', $rootAlias)); |
|
248 | 248 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", $payer)); |
249 | 249 | } |
250 | 250 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | $token = $this->security->getToken(); |
258 | 258 | if (!$token) return []; |
259 | - $currentUser = $token->getUser(); |
|
259 | + $currentUser = $token->getUser(); |
|
260 | 260 | $companies = []; |
261 | 261 | if (!$currentUser) return []; |
262 | 262 |
@@ -45,14 +45,17 @@ discard block |
||
45 | 45 | public function discoveryPeople(?string $document = null, ?string $email = null, ?array $phone = [], ?string $name = null, ?string $peopleType = null): People |
46 | 46 | { |
47 | 47 | |
48 | - if (!empty($document)) |
|
49 | - $people = $this->getDocument($document)?->getPeople(); |
|
48 | + if (!empty($document)) { |
|
49 | + $people = $this->getDocument($document)?->getPeople(); |
|
50 | + } |
|
50 | 51 | |
51 | - if (!$people && !empty($email)) |
|
52 | - $people = $this->getEmail($email)?->getPeople(); |
|
52 | + if (!$people && !empty($email)) { |
|
53 | + $people = $this->getEmail($email)?->getPeople(); |
|
54 | + } |
|
53 | 55 | |
54 | - if (!$people && !empty($phone)) |
|
55 | - $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
56 | + if (!$people && !empty($phone)) { |
|
57 | + $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
58 | + } |
|
56 | 59 | |
57 | 60 | if (!$people) { |
58 | 61 | $people = new People(); |
@@ -63,12 +66,15 @@ discard block |
||
63 | 66 | $this->manager->flush(); |
64 | 67 | } |
65 | 68 | |
66 | - if ($document) |
|
67 | - $this->addDocument($people, $document); |
|
68 | - if ($email) |
|
69 | - $this->addEmail($people, $email); |
|
70 | - if ($phone) |
|
71 | - $this->addPhone($people, $phone); |
|
69 | + if ($document) { |
|
70 | + $this->addDocument($people, $document); |
|
71 | + } |
|
72 | + if ($email) { |
|
73 | + $this->addEmail($people, $email); |
|
74 | + } |
|
75 | + if ($phone) { |
|
76 | + $this->addPhone($people, $phone); |
|
77 | + } |
|
72 | 78 | |
73 | 79 | |
74 | 80 | return $people; |
@@ -78,8 +84,9 @@ discard block |
||
78 | 84 | { |
79 | 85 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
80 | 86 | if ($phone && $phone->getPeople()) { |
81 | - if ($phone->getPeople()->getId() != $people->getId()) |
|
82 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
87 | + if ($phone->getPeople()->getId() != $people->getId()) { |
|
88 | + throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
89 | + } |
|
83 | 90 | } else { |
84 | 91 | $phone = new Phone(); |
85 | 92 | $phone->setDdd((int) $phone_number['ddd']); |
@@ -95,8 +102,9 @@ discard block |
||
95 | 102 | { |
96 | 103 | $document = $this->getDocument($document_number, $document_type); |
97 | 104 | if ($document) { |
98 | - if ($document->getPeople()->getId() != $people->getId()) |
|
99 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
105 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
106 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
107 | + } |
|
100 | 108 | } else { |
101 | 109 | $document_type = $document_type ? $this->discoveryDocumentType($document_type) : $this->discoveryDocumentType($this->getDocumentTypeByDocumentLen($document_number)); |
102 | 110 | $document = new Document(); |
@@ -114,8 +122,9 @@ discard block |
||
114 | 122 | { |
115 | 123 | $email = $this->getEmail($email_str); |
116 | 124 | if ($email && $email->getPeople()) { |
117 | - if ($email->getPeople()->getId() != $people->getId()) |
|
118 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
125 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
126 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
127 | + } |
|
119 | 128 | } else { |
120 | 129 | $email = new Email(); |
121 | 130 | $email->setEmail($email_str); |
@@ -154,8 +163,9 @@ discard block |
||
154 | 163 | |
155 | 164 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
156 | 165 | { |
157 | - if (!$document_type) |
|
158 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
166 | + if (!$document_type) { |
|
167 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
168 | + } |
|
159 | 169 | return $this->manager->getRepository(Document::class)->findOneBy([ |
160 | 170 | 'document' => $document_number, |
161 | 171 | 'documentType' => |
@@ -176,18 +186,21 @@ discard block |
||
176 | 186 | public function postPersist(People $people) |
177 | 187 | { |
178 | 188 | $request = $this->requestStack->getCurrentRequest(); |
179 | - if (!$request) return; |
|
189 | + if (!$request) { |
|
190 | + return; |
|
191 | + } |
|
180 | 192 | $payload = json_decode($request->getContent()); |
181 | 193 | if (isset($payload->link_type)) { |
182 | 194 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
183 | - if ($company) |
|
184 | - $this->addLink($company, $people, $payload->link_type); |
|
185 | - else { |
|
195 | + if ($company) { |
|
196 | + $this->addLink($company, $people, $payload->link_type); |
|
197 | + } else { |
|
186 | 198 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
187 | 199 | if ($payload->link_type == 'employee' && $link) { |
188 | 200 | $this->addLink($people, $link, $payload->link_type); |
189 | - if ($payload->people_document) |
|
190 | - $this->addDocument($people, $payload->people_document); |
|
201 | + if ($payload->people_document) { |
|
202 | + $this->addDocument($people, $payload->people_document); |
|
203 | + } |
|
191 | 204 | } |
192 | 205 | } |
193 | 206 | } |
@@ -202,8 +215,9 @@ discard block |
||
202 | 215 | 'link_type' => $link_type |
203 | 216 | ]); |
204 | 217 | |
205 | - if (!$peopleLink) |
|
206 | - $peopleLink = new PeopleLink(); |
|
218 | + if (!$peopleLink) { |
|
219 | + $peopleLink = new PeopleLink(); |
|
220 | + } |
|
207 | 221 | |
208 | 222 | $peopleLink->setCompany($company); |
209 | 223 | $peopleLink->setPeople($people); |
@@ -255,10 +269,14 @@ discard block |
||
255 | 269 | * @var \ControleOnline\Entity\User $currentUser |
256 | 270 | */ |
257 | 271 | $token = $this->security->getToken(); |
258 | - if (!$token) return []; |
|
272 | + if (!$token) { |
|
273 | + return []; |
|
274 | + } |
|
259 | 275 | $currentUser = $token->getUser(); |
260 | 276 | $companies = []; |
261 | - if (!$currentUser) return []; |
|
277 | + if (!$currentUser) { |
|
278 | + return []; |
|
279 | + } |
|
262 | 280 | |
263 | 281 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
264 | 282 | foreach ($currentUser->getPeople()->getLink() as $company) { |