From 1538841e83c72e777adb9c79ab2f844bae6e4c6c Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 2 Nov 2024 16:01:18 +0100 Subject: [PATCH 1/4] fix: double $config = --- EMS/core-bundle/src/Controller/Form/SubmissionController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EMS/core-bundle/src/Controller/Form/SubmissionController.php b/EMS/core-bundle/src/Controller/Form/SubmissionController.php index 455fa5658..eb4ea01ce 100644 --- a/EMS/core-bundle/src/Controller/Form/SubmissionController.php +++ b/EMS/core-bundle/src/Controller/Form/SubmissionController.php @@ -53,7 +53,7 @@ public function indexAction(Request $request, UserInterface $user): Response case TableAbstract::DOWNLOAD_ACTION: return $this->downloadMultiple($table->getSelected()); case TableAbstract::EXPORT_ACTION: - $config = $config = $this->formSubmissionService->generateExportConfig($table->getSelected()); + $config = $this->formSubmissionService->generateExportConfig($table->getSelected()); return $this->spreadsheetGeneratorService->generateSpreadsheet($config); default: From 6d2b630152315b3a5ea408115b9f770cd49ec761 Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 2 Nov 2024 16:05:19 +0100 Subject: [PATCH 2/4] fix: don't remove empty fields to keep the form fields order --- .../src/Service/Form/Submission/FormSubmissionService.php | 1 - 1 file changed, 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 e49efedeb..70e02f266 100644 --- a/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php +++ b/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php @@ -129,7 +129,6 @@ public function generateExportConfig(array $formSubmissionIds): array $formSubmission = $this->getById($formSubmissionId); /** @var array $data */ $data = $formSubmission->getData(); - $data = \array_filter($data, fn ($value) => \is_string($value)); $data['id'] = $formSubmission->getId(); $data['form'] = $formSubmission->getName(); $data['instance'] = $formSubmission->getInstance(); From c0af0a76bb01f62732e835f678139e2c43948108 Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 2 Nov 2024 16:06:36 +0100 Subject: [PATCH 3/4] fix: merge submissions field names in case of some fields have been added, removed or renamed between submissions --- .../Service/Form/Submission/FormSubmissionService.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php b/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php index 70e02f266..dec71f920 100644 --- a/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php +++ b/EMS/core-bundle/src/Service/Form/Submission/FormSubmissionService.php @@ -138,13 +138,9 @@ public function generateExportConfig(array $formSubmissionIds): array $data['deadline'] = null === $expireDate ? '' : $expireDate->format('Y-m-d'); $sheetName = $formSubmission->getName(); - if (!\key_exists($sheetName, $sheets)) { - $titles = []; - foreach ($data as $key => $value) { - $titles[] = $key; - } - $sheets[$sheetName] = [$titles]; - } + $titles = $sheets[$sheetName][0] ?? []; + $titles = \array_unique(\array_merge($titles, \array_keys($data))); + $sheets[$sheetName][0] = $titles; $sheets[$sheetName] = \array_merge($sheets[$sheetName], [$data]); } From d8c1ffd2acd9ce4d87b28001defd4d5d50d087c9 Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 2 Nov 2024 16:08:14 +0100 Subject: [PATCH 4/4] 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; + } }