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
->add('actionType', HiddenType::class)
->get('actionType')
->addModelTransformer($this->iterableToIdTransformer(SocialAction::class))
->addModelTransformer(
$this->iterableToIdTransformer(SocialAction::class)
)
;
$builder
->add('goal', HiddenType::class)
->get('goal')
->addModelTransformer($this->iterableToIdTransformer(Goal::class))
->addModelTransformer(
$this->iterableToIdTransformer(Goal::class)
)
;
$builder
->add('result', HiddenType::class)
->get('result')
->addModelTransformer($this->iterableToIdTransformer(Result::class))
->addModelTransformer(
$this->iterableToIdTransformer(Result::class)
)
;
}
@ -90,27 +96,35 @@ class SocialWorkTypeFilter implements FilterInterface
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
{
$actionTypes = [];
$objectives = [];
$goals = [];
$results = [];
foreach ($data['actionType'] as $at) {
$actionTypes[] = $at->getTitle();
}
foreach ($data['objectives'] as $o) {
$objectives[] = $o->getTitle();
}
foreach ($data['results'] as $r) {
$results[] = $r->getTitle();
$actionTypes[] = $this->translatableStringHelper->localize(
$at->getTitle()
);
}
return ['Filtered by referrers: only %actionTypes%', [
'%actionTypes%' => implode(', ou ', $actionTypes)
foreach ($data['goal'] as $g) {
$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)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('acpw.socialAction',':actionType');
/*
if (!empty($data['goal'])) {
$clause
$qb->expr()->in('acpw.goals', ':goals');
}
$qb->expr()->in('acpw.results', ':results');
*/
if (count($data['actionType']) > 0) {
$clause = $qb->expr()->in('acpw.socialAction', ':actionType');
if ($where instanceof Andx) {
$where->add($clause);
@ -138,12 +146,34 @@ class SocialWorkTypeFilter implements FilterInterface
$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->setParameters([
'actionType' => $data['actionType'],
'goal' => $data['goal'],
'result' => $data['result'],
]);
}
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
"Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%"
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
Accepted evaluations: Évaluations