mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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
|
||||||
lastName: nom
|
lastName: nom
|
||||||
Name: Nom
|
Name: Nom
|
||||||
|
First name or Last name: Prénom ou nom
|
||||||
id: identifiant
|
id: identifiant
|
||||||
Birthdate: 'Date de naissance'
|
Birthdate: 'Date de naissance'
|
||||||
birthdate: date de naissance
|
birthdate: date de naissance
|
||||||
|
@ -61,17 +61,22 @@
|
|||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ path('chill_person_new') }}" class="sc-button bt-create">
|
<a href="{{ path('chill_person_new') }}" class="sc-button bt-create">
|
||||||
<i class="fa fa-plus"></i>
|
|
||||||
{{ 'Add a person'|trans }}
|
{{ 'Add a person'|trans }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</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, "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 }}
|
{{ 'See all results'|trans }}
|
||||||
</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>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -30,8 +30,14 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
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;
|
use ContainerAwareTrait;
|
||||||
|
|
||||||
@ -249,5 +255,78 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
|||||||
|
|
||||||
return clone $qb;
|
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