Skip to content

Commit

Permalink
fix: normalize submissions rows with the titles row
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Nov 2, 2024
1 parent c0af0a7 commit d8c1ffd
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit d8c1ffd

Please sign in to comment.