mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 09:18:24 +00:00 
			
		
		
		
	Advanced search fixed to work with new gender entity
This commit is contained in:
		| @@ -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 .= '"'; | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -86,9 +86,7 @@ | ||||
|         </div> | ||||
|         {%- if options['addInfo'] -%} | ||||
|             <p class="moreinfo"> | ||||
|                 {{ person.gender.icon|chill_entity_render_box }} | ||||
| {#                <i class="{{ person.gender.icon.value }}" title="{{ person.gender.label|localize_translatable_string }}"></i>#} | ||||
|  | ||||
|                 {% 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 #} | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user