mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
fix deprecations: use fqcn instead of 'choice'
This commit is contained in:
parent
b596a7a9c9
commit
4399c96036
@ -29,9 +29,10 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|||||||
use Doctrine\ORM\Query\Expr\Join;
|
use Doctrine\ORM\Query\Expr\Join;
|
||||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
@ -43,19 +44,19 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
* @var EntityRepository
|
* @var EntityRepository
|
||||||
*/
|
*/
|
||||||
protected $categoryRepository;
|
protected $categoryRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var EntityRepository
|
* @var EntityRepository
|
||||||
*/
|
*/
|
||||||
protected $reasonRepository;
|
protected $reasonRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TranslatableStringHelper
|
* @var TranslatableStringHelper
|
||||||
*/
|
*/
|
||||||
protected $stringHelper;
|
protected $stringHelper;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EntityRepository $categoryRepository,
|
EntityRepository $categoryRepository,
|
||||||
EntityRepository $reasonRepository,
|
EntityRepository $reasonRepository,
|
||||||
@ -65,7 +66,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
$this->reasonRepository = $reasonRepository;
|
$this->reasonRepository = $reasonRepository;
|
||||||
$this->stringHelper = $stringHelper;
|
$this->stringHelper = $stringHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
// add select element
|
// add select element
|
||||||
@ -78,9 +79,9 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('the data provided are not recognized');
|
throw new \RuntimeException('the data provided are not recognized');
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb->addSelect($elem.' as '.$alias);
|
$qb->addSelect($elem.' as '.$alias);
|
||||||
|
|
||||||
// make a jointure only if needed
|
// make a jointure only if needed
|
||||||
$join = $qb->getDQLPart('join');
|
$join = $qb->getDQLPart('join');
|
||||||
if (
|
if (
|
||||||
@ -92,13 +93,13 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
(! array_key_exists('activity', $join))
|
(! array_key_exists('activity', $join))
|
||||||
) {
|
) {
|
||||||
$qb->add(
|
$qb->add(
|
||||||
'join',
|
'join',
|
||||||
array('activity' =>
|
array('activity' =>
|
||||||
new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')
|
new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')
|
||||||
),
|
),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// join category if necessary
|
// join category if necessary
|
||||||
if ($alias === 'activity_categories_id') {
|
if ($alias === 'activity_categories_id') {
|
||||||
// add join only if needed
|
// add join only if needed
|
||||||
@ -106,20 +107,20 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
$qb->join('reasons.category', 'category');
|
$qb->join('reasons.category', 'category');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the "group by" part
|
// add the "group by" part
|
||||||
$groupBy = $qb->getDQLPart('groupBy');
|
$groupBy = $qb->getDQLPart('groupBy');
|
||||||
|
|
||||||
if (count($groupBy) > 0) {
|
if (count($groupBy) > 0) {
|
||||||
$qb->addGroupBy($alias);
|
$qb->addGroupBy($alias);
|
||||||
} else {
|
} else {
|
||||||
$qb->groupBy($alias);
|
$qb->groupBy($alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a join between Activity and another alias
|
* Check if a join between Activity and another alias
|
||||||
*
|
*
|
||||||
* @param Join[] $joins
|
* @param Join[] $joins
|
||||||
* @param string $alias the alias to search for
|
* @param string $alias the alias to search for
|
||||||
* @return boolean
|
* @return boolean
|
||||||
@ -131,7 +132,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add('level', 'choice', array(
|
$builder->add('level', ChoiceType::class, array(
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
'By reason' => 'reasons',
|
'By reason' => 'reasons',
|
||||||
'By category of reason' => 'categories'
|
'By category of reason' => 'categories'
|
||||||
@ -153,7 +154,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
'label' => 'Reason\'s level'
|
'label' => 'Reason\'s level'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateForm($data, ExecutionContextInterface $context)
|
public function validateForm($data, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
if ($data['level'] === null) {
|
if ($data['level'] === null) {
|
||||||
@ -166,7 +167,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
{
|
{
|
||||||
return "Aggregate by activity reason";
|
return "Aggregate by activity reason";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRole()
|
public function addRole()
|
||||||
{
|
{
|
||||||
return new Role(ActivityStatsVoter::STATS);
|
return new Role(ActivityStatsVoter::STATS);
|
||||||
@ -186,7 +187,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
throw new \RuntimeException(sprintf("the level data '%s' is invalid",
|
throw new \RuntimeException(sprintf("the level data '%s' is invalid",
|
||||||
$data['level']));
|
$data['level']));
|
||||||
}
|
}
|
||||||
|
|
||||||
return function($value) use ($data) {
|
return function($value) use ($data) {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return $data['level'] === 'reasons' ?
|
return $data['level'] === 'reasons' ?
|
||||||
@ -195,12 +196,12 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
'Group by categories of reason'
|
'Group by categories of reason'
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($data['level']) {
|
switch ($data['level']) {
|
||||||
case 'reasons':
|
case 'reasons':
|
||||||
/* @var $r \Chill\ActivityBundle\Entity\ActivityReason */
|
/* @var $r \Chill\ActivityBundle\Entity\ActivityReason */
|
||||||
$r = $this->reasonRepository->find($value);
|
$r = $this->reasonRepository->find($value);
|
||||||
|
|
||||||
return $this->stringHelper->localize($r->getCategory()->getName())
|
return $this->stringHelper->localize($r->getCategory()->getName())
|
||||||
." > "
|
." > "
|
||||||
. $this->stringHelper->localize($r->getName());
|
. $this->stringHelper->localize($r->getName());
|
||||||
@ -208,13 +209,13 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
break;
|
break;
|
||||||
case 'categories':
|
case 'categories':
|
||||||
$c = $this->categoryRepository->find($value);
|
$c = $this->categoryRepository->find($value);
|
||||||
|
|
||||||
return $this->stringHelper->localize($c->getName());
|
return $this->stringHelper->localize($c->getName());
|
||||||
break;
|
break;
|
||||||
// no need for a default : the default was already set above
|
// no need for a default : the default was already set above
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryKeys($data)
|
public function getQueryKeys($data)
|
||||||
@ -227,7 +228,7 @@ class ActivityReasonAggregator implements AggregatorInterface,
|
|||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('the data provided are not recognised');
|
throw new \RuntimeException('the data provided are not recognised');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user