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,14 +30,15 @@ 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>
*/
class CountryOfBirthAggregator implements AggregatorInterface,
class CountryOfBirthAggregator implements AggregatorInterface,
ExportElementValidatedInterface
{
/**
@@ -45,19 +46,19 @@ class CountryOfBirthAggregator implements AggregatorInterface,
* @var EntityRepository
*/
protected $countriesRepository;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
*
* @var TranslatorInterface
*/
protected $translator;
public function __construct(EntityRepository $countriesRepository,
TranslatableStringHelper $translatableStringHelper,
TranslatorInterface $translator)
@@ -66,16 +67,16 @@ class CountryOfBirthAggregator 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'
@@ -84,9 +85,9 @@ class CountryOfBirthAggregator implements AggregatorInterface,
'expanded' => true,
'multiple' => false
));
}
public function validateForm($data, ExecutionContextInterface $context)
{
if ($data['group_by_level'] === null) {
@@ -94,7 +95,7 @@ class CountryOfBirthAggregator implements AggregatorInterface,
->addViolation();
}
}
public function alterQuery(QueryBuilder $qb, $data)
{
// add a clause in select part
@@ -109,10 +110,10 @@ class CountryOfBirthAggregator implements AggregatorInterface,
. 'WHEN countryOfBirth.countryCode IN(:cob_south_america_codes) THEN \'SA\' '
. 'WHEN countryOfBirth.countryCode IN(:cob_oceania_codes) THEN \'OC\' '
. 'WHEN countryOfBirth.countryCode IN(:cob_antartica_codes) THEN \'AN\' '
. 'ELSE \'\' '
. 'ELSE \'\' '
. 'END as country_of_birth_aggregator ';
$qb->addSelect($clause);
$params =
$params =
array(
'cob_africa_codes' => CountriesInfo::getCountriesCodeByContinent('AF'),
'cob_asia_codes' => CountriesInfo::getCountriesCodeByContinent('AS'),
@@ -129,47 +130,47 @@ class CountryOfBirthAggregator implements AggregatorInterface,
throw new \LogicException("The group_by_level '".$data['group_by_level']
." is not known.");
}
$qb->leftJoin('person.countryOfBirth', 'countryOfBirth');
// add group by
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('country_of_birth_aggregator');
} else {
$qb->groupBy('country_of_birth_aggregator');
}
}
public function getTitle()
{
return "Group people by country of birth";
}
public function getQueryKeys($data)
{
return array('country_of_birth_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('Country of birth');
@@ -177,9 +178,9 @@ class CountryOfBirthAggregator 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'),
@@ -192,11 +193,11 @@ class CountryOfBirthAggregator implements AggregatorInterface,
'_header' => $this->translator->trans('Continent of birth')
);
}
return function($value) use ($labels) {
return $labels[$value];
};
}
}
}

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];
};
}
}
}

View File

@@ -27,27 +27,28 @@ use Doctrine\ORM\Query\Expr;
use Symfony\Component\Security\Core\Role\Role;
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>
*/
class GenderFilter implements FilterInterface,
ExportElementValidatedInterface
{
public function applyOn()
{
return 'person';
}
/**
*
*
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('accepted_genders', 'choice', array(
$builder->add('accepted_genders', ChoiceType::class, array(
'choices' => array(
Person::FEMALE_GENDER => 'Woman',
Person::MALE_GENDER => 'Man'
@@ -56,7 +57,7 @@ class GenderFilter implements FilterInterface,
'expanded' => false
));
}
public function validateForm($data, ExecutionContextInterface $context)
{
if (count($data['accepted_genders']) === 0) {
@@ -64,38 +65,38 @@ class GenderFilter implements FilterInterface,
->addViolation();
}
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('person.gender', ':person_gender');
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('person_gender', $data['accepted_genders']);
}
/**
* A title which will be used in the label for the form
*
*
* @return string
*/
public function getTitle()
{
return 'Filter by person gender';
}
public function addRole()
{
return NULL;
}
public function describeAction($data, $format = 'string')
{
switch($data['accepted_genders']) {