mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FIX [phonenumber][search] fix advanced search when using a phonenumber
This commit is contained in:
parent
583d7b24ba
commit
c5f842076f
@ -70,6 +70,7 @@ class SearchController extends AbstractController
|
||||
}
|
||||
|
||||
if ($request->query->has('q')) {
|
||||
dump($request->query->get('q'));
|
||||
$data = $search->convertTermsToFormData($searchProvider->parse(
|
||||
$request->query->get('q')
|
||||
));
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Search;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ChillPhoneNumberType;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Search\AbstractSearch;
|
||||
use Chill\MainBundle\Search\HasAdvancedSearchFormInterface;
|
||||
@ -24,6 +25,7 @@ use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@ -94,7 +96,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'label' => 'Birthdate before',
|
||||
'required' => false,
|
||||
])
|
||||
->add('phonenumber', TelType::class, [
|
||||
->add('phonenumber', ChillPhoneNumberType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Part of the phonenumber',
|
||||
])
|
||||
@ -116,11 +118,12 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
|
||||
$string .= empty($data['_default']) ? '' : $data['_default'] . ' ';
|
||||
|
||||
foreach (['firstname', 'lastname', 'gender', 'phonenumber', 'city'] as $key) {
|
||||
foreach (['firstname', 'lastname', 'gender', 'city'] as $key) {
|
||||
$string .= empty($data[$key]) ? '' : $key . ':' .
|
||||
// add quote if contains spaces
|
||||
(strpos($data[$key], ' ') !== false ? '"' . $data[$key] . '"' : $data[$key])
|
||||
. ' ';
|
||||
|
||||
}
|
||||
|
||||
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
|
||||
@ -130,6 +133,8 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
$key . ':' . $data[$key]->format('Y-m-d') . ' ';
|
||||
}
|
||||
|
||||
$string .= empty($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber();
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -154,6 +159,18 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
$data[$key] = $date ?? null;
|
||||
}
|
||||
|
||||
if (array_key_exists('phonenumber', $terms)) {
|
||||
try {
|
||||
$phonenumber = new PhoneNumber();
|
||||
$phonenumber->setNationalNumber($terms['phonenumber']);
|
||||
} catch (Exception $ex) {
|
||||
throw new ParsingException("The date for {$key} is "
|
||||
. 'not parsable', 0, $ex);
|
||||
}
|
||||
|
||||
$data['phonenumber'] = $phonenumber ?? null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user