mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add validation to aggregator and filters
This commit is contained in:
parent
cc91ade6fe
commit
559239aca1
@ -22,6 +22,9 @@ namespace Chill\PersonBundle\Export\Aggregator;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -30,6 +33,17 @@ use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
*/
|
||||
class AgeAggregator implements AggregatorInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct($translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
@ -67,7 +81,7 @@ class AgeAggregator implements AggregatorInterface
|
||||
}
|
||||
|
||||
if ($value === NULL) {
|
||||
return "no data";
|
||||
return $this->translator->trans("without data");
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -160,7 +160,7 @@ class CountryOfBirthAggregator implements AggregatorInterface
|
||||
|
||||
// initialize array and add blank key for null values
|
||||
$labels[''] = $this->translator->trans('without data');
|
||||
$labels['_header'] = $this->translator->trans('Nationality');
|
||||
$labels['_header'] = $this->translator->trans('Country of birth');
|
||||
foreach($countries as $row) {
|
||||
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
|
||||
}
|
||||
@ -177,7 +177,7 @@ class CountryOfBirthAggregator implements AggregatorInterface
|
||||
'NA' => $this->translator->trans('North America'),
|
||||
'OC' => $this->translator->trans('Oceania'),
|
||||
'' => $this->translator->trans('without data'),
|
||||
'_header' => $this->translator->trans('Continent')
|
||||
'_header' => $this->translator->trans('Continent of birth')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ class CountPerson implements ExportInterface
|
||||
}
|
||||
|
||||
$labels = array_combine($values, $values);
|
||||
$labels['_header'] = 'Number of people';
|
||||
$labels['_header'] = $this->getTitle();
|
||||
|
||||
return function($value) use ($labels) {
|
||||
return $labels[$value];
|
||||
|
@ -20,13 +20,14 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
|
||||
/**
|
||||
* Render a list of peoples
|
||||
*
|
||||
* @author julien
|
||||
*/
|
||||
class ListPerson implements ListInterface
|
||||
class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
@ -126,6 +127,26 @@ class ListPerson implements ListInterface
|
||||
));
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
dump($data);
|
||||
// get the field starting with address_
|
||||
$addressFields = array_filter(function($el) {
|
||||
return substr($el, 0, 8) === 'address_';
|
||||
}, $this->fields);
|
||||
dump($data['address_date']);
|
||||
// check if there is one field starting with address in data
|
||||
if (count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
// if a field address is checked, the date must not be empty
|
||||
if (empty($data['address_date'])) {
|
||||
$context
|
||||
->buildViolation("You must set this date if an address is checked")
|
||||
->atPath('address_date')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom fields associated with person
|
||||
*
|
||||
|
@ -49,11 +49,19 @@ class GenderFilter implements FilterInterface
|
||||
Person::FEMALE_GENDER => 'Woman',
|
||||
Person::MALE_GENDER => 'Man'
|
||||
),
|
||||
'multiple' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false
|
||||
));
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
if (count($data['accepted_genders']) === 0) {
|
||||
$context->buildViolation("You should select an option")
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
|
@ -60,5 +60,7 @@ services:
|
||||
|
||||
chill.person.export.aggregator_age:
|
||||
class: Chill\PersonBundle\Export\Aggregator\AgeAggregator
|
||||
arguments:
|
||||
- "@translator"
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_age_aggregator }
|
||||
|
@ -23,6 +23,7 @@ gender: genre
|
||||
'Place of birth': 'Lieu de naissance'
|
||||
placeOfBirth: lieu de naissance
|
||||
'Country of birth': 'Pays de naissance'
|
||||
'Continent of birth': Continent de naissance
|
||||
countryOfBirth: 'Pays de naissance'
|
||||
'Unknown country of birth': 'Pays inconnu'
|
||||
'Marital status': 'État civil'
|
||||
@ -185,3 +186,6 @@ Group people by gender: Aggréger les personnes par genre
|
||||
|
||||
Aggregate by age: Aggréger par âge
|
||||
Calculate age in relation to this date: Calculer l'âge par rapport à cette date
|
||||
|
||||
Group people by country of birth: Aggréger les personnes par pays de naissance
|
||||
|
Loading…
x
Reference in New Issue
Block a user