fix deprecations: replace many strings by fqcn

This commit is contained in:
nobohan
2018-04-04 15:02:16 +02:00
parent 2eb81ab3ec
commit 678386ffd6
7 changed files with 168 additions and 159 deletions

View File

@@ -30,9 +30,10 @@ use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/**
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
@@ -44,19 +45,19 @@ class NationalityAggregator implements AggregatorInterface,
* @var EntityRepository
*/
protected $countriesRepository;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
*
* @var TranslatorInterface
*/
protected $translator;
public function __construct(EntityRepository $countriesRepository,
TranslatableStringHelper $translatableStringHelper,
TranslatorInterface $translator)
@@ -65,16 +66,16 @@ class NationalityAggregator implements AggregatorInterface,
$this->translatableStringHelper = $translatableStringHelper;
$this->translator = $translator;
}
public function applyOn()
{
return 'person';
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('group_by_level', 'choice', array(
$builder->add('group_by_level', ChoiceType::class, array(
'choices' => array(
'Group by continents' => 'continent',
'Group by country' => 'country'
@@ -83,7 +84,7 @@ class NationalityAggregator implements AggregatorInterface,
'expanded' => true,
'multiple' => false
));
}
public function validateForm($data, ExecutionContextInterface $context)
@@ -93,7 +94,7 @@ class NationalityAggregator implements AggregatorInterface,
->addViolation();
}
}
public function alterQuery(QueryBuilder $qb, $data)
{
// add a clause in select part
@@ -108,10 +109,10 @@ class NationalityAggregator implements AggregatorInterface,
. '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 \'\' '
. 'ELSE \'\' '
. 'END as nationality_aggregator ';
$qb->addSelect($clause);
$params =
$params =
array(
'africa_codes' => CountriesInfo::getCountriesCodeByContinent('AF'),
'asia_codes' => CountriesInfo::getCountriesCodeByContinent('AS'),
@@ -128,47 +129,47 @@ class NationalityAggregator implements AggregatorInterface,
throw new \LogicException("The group_by_level '".$data['group_by_level']
." is not known.");
}
$qb->leftJoin('person.nationality', 'nationality');
// add group by
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('nationality_aggregator');
} else {
$qb->groupBy('nationality_aggregator');
}
}
public function getTitle()
{
return "Group people by nationality";
}
public function getQueryKeys($data)
{
return array('nationality_aggregator');
}
public function addRole()
{
return NULL;
}
public function getLabels($key, array $values, $data)
{
if ($data['group_by_level'] === 'country') {
$qb = $this->countriesRepository->createQueryBuilder('c');
$countries = $qb
->andWhere($qb->expr()->in('c.countryCode', ':countries'))
->setParameter('countries', $values)
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
// initialize array and add blank key for null values
$labels[''] = $this->translator->trans('without data');
$labels['_header'] = $this->translator->trans('Nationality');
@@ -176,9 +177,9 @@ class NationalityAggregator implements AggregatorInterface,
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
}
} elseif ($data['group_by_level'] === 'continent') {
$labels = array(
'EU' => $this->translator->trans('Europe'),
'AS' => $this->translator->trans('Asia'),
@@ -191,11 +192,11 @@ class NationalityAggregator implements AggregatorInterface,
'_header' => $this->translator->trans('Continent')
);
}
return function($value) use ($labels) {
return $labels[$value];
};
}
}
}