Skip to content

Commit

Permalink
Merge pull request #35 from frappant/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Wh0l3 authored Sep 28, 2020
2 parents cac5b02 + f4c10fe commit 27178af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Classes/DataExporter/DataExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
Expand All @@ -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);
}
}
9 changes: 8 additions & 1 deletion Classes/View/FormEntry/ExportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);
}
}

Expand All @@ -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
Expand Down

0 comments on commit 27178af

Please sign in to comment.