mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
add advanced search for person
This commit is contained in:
parent
0031597e88
commit
54fbaa8c0d
@ -6,6 +6,7 @@ firstName: prénom
|
||||
lastname: nom
|
||||
lastName: nom
|
||||
Name: Nom
|
||||
First name or Last name: Prénom ou nom
|
||||
id: identifiant
|
||||
Birthdate: 'Date de naissance'
|
||||
birthdate: date de naissance
|
||||
|
@ -61,17 +61,22 @@
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('chill_person_new') }}" class="sc-button bt-create">
|
||||
<i class="fa fa-plus"></i>
|
||||
{{ 'Add a person'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% if preview == true and persons|length < total %}
|
||||
<li>
|
||||
<a href="{{ path('chill_main_search', { "name": search_name, "q" : pattern }) }}" class="sc-button">
|
||||
<a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="sc-button">
|
||||
{{ 'See all results'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% 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>
|
||||
|
||||
{% endif %}
|
||||
|
@ -30,8 +30,14 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Search\HasAdvancedSearchFormInterface;
|
||||
|
||||
class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
||||
class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
||||
HasAdvancedSearchFormInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
@ -249,5 +255,78 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
||||
|
||||
return clone $qb;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('_default', TextType::class, [
|
||||
'label' => 'First name or Last name',
|
||||
'required' => false
|
||||
])
|
||||
->add('firstname', TextType::class, [
|
||||
'label' => 'First name',
|
||||
'required' => false
|
||||
])
|
||||
->add('lastname', TextType::class, [
|
||||
'label' => 'Last name',
|
||||
'required' => false
|
||||
])
|
||||
->add('birthdate', ChillDateType::class, [
|
||||
'label' => 'Birthdate',
|
||||
'required' => false
|
||||
])
|
||||
->add('gender', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Man' => Person::MALE_GENDER,
|
||||
'Woman' => Person::FEMALE_GENDER
|
||||
],
|
||||
'label' => 'Gender',
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function convertFormDataToQuery(array $data)
|
||||
{
|
||||
$string = '@person ';
|
||||
|
||||
$string .= empty($data['_default']) ? '' : $data['_default'].' ';
|
||||
|
||||
foreach(['firstname', 'lastname', 'gender'] as $key) {
|
||||
$string .= empty($data[$key]) ? '' : $key.':'.
|
||||
// add quote if contains spaces
|
||||
(strpos($data[$key], ' ') !== false ? '"'.$data[$key].'"': $data[$key])
|
||||
.' ';
|
||||
}
|
||||
|
||||
$string .= empty($data['birthdate']) ?
|
||||
''
|
||||
:
|
||||
'birthdate:'.$data['birthdate']->format('Y-m-d').' '
|
||||
;
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function convertTermsToFormData(array $terms)
|
||||
{
|
||||
foreach(['firstname', 'lastname', 'gender', '_default']
|
||||
as $key) {
|
||||
$data[$key] = $terms[$key] ?? null;
|
||||
}
|
||||
|
||||
// parse birthdate
|
||||
if (\array_key_exists('birthdate', $terms)) {
|
||||
try {
|
||||
$date = new \DateTime($terms['birthdate']);
|
||||
} catch (\Exception $ex) {
|
||||
throw new ParsingException('The date is '
|
||||
. 'not parsable', 0, $ex);
|
||||
}
|
||||
}
|
||||
$data['birthdate'] = $date ?? null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user