mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
adding a date for the address
The address are computed to be valid at a given date. The date input appears only if fields concerning address are checked.
This commit is contained in:
parent
25cad2f11d
commit
cc91ade6fe
@ -113,7 +113,8 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
'chill_person' => array(
|
'chill_person' => array(
|
||||||
'fields' => $config['person_fields']
|
'fields' => $config['person_fields']
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
'form_themes' => array('ChillPersonBundle:Export:ListPersonFormFields.html.twig')
|
||||||
);
|
);
|
||||||
$container->prependExtensionConfig('twig', $twigConfig);
|
$container->prependExtensionConfig('twig', $twigConfig);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a list of peoples
|
* Render a list of peoples
|
||||||
@ -87,13 +88,21 @@ class ListPerson implements ListInterface
|
|||||||
$cf->getSlug();
|
$cf->getSlug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a checkbox to select fields
|
||||||
$builder->add('fields', ChoiceType::class, array(
|
$builder->add('fields', ChoiceType::class, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
'choices_as_values' => true,
|
'choices_as_values' => true,
|
||||||
'label' => 'Fields to include in export',
|
'label' => 'Fields to include in export',
|
||||||
|
'choice_attr' => function($val, $key, $index) {
|
||||||
|
// add a 'data-display-target' for address fields
|
||||||
|
if (substr($val, 0, 8) === 'address_') {
|
||||||
|
return ['data-display-target' => 'address_date'];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
'constraints' => [new Callback(array(
|
'constraints' => [new Callback(array(
|
||||||
'callback' => function($selected, ExecutionContextInterface $context) {
|
'callback' => function($selected, ExecutionContextInterface $context) {
|
||||||
if (count($selected) === 0) {
|
if (count($selected) === 0) {
|
||||||
@ -104,7 +113,17 @@ class ListPerson implements ListInterface
|
|||||||
}
|
}
|
||||||
))]
|
))]
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// add a date field for addresses
|
||||||
|
$builder->add('address_date', DateType::class, array(
|
||||||
|
'label' => "Address valid at this date",
|
||||||
|
'data' => new \DateTime(),
|
||||||
|
'attr' => array( 'class' => 'datepicker'),
|
||||||
|
'widget'=> 'single_text',
|
||||||
|
'format' => 'dd-MM-yyyy',
|
||||||
|
'required' => false,
|
||||||
|
'block_name' => 'list_export_form_address_date'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -346,7 +365,7 @@ class ListPerson implements ListInterface
|
|||||||
// get the part after address_
|
// get the part after address_
|
||||||
strtoupper(substr($f, 8)),
|
strtoupper(substr($f, 8)),
|
||||||
$f));
|
$f));
|
||||||
$qb->setParameter('address_date', new \DateTime());
|
$qb->setParameter('address_date', $data['address_date']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
|
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
|
||||||
|
@ -155,6 +155,7 @@ Count peoples: Nombre de personnes
|
|||||||
List peoples: Liste des personnes
|
List peoples: Liste des personnes
|
||||||
Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres.
|
Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres.
|
||||||
Fields to include in export: Champs à inclure dans l'export
|
Fields to include in export: Champs à inclure dans l'export
|
||||||
|
Address valid at this date: Addresse valide à cette date
|
||||||
|
|
||||||
## filters
|
## filters
|
||||||
Filter by person gender: Filtrer par genre de la personne
|
Filter by person gender: Filtrer par genre de la personne
|
||||||
|
5
Resources/views/Export/ListPersonFormFields.html.twig
Normal file
5
Resources/views/Export/ListPersonFormFields.html.twig
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% block _export_export_list_export_form_address_date_row %}
|
||||||
|
<div data-display-show-hide="address_date">
|
||||||
|
{{ form_row(form) }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -73,8 +73,10 @@ class ListPersonTest extends AbstractExportTest
|
|||||||
array('fields' => ['id', 'nationality']),
|
array('fields' => ['id', 'nationality']),
|
||||||
array('fields' => ['id', 'countryOfBirth']),
|
array('fields' => ['id', 'countryOfBirth']),
|
||||||
array('fields' => ['id', 'address_street_address_1',
|
array('fields' => ['id', 'address_street_address_1',
|
||||||
'address_street_address_2', 'address_valid_from', 'address_postcode_label',
|
'address_street_address_2', 'address_valid_from',
|
||||||
'address_postcode_code', 'address_country_name', 'address_country_code'])
|
'address_postcode_label', 'address_postcode_code',
|
||||||
|
'address_country_name', 'address_country_code'],
|
||||||
|
'address_date' => \DateTime::createFromFormat('Y-m-d', '2016-06-12'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user