diff --git a/Export/Aggregator/AgeAggregator.php b/Export/Aggregator/AgeAggregator.php index 778a841ca..8d0065328 100644 --- a/Export/Aggregator/AgeAggregator.php +++ b/Export/Aggregator/AgeAggregator.php @@ -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; diff --git a/Export/Aggregator/CountryOfBirthAggregator.php b/Export/Aggregator/CountryOfBirthAggregator.php index 43f62c336..32c6edf95 100644 --- a/Export/Aggregator/CountryOfBirthAggregator.php +++ b/Export/Aggregator/CountryOfBirthAggregator.php @@ -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') ); } diff --git a/Export/Export/CountPerson.php b/Export/Export/CountPerson.php index dda2ce18b..0431095ec 100644 --- a/Export/Export/CountPerson.php +++ b/Export/Export/CountPerson.php @@ -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]; diff --git a/Export/Export/ListPerson.php b/Export/Export/ListPerson.php index 39e305a2c..bec4244be 100644 --- a/Export/Export/ListPerson.php +++ b/Export/Export/ListPerson.php @@ -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 * diff --git a/Export/Filter/GenderFilter.php b/Export/Filter/GenderFilter.php index f321900e2..729e9c682 100644 --- a/Export/Filter/GenderFilter.php +++ b/Export/Filter/GenderFilter.php @@ -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'); diff --git a/Resources/config/services/exports.yml b/Resources/config/services/exports.yml index 3d2fde74a..fc6cf645f 100644 --- a/Resources/config/services/exports.yml +++ b/Resources/config/services/exports.yml @@ -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 } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index c24eefb1b..34ebc0e04 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -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 + \ No newline at end of file