Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Exporting all data #32

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/Controller/Backend/FormLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function exportAction(Filters $filters)
$this->view->setConfiguration([
'columns' => $this->settings['export']['columns'],
'dateTimeFormat' => $this->settings['dateTimeFormat'],
'labelPattern' => $this->settings['export']['labelPattern'],
'fileBasename' => $fileBasename,
]);
$this->view->assign('items', $this->formLogEntryRepository->findAllFiltered($filters));
Expand Down
41 changes: 41 additions & 0 deletions Classes/Mvc/View/Export/AbstractExportView.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,47 @@ protected function getColumnPaths()
return $columnPaths;
}

/**
* Extends the "__allData" placeholder within export column configuration with columns from first record.
*/
protected function extendAllDataPlaceholder()
{
if (empty($this->configuration['columns']) || !is_array($this->configuration['columns'])) {
return;
}

$newColumnConfiguration = [];
$columnProperties = array_column($this->configuration['columns'], 'property');

foreach ($this->configuration['columns'] as $key => $column) {
if (($column['property'] ?? '') === '__allData') {
$firstItem = $this->variables['items']->getFirst();
if ($firstItem !== null) {

/** @var \Pagemachine\Formlog\Domain\Model\FormLogEntry $firstItem */
$columns = $firstItem->getData();

foreach ($columns as $columnName => $columnValue) {
if (!in_array('data.' . $columnName, $columnProperties, true)) {
$columnConfiguration = [
'property' => 'data.' . $columnName,
'label' => $columnName,
];
if (!empty($this->configuration['labelPattern'])) {
$columnConfiguration['label'] = LocalizationUtility::translate(sprintf($this->configuration['labelPattern'], $columnName), 'Formlog') ?: $columnName;
}
$newColumnConfiguration[] = $columnConfiguration;
}
}
}
} else {
$newColumnConfiguration[] = $column;
}
}

$this->configuration['columns'] = $newColumnConfiguration;
}

/**
* Get the CSV output filename
*
Expand Down
1 change: 1 addition & 0 deletions Classes/Mvc/View/Export/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function render()
throw new \InvalidArgumentException('CSV export column configuration is empty', 1516620386);
}

$this->extendAllDataPlaceholder();
$headers = $this->getHeaders();
$columnPaths = $this->getColumnPaths();
$filename = $this->getOutputFilename();
Expand Down
1 change: 1 addition & 0 deletions Classes/Mvc/View/Export/XlsxView.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function render()
throw new \InvalidArgumentException('XLSX export column configuration is empty', 1517391761);
}

$this->extendAllDataPlaceholder();
$headers = $this->getHeaders();
$columnPaths = $this->getColumnPaths();
$filename = $this->getOutputFilename();
Expand Down
4 changes: 4 additions & 0 deletions ext_typoscript_setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module {
# }

export {
labelPattern = LLL:EXT:formlog/Resources/Language/locallang.xlf:formlog.entry.%s
columns {
10 {
property = uid
Expand All @@ -76,6 +77,9 @@ module {
property = submissionDate
label = formlog.entry.submissionDate
}
60 {
property = __allData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should integrate this a bit differently because it actually doesn't make sense to configure some columns explicitly only to have it ignored by this special column.

We could have an additional option at the same level as columns for this and maybe consider something like a labelPattern (like LLL:EXT:foo/locallang.xlf:formlog.entry.%s) where one could easily integrate custom labels.

}
}
}
}
Expand Down