Advanced search fixed to work with new gender entity

This commit is contained in:
Julie Lenaerts 2024-10-22 14:50:06 +02:00
parent 588f02cdf4
commit 5dfa5e1e7f
5 changed files with 29 additions and 18 deletions

View File

@ -62,12 +62,12 @@ abstract class AbstractSearch implements SearchInterface
$recomposed .= ' '.$term.':'; $recomposed .= ' '.$term.':';
$containsSpace = str_contains((string) $terms[$term], ' '); $containsSpace = str_contains((string) $terms[$term], ' ');
if ($containsSpace) { if ($containsSpace || is_numeric($terms[$term])) {
$recomposed .= '"'; $recomposed .= '"';
} }
$recomposed .= (false === mb_stristr(' ', (string) $terms[$term])) ? $terms[$term] : '('.$terms[$term].')'; $recomposed .= (false === mb_stristr(' ', (string) $terms[$term])) ? $terms[$term] : '('.$terms[$term].')';
if ($containsSpace) { if ($containsSpace || is_numeric($terms[$term])) {
$recomposed .= '"'; $recomposed .= '"';
} }
} }

View File

@ -34,7 +34,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,
@ -62,7 +62,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,
@ -96,7 +96,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,
@ -202,7 +202,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
} }
if (null !== $gender) { if (null !== $gender) {
$query->andWhereClause('person.gender = ?', [$gender]); $query->andWhereClause('person.gender_id = ?', [$gender]);
} }
return $query; return $query;
@ -253,7 +253,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,

View File

@ -23,7 +23,7 @@ interface PersonACLAwareRepositoryInterface
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,
@ -36,7 +36,7 @@ interface PersonACLAwareRepositoryInterface
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,
@ -55,7 +55,7 @@ interface PersonACLAwareRepositoryInterface
?\DateTimeInterface $birthdate = null, ?\DateTimeInterface $birthdate = null,
?\DateTimeInterface $birthdateBefore = null, ?\DateTimeInterface $birthdateBefore = null,
?\DateTimeInterface $birthdateAfter = null, ?\DateTimeInterface $birthdateAfter = null,
?string $gender = null, ?int $gender = null,
?string $countryCode = null, ?string $countryCode = null,
?string $phonenumber = null, ?string $phonenumber = null,
?string $city = null, ?string $city = null,

View File

@ -86,9 +86,7 @@
</div> </div>
{%- if options['addInfo'] -%} {%- if options['addInfo'] -%}
<p class="moreinfo"> <p class="moreinfo">
{{ person.gender.icon|chill_entity_render_box }} {% if person.gender is not null %}{{ person.gender.icon|chill_entity_render_box }}{% endif %}
{# <i class="{{ person.gender.icon.value }}" title="{{ person.gender.label|localize_translatable_string }}"></i>#}
{%- if person.deathdate is not null -%} {%- if person.deathdate is not null -%}
{%- if person.birthdate is not null -%} {%- if person.birthdate is not null -%}
{# must be on one line to avoid spaces with dash #} {# must be on one line to avoid spaces with dash #}

View File

@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Search;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillPhoneNumberType; use Chill\MainBundle\Form\Type\ChillPhoneNumberType;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\GenderRepository;
use Chill\MainBundle\Search\AbstractSearch; use Chill\MainBundle\Search\AbstractSearch;
use Chill\MainBundle\Search\HasAdvancedSearchFormInterface; use Chill\MainBundle\Search\HasAdvancedSearchFormInterface;
use Chill\MainBundle\Search\ParsingException; use Chill\MainBundle\Search\ParsingException;
@ -36,7 +37,14 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
'birthdate-after', 'gender', 'nationality', 'phonenumber', 'city', '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) public function buildForm(FormBuilderInterface $builder)
{ {
@ -87,7 +95,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$string .= !isset($data['_default']) ? '' : $data['_default'].' '; $string .= !isset($data['_default']) ? '' : $data['_default'].' ';
foreach (['firstname', 'lastname', 'gender', 'city'] as $key) { foreach (['firstname', 'lastname', 'city'] as $key) {
$string .= !isset($data[$key]) ? '' : $key.':'. $string .= !isset($data[$key]) ? '' : $key.':'.
// add quote if contains spaces // add quote if contains spaces
(str_contains((string) $data[$key], ' ') ? '"'.$data[$key].'"' : $data[$key]) (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['phonenumber']) ? '' : 'phonenumber:'.$data['phonenumber']->getNationalNumber();
$string .= !isset($data['gender']) ? '' : 'gender:"'.$data['gender']->getId().'"';
return $string; return $string;
} }
@ -110,7 +119,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
{ {
$data = []; $data = [];
foreach (['firstname', 'lastname', 'gender', '_default', 'phonenumber', 'city'] as $key) { foreach (['firstname', 'lastname', '_default', 'phonenumber', 'city'] as $key) {
$data[$key] = $terms[$key] ?? null; $data[$key] = $terms[$key] ?? null;
} }
@ -137,6 +146,10 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$data['phonenumber'] = $phonenumber; $data['phonenumber'] = $phonenumber;
} }
if (array_key_exists('gender', $terms)) {
$data['gender'] = $this->genderRepository->find((int) $terms['gender']);
}
return $data; return $data;
} }
@ -256,7 +269,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$birthdate, $birthdate,
$birthdateBefore, $birthdateBefore,
$birthdateAfter, $birthdateAfter,
$gender, null !== $gender ? (int) $gender : null,
$countryCode, $countryCode,
$phonenumber, $phonenumber,
$city $city
@ -316,7 +329,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$birthdate, $birthdate,
$birthdateBefore, $birthdateBefore,
$birthdateAfter, $birthdateAfter,
$gender, null !== $gender ? (int) $gender : null,
$countryCode, $countryCode,
$phonenumber, $phonenumber,
$city $city