@@ -113,8 +113,9 @@ |
||
| 113 | 113 | |
| 114 | 114 | return true; |
| 115 | 115 | } catch (\Exception $e) { |
| 116 | - if ($this->manager->getConnection()->isTransactionActive()) |
|
| 117 | - $this->manager->getConnection()->rollBack(); |
|
| 116 | + if ($this->manager->getConnection()->isTransactionActive()) { |
|
| 117 | + $this->manager->getConnection()->rollBack(); |
|
| 118 | + } |
|
| 118 | 119 | |
| 119 | 120 | throw new \InvalidArgumentException($e->getMessage()); |
| 120 | 121 | } |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | ->setParameter('company', $company->getId()) |
| 52 | 52 | ->setParameter('people', $people->getId()); |
| 53 | 53 | |
| 54 | - if ($linkType) |
|
| 55 | - $queryBuilder->setParameter('linkType', $linkType)->andWhere('pl.link_type = :linkType'); |
|
| 54 | + if ($linkType) { |
|
| 55 | + $queryBuilder->setParameter('linkType', $linkType)->andWhere('pl.link_type = :linkType'); |
|
| 56 | + } |
|
| 56 | 57 | |
| 57 | 58 | if ($maxResults) { |
| 58 | 59 | $queryBuilder->setMaxResults($maxResults); |
@@ -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) { |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | $isSalesman = false; |
| 36 | 36 | |
| 37 | 37 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'salesman', 1); |
| 38 | - if ($isSalesman) return true; |
|
| 38 | + if ($isSalesman) { |
|
| 39 | + return true; |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | $getPeopleCompanies = $this->manager->getRepository(PeopleLink::class)->findBy([ |
| 41 | 43 | 'people' => $people, |
@@ -46,7 +48,9 @@ discard block |
||
| 46 | 48 | */ |
| 47 | 49 | foreach ($getPeopleCompanies as $peopleCompany) { |
| 48 | 50 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $peopleCompany->getCompany(), 'salesman', 1); |
| 49 | - if ($isSalesman) return true; |
|
| 51 | + if ($isSalesman) { |
|
| 52 | + return true; |
|
| 53 | + } |
|
| 50 | 54 | } |
| 51 | 55 | return $isSalesman; |
| 52 | 56 | } |
@@ -58,8 +62,9 @@ discard block |
||
| 58 | 62 | $mainCompany = $this->getMainCompany(); |
| 59 | 63 | |
| 60 | 64 | $isSuper = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'employee', 1); |
| 61 | - if ($isSuper) |
|
| 62 | - $peopleRole[] = 'super'; |
|
| 65 | + if ($isSuper) { |
|
| 66 | + $peopleRole[] = 'super'; |
|
| 67 | + } |
|
| 63 | 68 | |
| 64 | 69 | $isFranchisee = $this->isFranchisee($people); |
| 65 | 70 | if ($isFranchisee) { |
@@ -68,13 +73,15 @@ discard block |
||
| 68 | 73 | } |
| 69 | 74 | |
| 70 | 75 | $isClient = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'client', 1); |
| 71 | - if ($isClient) |
|
| 72 | - $peopleRole[] = 'client'; |
|
| 76 | + if ($isClient) { |
|
| 77 | + $peopleRole[] = 'client'; |
|
| 78 | + } |
|
| 73 | 79 | |
| 74 | 80 | |
| 75 | 81 | $isSalesman = $this->isSalesman($people); |
| 76 | - if ($isSalesman) |
|
| 77 | - $peopleRole[] = 'salesman'; |
|
| 82 | + if ($isSalesman) { |
|
| 83 | + $peopleRole[] = 'salesman'; |
|
| 84 | + } |
|
| 78 | 85 | |
| 79 | 86 | |
| 80 | 87 | return array_values(array_unique(empty($peopleRole) ? ['guest'] : $peopleRole)); |
@@ -88,7 +95,9 @@ discard block |
||
| 88 | 95 | public function getMainCompany(): People |
| 89 | 96 | { |
| 90 | 97 | |
| 91 | - if (self::$mainCompany) return self::$mainCompany; |
|
| 98 | + if (self::$mainCompany) { |
|
| 99 | + return self::$mainCompany; |
|
| 100 | + } |
|
| 92 | 101 | |
| 93 | 102 | $peopleDomain = $this->domainService->getPeopleDomain(); |
| 94 | 103 | self::$mainCompany = $peopleDomain->getPeople(); |