|
27 | 27 | use Sg\DatatablesBundle\Datatable\Options; |
28 | 28 | use Symfony\Component\PropertyAccess\PropertyAccess; |
29 | 29 | use Symfony\Component\PropertyAccess\PropertyAccessor; |
| 30 | +use libphonenumber\PhoneNumberUtil; |
| 31 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
30 | 32 |
|
31 | 33 | /** |
32 | 34 | * @todo: remove phpcs warnings |
@@ -498,7 +500,7 @@ private function setJoins(QueryBuilder $qb) |
498 | 500 | * |
499 | 501 | * @return $this |
500 | 502 | */ |
501 | | - private function setWhere(QueryBuilder $qb) |
| 503 | + private function setWhere(QueryBuilder $qb, ParameterBagInterface $params) |
502 | 504 | { |
503 | 505 | // Retrieving parameter counter |
504 | 506 | $parameterCounter = self::INIT_PARAMETER_COUNTER; |
@@ -529,6 +531,38 @@ private function setWhere(QueryBuilder $qb) |
529 | 531 | $keywords = [$globalSearch]; |
530 | 532 | } |
531 | 533 |
|
| 534 | + // Adding searchable version of phone numbers in search |
| 535 | + $additionalkeywords = []; |
| 536 | + foreach($keywords as $k => $word) { |
| 537 | + |
| 538 | + // If keyword looks like a phone number |
| 539 | + if ( null !== $phone ) { |
| 540 | + try { |
| 541 | + // Creating instance of phone number service |
| 542 | + $phoneUtil = PhoneNumberUtil::getInstance(); |
| 543 | + |
| 544 | + // Retrieving country |
| 545 | + $countrycode = $params->get('country'); |
| 546 | + |
| 547 | + // Trying to parse word to phone number object |
| 548 | + $newphoneobject = $phoneUtil->parse($phone, $countrycode); |
| 549 | + $newphone = $phoneUtil->formatOutOfCountryCallingNumber($newphoneobject, $countrycode); |
| 550 | + |
| 551 | + // Adding standardized version of keyword to search array |
| 552 | + $additionalkeywords[] = $newphone; |
| 553 | + |
| 554 | + } catch (\Exception $e) { |
| 555 | + // Nothing, this is normal |
| 556 | + unset($e); |
| 557 | + } |
| 558 | + } |
| 559 | + } |
| 560 | + |
| 561 | + // Merquiry additional array |
| 562 | + if (!empty($additionalkeywords)) { |
| 563 | + $keywords = array_merge($keywords, $additionalkeywords); |
| 564 | + } |
| 565 | + |
532 | 566 | // Iterating through each keyword |
533 | 567 | foreach ($keywords as $k => $word) { |
534 | 568 |
|
|
0 commit comments