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:
2017-01-31 13:43:14 +01:00
parent 25cad2f11d
commit cc91ade6fe
5 changed files with 34 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Symfony\Component\Form\Extension\Core\Type\DateType;
/**
* Render a list of peoples
@@ -87,13 +88,21 @@ class ListPerson implements ListInterface
$cf->getSlug();
}
// Add a checkbox to select fields
$builder->add('fields', ChoiceType::class, array(
'multiple' => true,
'expanded' => true,
'choices' => $choices,
'choices_as_values' => true,
'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(
'callback' => function($selected, ExecutionContextInterface $context) {
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_
strtoupper(substr($f, 8)),
$f));
$qb->setParameter('address_date', new \DateTime());
$qb->setParameter('address_date', $data['address_date']);
break;
default:
$qb->addSelect(sprintf('person.%s as %s', $f, $f));