diff --git a/Classes/DataExporter/DataExporter.php b/Classes/DataExporter/DataExporter.php index d57b7e3..a946c9f 100644 --- a/Classes/DataExporter/DataExporter.php +++ b/Classes/DataExporter/DataExporter.php @@ -28,7 +28,7 @@ public function getExport($rowAnswers, FormEntryDemand $formEntryDemand, $useSub $rows[$uid][$formEntryDemand->getUidLabel()] = $uid; } foreach ($entry->getAnswers() as $fieldName => $field) { - if (!preg_match('/^fieldset/', $fieldName) && !preg_match('/^statictext/', $fieldName)) { + if ($this->isExportableType($field['conf']['inputType'])) { $rows[$uid][$fieldName] = (is_array($field['value']) ? implode(",", $field['value']) : $field['value']); } } @@ -54,9 +54,19 @@ protected function setHeaders($rowAnswers, FormEntryDemand $formEntryDemand, $he } foreach ($headerKeys as $field => $val) { - if ($val['conf']['inputType'] !== 'Fieldset' && $val['conf']['inputType'] !== 'StaticText') { + if ($this->isExportableType($val['conf']['inputType'])) { $header[] = ($val['conf']['label'] ? $val['conf']['label'] : $field); } } } + + private function isExportableType(string $inputType): bool + { + $typesToSkip = [ + 'Fieldset', + 'StaticText', + 'GridRow' + ]; + return !\in_array($inputType, $typesToSkip); + } } diff --git a/Classes/View/FormEntry/ExportCsv.php b/Classes/View/FormEntry/ExportCsv.php index f02a3c7..e08f6d2 100644 --- a/Classes/View/FormEntry/ExportCsv.php +++ b/Classes/View/FormEntry/ExportCsv.php @@ -63,7 +63,11 @@ public function initializeView() public function render() { foreach ($this->variables['rows'] as $fields) { - $this->fputcsv2($fields, $this->delimiter[$this->variables['formEntryDemand']->getDelimiter()], $this->enclosure[$this->variables['formEntryDemand']->getEnclosure()]); + $this->fputcsv2( + $fields, + $this->delimiter[$this->variables['formEntryDemand']->getDelimiter()], + $this->enclosure[$this->variables['formEntryDemand']->getEnclosure()] + ); } } @@ -88,6 +92,9 @@ private function fputcsv2(array $fields, $delimiter = ';', $enclosure = '"', $my $output[] = 'NULL'; continue; } + if ($field instanceof \DateTime) { + $field = $field->format('r'); + } $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field) ? ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure