exports: fix alterQuery and DescribeAction in SocialWorkTypeFilter

This commit is contained in:
Mathieu Jaumotte 2022-09-14 12:08:57 +02:00
parent 4cb6e8e564
commit 478afc893b
2 changed files with 63 additions and 31 deletions

View File

@ -50,17 +50,23 @@ class SocialWorkTypeFilter implements FilterInterface
$builder $builder
->add('actionType', HiddenType::class) ->add('actionType', HiddenType::class)
->get('actionType') ->get('actionType')
->addModelTransformer($this->iterableToIdTransformer(SocialAction::class)) ->addModelTransformer(
$this->iterableToIdTransformer(SocialAction::class)
)
; ;
$builder $builder
->add('goal', HiddenType::class) ->add('goal', HiddenType::class)
->get('goal') ->get('goal')
->addModelTransformer($this->iterableToIdTransformer(Goal::class)) ->addModelTransformer(
$this->iterableToIdTransformer(Goal::class)
)
; ;
$builder $builder
->add('result', HiddenType::class) ->add('result', HiddenType::class)
->get('result') ->get('result')
->addModelTransformer($this->iterableToIdTransformer(Result::class)) ->addModelTransformer(
$this->iterableToIdTransformer(Result::class)
)
; ;
} }
@ -90,27 +96,35 @@ class SocialWorkTypeFilter implements FilterInterface
public function getTitle(): string public function getTitle(): string
{ {
return 'Filter by type of action, objectives and results'; return 'Filter by type of action, goals and results';
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
$actionTypes = []; $actionTypes = [];
$objectives = []; $goals = [];
$results = []; $results = [];
foreach ($data['actionType'] as $at) { foreach ($data['actionType'] as $at) {
$actionTypes[] = $at->getTitle(); $actionTypes[] = $this->translatableStringHelper->localize(
} $at->getTitle()
foreach ($data['objectives'] as $o) { );
$objectives[] = $o->getTitle();
}
foreach ($data['results'] as $r) {
$results[] = $r->getTitle();
} }
return ['Filtered by referrers: only %actionTypes%', [ foreach ($data['goal'] as $g) {
'%actionTypes%' => implode(', ou ', $actionTypes) $goals[] = $this->translatableStringHelper->localize(
$g->getTitle()
);
}
foreach ($data['result'] as $r) {
$results[] = $this->translatableStringHelper->localize(
$r->getTitle()
);
}
return ['Filtered actions by type, goals and results: %selected%', [
'%selected%' => implode(', ', array_merge($actionTypes, $goals, $results))
]]; ]];
} }
@ -122,15 +136,9 @@ class SocialWorkTypeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$where = $qb->getDQLPart('where'); $where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('acpw.socialAction',':actionType');
/* if (count($data['actionType']) > 0) {
if (!empty($data['goal'])) { $clause = $qb->expr()->in('acpw.socialAction', ':actionType');
$clause
$qb->expr()->in('acpw.goals', ':goals');
}
$qb->expr()->in('acpw.results', ':results');
*/
if ($where instanceof Andx) { if ($where instanceof Andx) {
$where->add($clause); $where->add($clause);
@ -138,12 +146,34 @@ class SocialWorkTypeFilter implements FilterInterface
$where = $qb->expr()->andX($clause); $where = $qb->expr()->andX($clause);
} }
$qb->setParameter('actionType', $data['actionType']);
}
if (count($data['goal']) > 0) {
if (!in_array('goal', $qb->getAllAliases(), true)) {
$qb->join('acpw.goals', 'goal');
}
$where->add(
$qb->expr()->in('goal.id', ':goals')
);
$qb->setParameter('goals', $data['goal']);
}
if (count($data['result']) > 0) {
if (!in_array('result', $qb->getAllAliases(), true)) {
$qb->join('acpw.results', 'result');
}
$where->add(
$qb->expr()->in('result.id', ':results')
);
$qb->setParameter('results', $data['result']);
}
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameters([
'actionType' => $data['actionType'],
'goal' => $data['goal'],
'result' => $data['result'],
]);
} }
public function applyOn(): string public function applyOn(): string

View File

@ -456,7 +456,9 @@ Filter by socialaction: Filtrer les parcours par action d'accompagnement
Accepted socialactions: Actions d'accompagnement Accepted socialactions: Actions d'accompagnement
"Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%" "Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%"
Group by social action: Grouper les parcours par action d'accompagnement Group by social action: Grouper les parcours par action d'accompagnement
Filter by type of action, objectives and results: "Filtrer les actions par type, objectif et résultat"
Filter by type of action, goals and results: "Filtrer les actions par type, objectif et résultat"
'Filtered actions by type, goals and results: %selected%': "Actions filtrées par: %selected%"
Filter by evaluation: Filtrer les parcours par évaluation Filter by evaluation: Filtrer les parcours par évaluation
Accepted evaluations: Évaluations Accepted evaluations: Évaluations