Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 72a240b

Browse files
committedFeb 13, 2025
MQV-229 Adding formatted phone numbers to global search (phone numbers must be without spaces)
1 parent e7ff38c commit 72a240b

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

‎Resources/config/services.yml

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ services:
3232
- '@router'
3333
- '@doctrine.orm.entity_manager'
3434
- '@twig'
35+
36+
parameters:
37+
app.country: '%env(COUNTRY)%'

‎Response/DatatableQueryBuilder.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Sg\DatatablesBundle\Datatable\Options;
2828
use Symfony\Component\PropertyAccess\PropertyAccess;
2929
use Symfony\Component\PropertyAccess\PropertyAccessor;
30+
use libphonenumber\PhoneNumberUtil;
31+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
3032

3133
/**
3234
* @todo: remove phpcs warnings
@@ -498,7 +500,7 @@ private function setJoins(QueryBuilder $qb)
498500
*
499501
* @return $this
500502
*/
501-
private function setWhere(QueryBuilder $qb)
503+
private function setWhere(QueryBuilder $qb, ParameterBagInterface $params)
502504
{
503505
// Retrieving parameter counter
504506
$parameterCounter = self::INIT_PARAMETER_COUNTER;
@@ -529,6 +531,38 @@ private function setWhere(QueryBuilder $qb)
529531
$keywords = [$globalSearch];
530532
}
531533

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+
532566
// Iterating through each keyword
533567
foreach ($keywords as $k => $word) {
534568

‎composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"symfony/routing": "^3.4|^4.1|^5.0",
3232
"symfony/security-core": "^3.4|^4.1|^5.0",
3333
"symfony/translation": "^3.4|^4.1|^5.0",
34-
"twig/twig": "^2.9|^3.0"
34+
"twig/twig": "^2.9|^3.0",
35+
"giggsey/libphonenumber-for-php": "^8.13"
3536
},
3637
"require-dev": {
3738
"phpunit/phpunit": "^7.5|^8.5",

0 commit comments

Comments
 (0)
This repository has been archived.