improve exports & add new filter, export, aggregators

This commit is contained in:
2017-01-17 00:34:32 +01:00
parent b36ec02b65
commit 67c8c19885
8 changed files with 793 additions and 28 deletions

View File

@@ -26,6 +26,7 @@ use Symfony\Component\Security\Core\Role\Role;
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
use Doctrine\ORM\EntityRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\Query\Expr\Join;
/**
*
@@ -76,15 +77,23 @@ class ActivityReasonAggregator implements AggregatorInterface
}
$qb->addSelect($elem.' as '.$alias);
// make a jointure only if needed
// add a join to reasons only if needed
if (array_key_exists('activity', $qb->getDQLPart('join'))) {
// we want to avoid multiple join on same object
if (!$this->checkJoinAlreadyDefined($qb->getDQLPart('join')['activity'], 'reasons')) {
$qb->add('join', new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons'));
}
} else {
$qb->join('activity.reasons', 'reasons');
$join = $qb->getDQLPart('join');
if (
(array_key_exists('activity', $join)
&&
!$this->checkJoinAlreadyDefined($join['activity'], 'reasons')
)
OR
(! array_key_exists('activity', $join))
) {
$qb->add(
'join',
array('activity' =>
new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')
),
true);
}
// join category if necessary
@@ -178,19 +187,21 @@ class ActivityReasonAggregator implements AggregatorInterface
switch ($data['level']) {
case 'reasons':
$n = $this->reasonRepository->find($value)
->getName()
/* @var $r \Chill\ActivityBundle\Entity\ActivityReason */
$r = $this->reasonRepository->find($value);
return $this->stringHelper->localize($r->getCategory()->getName())
." > "
. $this->stringHelper->localize($r->getName());
;
break;
case 'categories':
$n = $this->categoryRepository->find($value)
->getName()
;
$c = $this->categoryRepository->find($value);
return $this->stringHelper->localize($c->getName());
break;
// no need for a default : the default was already set above
}
return $this->stringHelper->localize($n);
};
}