diff --git a/Export/Aggregator/NationalityAggregator.php b/Export/Aggregator/NationalityAggregator.php index 834921f68..442aff978 100644 --- a/Export/Aggregator/NationalityAggregator.php +++ b/Export/Aggregator/NationalityAggregator.php @@ -25,6 +25,7 @@ use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\EntityRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Component\Translation\TranslatorInterface; +use Chill\MainBundle\Util\CountriesInfo; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; @@ -62,8 +63,6 @@ class NationalityAggregator implements AggregatorInterface $this->translator = $translator; } - const EUROPE_COUNTRY_CODE = array('BE', 'FR'); - public function applyOn() { return 'person'; @@ -91,11 +90,29 @@ class NationalityAggregator implements AggregatorInterface $qb->addSelect('nationality.countryCode as nationality_aggregator'); } elseif ($data['group_by_level'] === 'continent') { $clause = 'CASE ' - . 'WHEN nationality.countryCode IN(:europe_country_codes) THEN \'EU\' ' - . 'ELSE \'OC\' ' //this is dummy code ! + . 'WHEN nationality.countryCode IN(:africa_codes) THEN \'AF\' ' + . 'WHEN nationality.countryCode IN(:asia_codes) THEN \'AS\' ' + . 'WHEN nationality.countryCode IN(:europe_codes) THEN \'EU\' ' + . 'WHEN nationality.countryCode IN(:north_america_codes) THEN \'NA\' ' + . 'WHEN nationality.countryCode IN(:south_america_codes) THEN \'SA\' ' + . 'WHEN nationality.countryCode IN(:oceania_codes) THEN \'OC\' ' + . 'WHEN nationality.countryCode IN(:antartica_codes) THEN \'AN\' ' + . 'ELSE \'\' ' . 'END as nationality_aggregator '; $qb->addSelect($clause); - $qb->setParameter('europe_country_codes', self::EUROPE_COUNTRY_CODE); + $params = + array( + 'africa_codes' => CountriesInfo::getCountriesCodeByContinent('AF'), + 'asia_codes' => CountriesInfo::getCountriesCodeByContinent('AS'), + 'europe_codes' => CountriesInfo::getCountriesCodeByContinent('EU'), + 'north_america_codes' => CountriesInfo::getCountriesCodeByContinent('NA'), + 'south_america_codes' => CountriesInfo::getCountriesCodeByContinent('SA'), + 'oceania_codes' => CountriesInfo::getCountriesCodeByContinent('OC'), + 'antartica_codes' => CountriesInfo::getCountriesCodeByContinent('AN') + ); + foreach ($params as $k => $v) { + $qb->setParameter($k, $v); + } } else { throw new \LogicException("The group_by_level '".$data['group_by_level'] ." is not known."); @@ -165,279 +182,5 @@ class NationalityAggregator implements AggregatorInterface ); } - } - - public static function getCountryData() - { - // this list is extracted by https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_%28data_file%29 - // source : - // Wikipedia contributors, "List of sovereign states and dependent territories by continent (data file)," - // Wikipedia, The Free Encyclopedia, https://en.wikipedia.org/w/index.php?title=List_of_sovereign_states_and_dependent_territories_by_continent_(data_file)&oldid=688980440 - // (accessed January 2, 2016). - return <<