Merge branch '__111_action_goal_result' into 111_exports_suite

This commit is contained in:
Mathieu Jaumotte 2022-09-19 13:55:16 +02:00
commit 1869f44ec6
5 changed files with 167 additions and 23 deletions

View File

@ -41,7 +41,7 @@ final class GoalAggregator implements AggregatorInterface
$qb->join('acpw.goals', 'goal');
}
$qb->addSelect('goal.id as goal_aggregator');
$qb->addSelect('IDENTITY(goal.goal) as goal_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@ -52,7 +52,7 @@ final class GoalAggregator implements AggregatorInterface
}
}
public function applyOn()
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
@ -70,17 +70,19 @@ final class GoalAggregator implements AggregatorInterface
}
$g = $this->goalRepository->find($value);
return $this->translatableStringHelper->localize($g->getTitle());
return $this->translatableStringHelper->localize(
$g->getTitle()
);
};
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
return ['goal_aggregator'];
}
public function getTitle()
public function getTitle(): string
{
return 'Group social work actions by goal';
}

View File

@ -0,0 +1,138 @@
<?php
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 GoalRepository $goalRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
ResultRepository $resultRepository,
GoalRepository $goalRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->resultRepository = $resultRepository;
$this->goalRepository = $goalRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
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();
}
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return [
'goal_aggregator',
'result_aggregator'
];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group social work actions by goal and result';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
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');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -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');
@ -60,7 +52,7 @@ final class ResultAggregator implements AggregatorInterface
}
}
public function applyOn()
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
@ -77,18 +69,20 @@ final class ResultAggregator implements AggregatorInterface
return 'Result Type';
}
$g = $this->resultRepository->find($value);
$r = $this->resultRepository->find($value);
return $this->translatableStringHelper->localize($g->getTitle());
return $this->translatableStringHelper->localize(
$r->getTitle()
);
};
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
return ['result_aggregator'];
}
public function getTitle()
public function getTitle(): string
{
return 'Group social work actions by result';
}

View File

@ -79,3 +79,10 @@ services:
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_result_aggregator }
chill.person.export.aggregator_goalresult:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalResultAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_goal_result_aggregator }

View File

@ -560,8 +560,11 @@ Group by treating agent: Grouper les actions par agent traitant
Group social work actions by action type: Grouper les actions par type
Group social work actions by goal: Grouper les actions par objectif
Goal Type: Objectif
Group social work actions by result: Grouper les actions par résultat
Group social work actions by goal and result: Grouper les actions par objectif et résultat
Goal Type: Objectif
Result Type: Résultat
Goal and result Type: Objectif et résultat
## evaluations filters/aggr
Filter by evaluation type: Filtrer les évaluations par type