From d8c1ffd2acd9ce4d87b28001defd4d5d50d087c9 Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 2 Nov 2024 16:08:14 +0100 Subject: [PATCH] fix: normalize submissions rows with the titles row --- .../Form/Submission/FormSubmissionService.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php b/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php index dec71f920..44591f0a3 100644 --- a/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php +++ b/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php @@ -148,7 +148,7 @@ public function generateExportConfig(array $formSubmissionIds): array foreach ($sheets as $key => $value) { $config['sheets'][] = [ 'name' => $key, - 'rows' => $value, + 'rows' => $this->normalizeRows($value), ]; } @@ -290,4 +290,21 @@ public function deleteByItemName(string $name): string { throw new \RuntimeException('deleteByItemName method not yet implemented'); } + + /** + * @param mixed[][] $rows + * @return mixed[][] + */ + private function normalizeRows(array $rows): array + { + if (\count($rows) < 2) { + return $rows; + } + $titles = $rows[0]; + for ($i = 1; $i < \count($rows); ++$i) { + $rows[$i] = \array_map(fn (string $key) => $rows[$i][$key] ?? null, $titles); + } + + return $rows; + } }