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