mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
fix goalResult aggregator
This commit is contained in:
parent
37d49e1123
commit
91af01336a
@ -5,20 +5,26 @@ namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class GoalResultAggregator implements AggregatorInterface
|
||||
{
|
||||
//private ResultRepository $resultRepository;
|
||||
private ResultRepository $resultRepository;
|
||||
|
||||
private GoalRepository $goalRepository;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
//ResultRepository $resultRepository,
|
||||
ResultRepository $resultRepository,
|
||||
GoalRepository $goalRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
//$this->resultRepository = $resultRepository;
|
||||
$this->resultRepository = $resultRepository;
|
||||
$this->goalRepository = $goalRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
@ -28,19 +34,35 @@ class GoalResultAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'Goal and result Type';
|
||||
return function ($value) use ($key): string {
|
||||
switch ($key) {
|
||||
case 'goal_aggregator':
|
||||
|
||||
if ('_header' === $value) {
|
||||
return 'Goal Type';
|
||||
}
|
||||
|
||||
$g = $this->goalRepository->find($value);
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$g->getTitle()
|
||||
);
|
||||
|
||||
case 'result_aggregator':
|
||||
|
||||
if ('_header' === $value) {
|
||||
return 'Result Type';
|
||||
}
|
||||
|
||||
$r = $this->resultRepository->find($value);
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$r->getTitle()
|
||||
);
|
||||
|
||||
default:
|
||||
throw new \LogicException();
|
||||
}
|
||||
|
||||
//$g = $this->resultRepository->find($value);
|
||||
|
||||
return
|
||||
$value
|
||||
//$this->translatableStringHelper->localize(
|
||||
// $g->getTitle()
|
||||
//)
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
@ -49,7 +71,10 @@ class GoalResultAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['goal_result_aggregator'];
|
||||
return [
|
||||
'goal_aggregator',
|
||||
'result_aggregator'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +106,26 @@ class GoalResultAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
// TODO: Implement alterQuery() method.
|
||||
if (!in_array('goal', $qb->getAllAliases(), true)) {
|
||||
$qb->join('acpw.goals', 'goal');
|
||||
}
|
||||
|
||||
if (!in_array('goalresult', $qb->getAllAliases(), true)) {
|
||||
$qb->join('goal.results', 'goalresult');
|
||||
}
|
||||
|
||||
$qb->addSelect('IDENTITY(goal.goal) as goal_aggregator');
|
||||
$qb->addSelect('goalresult.id as result_aggregator');
|
||||
|
||||
$groupBy = $qb->getDQLPart('groupBy');
|
||||
|
||||
if (!empty($groupBy)) {
|
||||
$qb->addGroupBy('goal_aggregator');
|
||||
} else {
|
||||
$qb->groupBy('goal_aggregator');
|
||||
}
|
||||
|
||||
$qb->addGroupBy('result_aggregator');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,19 +37,11 @@ final class ResultAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('acpwresult', $qb->getAllAliases(), true)) {
|
||||
$qb->join('acpw.results', 'acpwresult');
|
||||
if (!in_array('result', $qb->getAllAliases(), true)) {
|
||||
$qb->join('acpw.results', 'result');
|
||||
}
|
||||
|
||||
if (!in_array('goal', $qb->getAllAliases(), true)) {
|
||||
$qb->join('acpw.goals', 'goal');
|
||||
}
|
||||
|
||||
if (!in_array('goalresult', $qb->getAllAliases(), true)) {
|
||||
$qb->join('goal.results', 'goalresult');
|
||||
}
|
||||
|
||||
$qb->addSelect('acpwresult.id, IDENTITY(goal.results) as result_aggregator');
|
||||
$qb->addSelect('result.id as result_aggregator');
|
||||
|
||||
$groupBy = $qb->getDQLPart('groupBy');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user