mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46: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\Export\AggregatorInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
||||||
|
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
class GoalResultAggregator implements AggregatorInterface
|
class GoalResultAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
//private ResultRepository $resultRepository;
|
private ResultRepository $resultRepository;
|
||||||
|
|
||||||
|
private GoalRepository $goalRepository;
|
||||||
|
|
||||||
private TranslatableStringHelper $translatableStringHelper;
|
private TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
//ResultRepository $resultRepository,
|
ResultRepository $resultRepository,
|
||||||
|
GoalRepository $goalRepository,
|
||||||
TranslatableStringHelper $translatableStringHelper
|
TranslatableStringHelper $translatableStringHelper
|
||||||
) {
|
) {
|
||||||
//$this->resultRepository = $resultRepository;
|
$this->resultRepository = $resultRepository;
|
||||||
|
$this->goalRepository = $goalRepository;
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,19 +34,35 @@ class GoalResultAggregator implements AggregatorInterface
|
|||||||
*/
|
*/
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data)
|
||||||
{
|
{
|
||||||
return function ($value): string {
|
return function ($value) use ($key): string {
|
||||||
if ('_header' === $value) {
|
switch ($key) {
|
||||||
return 'Goal and result Type';
|
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
|
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)
|
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)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
if (!in_array('acpwresult', $qb->getAllAliases(), true)) {
|
if (!in_array('result', $qb->getAllAliases(), true)) {
|
||||||
$qb->join('acpw.results', 'acpwresult');
|
$qb->join('acpw.results', 'result');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array('goal', $qb->getAllAliases(), true)) {
|
$qb->addSelect('result.id as result_aggregator');
|
||||||
$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');
|
|
||||||
|
|
||||||
$groupBy = $qb->getDQLPart('groupBy');
|
$groupBy = $qb->getDQLPart('groupBy');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user