From 36dfce661367234373db518c75323f871790da1c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 29 Oct 2025 14:38:50 +0100 Subject: [PATCH] Fix: export actions and their results in csv even when action does not have any goals attached to it. --- .../unreleased/Fixed-20251029-143836.yaml | 6 +++ .../SocialActionCSVExportService.php | 37 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changes/unreleased/Fixed-20251029-143836.yaml diff --git a/.changes/unreleased/Fixed-20251029-143836.yaml b/.changes/unreleased/Fixed-20251029-143836.yaml new file mode 100644 index 000000000..308ed0fca --- /dev/null +++ b/.changes/unreleased/Fixed-20251029-143836.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'Fix: export actions and their results in csv even when action does not have any goals attached to it.' +time: 2025-10-29T14:38:36.195220844+01:00 +custom: + Issue: "453" + SchemaChange: No schema change diff --git a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php index 09b4442b2..71c548dd1 100644 --- a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php +++ b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php @@ -42,28 +42,41 @@ final readonly class SocialActionCSVExportService $csv->insertOne($headers); foreach ($actions as $action) { - if ($action->getGoals()->isEmpty() && $action->getResults()->isEmpty() && $action->getEvaluations()->isEmpty()) { + $hasGoals = !$action->getGoals()->isEmpty(); + $hasResults = !$action->getResults()->isEmpty(); + $hasEvaluations = !$action->getEvaluations()->isEmpty(); + + // If action has no goals, results, or evaluations, insert a single row + if (!$hasGoals && !$hasResults && !$hasEvaluations) { $csv->insertOne($this->formatRow($action)); + continue; } - foreach ($action->getGoals() as $goal) { - if ($goal->getResults()->isEmpty()) { - $csv->insertOne($this->formatRow($action, $goal)); - } - - foreach ($goal->getResults() as $goalResult) { - $csv->insertOne($this->formatRow($action, $goal, $goalResult)); + // Process goals and their results + if ($hasGoals) { + foreach ($action->getGoals() as $goal) { + if ($goal->getResults()->isEmpty()) { + $csv->insertOne($this->formatRow($action, $goal)); + } else { + foreach ($goal->getResults() as $goalResult) { + $csv->insertOne($this->formatRow($action, $goal, $goalResult)); + } + } } } - foreach ($action->getResults() as $result) { - if ($result->getGoals()->isEmpty()) { + // Process results that are linked to this action (regardless of whether they have goals elsewhere) + if ($hasResults && !$hasGoals) { + foreach ($action->getResults() as $result) { $csv->insertOne($this->formatRow($action, null, null, $result)); } } - foreach ($action->getEvaluations() as $evaluation) { - $csv->insertOne($this->formatRow($action, evaluation: $evaluation)); + // Process evaluations + if ($hasEvaluations) { + foreach ($action->getEvaluations() as $evaluation) { + $csv->insertOne($this->formatRow($action, evaluation: $evaluation)); + } } }