mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
add filtering before / after date of birth
This commit is contained in:
parent
f5de2d8049
commit
75b4ef5a7d
@ -14,6 +14,8 @@ birthdate: date de naissance
|
|||||||
dateOfBirth: date de naissance
|
dateOfBirth: date de naissance
|
||||||
dateofbirth: date de naissance
|
dateofbirth: date de naissance
|
||||||
'Unknown date of birth': 'Date de naissance inconnue'
|
'Unknown date of birth': 'Date de naissance inconnue'
|
||||||
|
Birthdate before: Date de naissance avant le
|
||||||
|
Birthdate after: Date de naissance après le
|
||||||
Nationality: Nationalité
|
Nationality: Nationalité
|
||||||
nationality: nationalité
|
nationality: nationalité
|
||||||
'Without nationality': 'Sans nationalité'
|
'Without nationality': 'Sans nationalité'
|
||||||
@ -85,7 +87,7 @@ Reset: 'Remise à zéro'
|
|||||||
'The person has been created': 'Le dossier a été créé'
|
'The person has been created': 'Le dossier a été créé'
|
||||||
'Person search results': 'Recherche de personnes'
|
'Person search results': 'Recherche de personnes'
|
||||||
'Search within persons': 'Recherche parmi les personnes'
|
'Search within persons': 'Recherche parmi les personnes'
|
||||||
'%total% persons matching the search %pattern%': '{0} Aucune personne ne correspond aux termes de recherche "%pattern%" | {1} Une personne a été trouvée par la recherche "%pattern%" | ]1,Inf] %total% personnes correspondent aux termes de recherche "%pattern%".'
|
'%total% persons matching the search pattern:': '{0} Aucune personne ne correspond aux termes de recherche : | {1} Une personne a été trouvée par la recherche : | ]1,Inf] %total% personnes correspondent aux termes de recherche :'
|
||||||
'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.'
|
'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.'
|
||||||
'Person accompanying period - %name%': 'Historique du dossier - %name%'
|
'Person accompanying period - %name%': 'Historique du dossier - %name%'
|
||||||
'Opening date': 'Date d''ouverture'
|
'Opening date': 'Date d''ouverture'
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
#}
|
#}
|
||||||
<h2>{{ 'Person search results'|trans }}</h2>
|
<h2>{{ 'Person search results'|trans }}</h2>
|
||||||
|
|
||||||
<p>{{ '%total% persons matching the search %pattern%'|transchoice( total, {'%pattern%': pattern, '%total%' : total}) }}</p>
|
<p>
|
||||||
|
{{ '%total% persons matching the search pattern:'|transchoice( total, { '%total%' : total}) }}
|
||||||
|
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button button-small">
|
||||||
|
<i class="fa fa-search" aria-hidden="true"></i> {{ pattern }}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}</p>
|
<p>{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}</p>
|
||||||
|
|
||||||
@ -64,6 +69,11 @@
|
|||||||
{{ 'Add a person'|trans }}
|
{{ 'Add a person'|trans }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
|
||||||
|
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% if preview == true and persons|length < total %}
|
{% if preview == true and persons|length < total %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="sc-button">
|
<a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="sc-button">
|
||||||
@ -71,14 +81,15 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li>
|
|
||||||
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
|
|
||||||
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
|
||||||
|
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if preview == false %}
|
{% if preview == false %}
|
||||||
|
@ -122,7 +122,8 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
|||||||
array(
|
array(
|
||||||
'persons' => $this->search($terms, $start, $limit, $options),
|
'persons' => $this->search($terms, $start, $limit, $options),
|
||||||
'pattern' => $this->recomposePattern($terms, array('nationality',
|
'pattern' => $this->recomposePattern($terms, array('nationality',
|
||||||
'firstname', 'lastname', 'birthdate', 'gender'), $terms['_domain']),
|
'firstname', 'lastname', 'birthdate', 'gender',
|
||||||
|
'birthdate-before','birthdate-after'), $terms['_domain']),
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'start' => $start,
|
'start' => $start,
|
||||||
'search_name' => self::NAME,
|
'search_name' => self::NAME,
|
||||||
@ -194,16 +195,32 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
|||||||
->setParameter('lastname', '%'.$terms['lastname'].'%');
|
->setParameter('lastname', '%'.$terms['lastname'].'%');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('birthdate', $terms)) {
|
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key)
|
||||||
|
if (array_key_exists($key, $terms)) {
|
||||||
try {
|
try {
|
||||||
$date = new \DateTime($terms['birthdate']);
|
$date = new \DateTime($terms[$key]);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
throw new ParsingException('The date is '
|
throw new ParsingException('The date is '
|
||||||
. 'not parsable', 0, $ex);
|
. 'not parsable', 0, $ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb->andWhere($qb->expr()->eq('p.birthdate', ':birthdate'))
|
switch($key) {
|
||||||
->setParameter('birthdate', $date);
|
case 'birthdate':
|
||||||
|
$qb->andWhere($qb->expr()->eq('p.birthdate', ':birthdate'))
|
||||||
|
->setParameter('birthdate', $date);
|
||||||
|
break;
|
||||||
|
case 'birthdate-before':
|
||||||
|
$qb->andWhere($qb->expr()->lt('p.birthdate', ':birthdatebefore'))
|
||||||
|
->setParameter('birthdatebefore', $date);
|
||||||
|
break;
|
||||||
|
case 'birthdate-after':
|
||||||
|
$qb->andWhere($qb->expr()->gt('p.birthdate', ':birthdateafter'))
|
||||||
|
->setParameter('birthdateafter', $date);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \LogicException("this case $key should not exists");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('gender', $terms)) {
|
if (array_key_exists('gender', $terms)) {
|
||||||
@ -271,10 +288,18 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
|||||||
'label' => 'Last name',
|
'label' => 'Last name',
|
||||||
'required' => false
|
'required' => false
|
||||||
])
|
])
|
||||||
|
->add('birthdate-after', ChillDateType::class, [
|
||||||
|
'label' => 'Birthdate after',
|
||||||
|
'required' => false
|
||||||
|
])
|
||||||
->add('birthdate', ChillDateType::class, [
|
->add('birthdate', ChillDateType::class, [
|
||||||
'label' => 'Birthdate',
|
'label' => 'Birthdate',
|
||||||
'required' => false
|
'required' => false
|
||||||
])
|
])
|
||||||
|
->add('birthdate-before', ChillDateType::class, [
|
||||||
|
'label' => 'Birthdate before',
|
||||||
|
'required' => false
|
||||||
|
])
|
||||||
->add('gender', ChoiceType::class, [
|
->add('gender', ChoiceType::class, [
|
||||||
'choices' => [
|
'choices' => [
|
||||||
'Man' => Person::MALE_GENDER,
|
'Man' => Person::MALE_GENDER,
|
||||||
@ -299,11 +324,13 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
|||||||
.' ';
|
.' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
$string .= empty($data['birthdate']) ?
|
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
|
||||||
''
|
$string .= empty($data[$key]) ?
|
||||||
:
|
''
|
||||||
'birthdate:'.$data['birthdate']->format('Y-m-d').' '
|
:
|
||||||
;
|
$key.':'.$data[$key]->format('Y-m-d').' '
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
@ -315,18 +342,25 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
|||||||
$data[$key] = $terms[$key] ?? null;
|
$data[$key] = $terms[$key] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse birthdate
|
// parse dates
|
||||||
if (\array_key_exists('birthdate', $terms)) {
|
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
|
||||||
try {
|
if (\array_key_exists($key, $terms)) {
|
||||||
$date = new \DateTime($terms['birthdate']);
|
try {
|
||||||
} catch (\Exception $ex) {
|
$date = new \DateTime($terms[$key]);
|
||||||
throw new ParsingException('The date is '
|
} catch (\Exception $ex) {
|
||||||
. 'not parsable', 0, $ex);
|
throw new ParsingException("The date for $key is "
|
||||||
|
. 'not parsable', 0, $ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$data[$key] = $date ?? null;
|
||||||
}
|
}
|
||||||
$data['birthdate'] = $date ?? null;
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAdvancedSearchTitle()
|
||||||
|
{
|
||||||
|
return 'Search within persons';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user