diff --git a/src/Bundle/ChillMainBundle/Search/AbstractSearch.php b/src/Bundle/ChillMainBundle/Search/AbstractSearch.php index c4e0fecd9..a7c81d5bf 100644 --- a/src/Bundle/ChillMainBundle/Search/AbstractSearch.php +++ b/src/Bundle/ChillMainBundle/Search/AbstractSearch.php @@ -62,12 +62,12 @@ abstract class AbstractSearch implements SearchInterface $recomposed .= ' '.$term.':'; $containsSpace = str_contains((string) $terms[$term], ' '); - if ($containsSpace) { + if ($containsSpace || is_numeric($terms[$term])) { $recomposed .= '"'; } $recomposed .= (false === mb_stristr(' ', (string) $terms[$term])) ? $terms[$term] : '('.$terms[$term].')'; - if ($containsSpace) { + if ($containsSpace || is_numeric($terms[$term])) { $recomposed .= '"'; } } diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepository.php b/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepository.php index 9e76dd374..686022ca3 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepository.php @@ -34,7 +34,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, @@ -62,7 +62,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, @@ -96,7 +96,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, @@ -202,7 +202,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor } if (null !== $gender) { - $query->andWhereClause('person.gender = ?', [$gender]); + $query->andWhereClause('person.gender_id = ?', [$gender]); } return $query; @@ -253,7 +253,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepositoryInterface.php b/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepositoryInterface.php index 7a45d6648..50fdcd4b3 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonACLAwareRepositoryInterface.php @@ -23,7 +23,7 @@ interface PersonACLAwareRepositoryInterface ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, @@ -36,7 +36,7 @@ interface PersonACLAwareRepositoryInterface ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, @@ -55,7 +55,7 @@ interface PersonACLAwareRepositoryInterface ?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateAfter = null, - ?string $gender = null, + ?int $gender = null, ?string $countryCode = null, ?string $phonenumber = null, ?string $city = null, diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index d59de28a4..380a17fa2 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -86,9 +86,7 @@ {%- if options['addInfo'] -%}
- {{ person.gender.icon|chill_entity_render_box }} -{# #} - + {% if person.gender is not null %}{{ person.gender.icon|chill_entity_render_box }}{% endif %} {%- if person.deathdate is not null -%} {%- if person.birthdate is not null -%} {# must be on one line to avoid spaces with dash #} diff --git a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php index 16a036cea..4e16bfb56 100644 --- a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php +++ b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Search; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillPhoneNumberType; use Chill\MainBundle\Pagination\PaginatorFactory; +use Chill\MainBundle\Repository\GenderRepository; use Chill\MainBundle\Search\AbstractSearch; use Chill\MainBundle\Search\HasAdvancedSearchFormInterface; use Chill\MainBundle\Search\ParsingException; @@ -36,7 +37,14 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf 'birthdate-after', 'gender', 'nationality', 'phonenumber', 'city', ]; - public function __construct(private readonly \Twig\Environment $templating, private readonly ExtractDateFromPattern $extractDateFromPattern, private readonly ExtractPhonenumberFromPattern $extractPhonenumberFromPattern, private readonly PaginatorFactory $paginatorFactory, private readonly PersonACLAwareRepositoryInterface $personACLAwareRepository) {} + public function __construct( + private readonly \Twig\Environment $templating, + private readonly ExtractDateFromPattern $extractDateFromPattern, + private readonly ExtractPhonenumberFromPattern $extractPhonenumberFromPattern, + private readonly PaginatorFactory $paginatorFactory, + private readonly PersonACLAwareRepositoryInterface $personACLAwareRepository, + private readonly GenderRepository $genderRepository, + ) {} public function buildForm(FormBuilderInterface $builder) { @@ -87,7 +95,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $string .= !isset($data['_default']) ? '' : $data['_default'].' '; - foreach (['firstname', 'lastname', 'gender', 'city'] as $key) { + foreach (['firstname', 'lastname', 'city'] as $key) { $string .= !isset($data[$key]) ? '' : $key.':'. // add quote if contains spaces (str_contains((string) $data[$key], ' ') ? '"'.$data[$key].'"' : $data[$key]) @@ -103,6 +111,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $string .= !isset($data['phonenumber']) ? '' : 'phonenumber:'.$data['phonenumber']->getNationalNumber(); + $string .= !isset($data['gender']) ? '' : 'gender:"'.$data['gender']->getId().'"'; return $string; } @@ -110,7 +119,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf { $data = []; - foreach (['firstname', 'lastname', 'gender', '_default', 'phonenumber', 'city'] as $key) { + foreach (['firstname', 'lastname', '_default', 'phonenumber', 'city'] as $key) { $data[$key] = $terms[$key] ?? null; } @@ -137,6 +146,10 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $data['phonenumber'] = $phonenumber; } + if (array_key_exists('gender', $terms)) { + $data['gender'] = $this->genderRepository->find((int) $terms['gender']); + } + return $data; } @@ -256,7 +269,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $birthdate, $birthdateBefore, $birthdateAfter, - $gender, + null !== $gender ? (int) $gender : null, $countryCode, $phonenumber, $city @@ -316,7 +329,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $birthdate, $birthdateBefore, $birthdateAfter, - $gender, + null !== $gender ? (int) $gender : null, $countryCode, $phonenumber, $city