@@ -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) |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
79 | 79 | if ($phone && $phone->getPeople()) { |
80 | 80 | if ($phone->getPeople()->getId() != $people->getId()) |
81 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
81 | + throw new Exception("Phone is in use by people ".$people->getId(), 1); |
|
82 | 82 | } else { |
83 | 83 | $phone = new Phone(); |
84 | 84 | $phone->setDdd($phone_number['ddd']); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $document = $this->getDocument($document_number, $document_type); |
96 | 96 | if ($document) { |
97 | 97 | if ($document->getPeople()->getId() != $people->getId()) |
98 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
98 | + throw new Exception("Document is in use by people ".$people->getId(), 1); |
|
99 | 99 | } else { |
100 | 100 | $document = new Document(); |
101 | 101 | $document->setDocument($document_number); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $email = $this->getEmail($email_str); |
114 | 114 | if ($email && $email->getPeople()) { |
115 | 115 | if ($email->getPeople()->getId() != $people->getId()) |
116 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
116 | + throw new Exception("Email is in use by people ".$people->getId(), 1); |
|
117 | 117 | } else { |
118 | 118 | $email = new Email(); |
119 | 119 | $email->setEmail($email_str); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | public function discoveryDocumentType(string $document_type): DocumentType |
140 | 140 | { |
141 | - $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['document_type' => $document_type]); |
|
141 | + $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['document_type' => $document_type]); |
|
142 | 142 | |
143 | 143 | if (!$documentType) { |
144 | 144 | $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 |
@@ -47,11 +47,13 @@ discard block |
||
47 | 47 | |
48 | 48 | $people = $this->getDocument($document)?->getPeople(); |
49 | 49 | |
50 | - if (!$people) |
|
51 | - $people = $this->getEmail($email)?->getPeople(); |
|
50 | + if (!$people) { |
|
51 | + $people = $this->getEmail($email)?->getPeople(); |
|
52 | + } |
|
52 | 53 | |
53 | - if (!$people) |
|
54 | - $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
54 | + if (!$people) { |
|
55 | + $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
56 | + } |
|
55 | 57 | |
56 | 58 | if (!$people) { |
57 | 59 | $people = new People(); |
@@ -62,12 +64,15 @@ discard block |
||
62 | 64 | $this->manager->flush(); |
63 | 65 | } |
64 | 66 | |
65 | - if ($document) |
|
66 | - $this->addDocument($people, $document); |
|
67 | - if ($email) |
|
68 | - $this->addEmail($people, $email); |
|
69 | - if ($phone) |
|
70 | - $this->addPhone($people, $phone); |
|
67 | + if ($document) { |
|
68 | + $this->addDocument($people, $document); |
|
69 | + } |
|
70 | + if ($email) { |
|
71 | + $this->addEmail($people, $email); |
|
72 | + } |
|
73 | + if ($phone) { |
|
74 | + $this->addPhone($people, $phone); |
|
75 | + } |
|
71 | 76 | |
72 | 77 | |
73 | 78 | return $people; |
@@ -77,8 +82,9 @@ discard block |
||
77 | 82 | { |
78 | 83 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
79 | 84 | if ($phone && $phone->getPeople()) { |
80 | - if ($phone->getPeople()->getId() != $people->getId()) |
|
81 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
85 | + if ($phone->getPeople()->getId() != $people->getId()) { |
|
86 | + throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
87 | + } |
|
82 | 88 | } else { |
83 | 89 | $phone = new Phone(); |
84 | 90 | $phone->setDdd($phone_number['ddd']); |
@@ -94,8 +100,9 @@ discard block |
||
94 | 100 | { |
95 | 101 | $document = $this->getDocument($document_number, $document_type); |
96 | 102 | if ($document) { |
97 | - if ($document->getPeople()->getId() != $people->getId()) |
|
98 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
103 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
104 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
105 | + } |
|
99 | 106 | } else { |
100 | 107 | $document = new Document(); |
101 | 108 | $document->setDocument($document_number); |
@@ -112,8 +119,9 @@ discard block |
||
112 | 119 | { |
113 | 120 | $email = $this->getEmail($email_str); |
114 | 121 | if ($email && $email->getPeople()) { |
115 | - if ($email->getPeople()->getId() != $people->getId()) |
|
116 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
122 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
123 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
124 | + } |
|
117 | 125 | } else { |
118 | 126 | $email = new Email(); |
119 | 127 | $email->setEmail($email_str); |
@@ -152,8 +160,9 @@ discard block |
||
152 | 160 | |
153 | 161 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
154 | 162 | { |
155 | - if (!$document_type) |
|
156 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
163 | + if (!$document_type) { |
|
164 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
165 | + } |
|
157 | 166 | return $this->manager->getRepository(Document::class)->findOneBy([ |
158 | 167 | 'document' => $document_number, |
159 | 168 | 'documentType' => |
@@ -172,9 +181,9 @@ discard block |
||
172 | 181 | $payload = json_decode($request->getContent()); |
173 | 182 | if (isset($payload->link_type)) { |
174 | 183 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
175 | - if ($company) |
|
176 | - $this->addLink($company, $people, $payload->link_type); |
|
177 | - else { |
|
184 | + if ($company) { |
|
185 | + $this->addLink($company, $people, $payload->link_type); |
|
186 | + } else { |
|
178 | 187 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
179 | 188 | if ($payload->link_type == 'employee' && $link) { |
180 | 189 | $this->addLink($people, $link, $payload->link_type); |
@@ -202,8 +211,9 @@ discard block |
||
202 | 211 | 'link_type' => $link_type |
203 | 212 | ]); |
204 | 213 | |
205 | - if (!$peopleLink) |
|
206 | - $peopleLink = new PeopleLink(); |
|
214 | + if (!$peopleLink) { |
|
215 | + $peopleLink = new PeopleLink(); |
|
216 | + } |
|
207 | 217 | |
208 | 218 | $peopleLink->setCompany($company); |
209 | 219 | $peopleLink->setPeople($people); |
@@ -255,10 +265,14 @@ discard block |
||
255 | 265 | * @var \ControleOnline\Entity\User $currentUser |
256 | 266 | */ |
257 | 267 | $token = $this->security->getToken(); |
258 | - if (!$token) return []; |
|
268 | + if (!$token) { |
|
269 | + return []; |
|
270 | + } |
|
259 | 271 | $currentUser = $token->getUser(); |
260 | 272 | $companies = []; |
261 | - if (!$currentUser) return []; |
|
273 | + if (!$currentUser) { |
|
274 | + return []; |
|
275 | + } |
|
262 | 276 | |
263 | 277 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
264 | 278 | foreach ($currentUser->getPeople()->getLink() as $company) { |