Skip to content

Commit

Permalink
[ClacoForm] fixes entries export
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Nov 7, 2023
1 parent 97d5f23 commit ccbbfd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/plugin/claco-form/Controller/ClacoFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ public function clacoFormEntriesExportAction(ClacoForm $clacoForm): BinaryFileRe
{
$this->checkPermission('EDIT', $clacoForm->getResourceNode(), [], true);

$exportPath = $this->exportManager->exportEntries($clacoForm);
$export = $this->exportManager->exportEntries($clacoForm);

return new BinaryFileResponse($exportPath, 200, [
'Content-Disposition' => 'attachment; filename='.urlencode($clacoForm->getResourceNode()->getName()),
return new BinaryFileResponse($export[0], 200, [
'Content-Disposition' => 'attachment; filename='.$export[1],
]);
}

Expand Down
22 changes: 12 additions & 10 deletions src/plugin/claco-form/Manager/ExportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function generatePdfForEntry(Entry $entry, User $user)
);
}

public function exportEntries(ClacoForm $clacoForm): string
public function exportEntries(ClacoForm $clacoForm): array
{
$files = [];
$entriesData = [];
Expand Down Expand Up @@ -190,19 +190,21 @@ public function exportEntries(ClacoForm $clacoForm): string
$exportedFile = $this->tempManager->generate();
if (empty($files)) {
file_put_contents($exportedFile, $entryList);
} else {
$archive = new \ZipArchive();
$archive->open($exportedFile, \ZipArchive::CREATE);

$archive->addFromString(TextNormalizer::toKey($clacoForm->getResourceNode()->getName()).'.xls', $entryList);
foreach ($files as $filePath => $fileName) {
$archive->addFile($filePath, $fileName);
}
return [$exportedFile, TextNormalizer::toKey($clacoForm->getResourceNode()->getName()).'.xls'];
}

$archive->close();
$archive = new \ZipArchive();
$archive->open($exportedFile, \ZipArchive::CREATE);

$archive->addFromString(TextNormalizer::toKey($clacoForm->getResourceNode()->getName()).'.xls', $entryList);
foreach ($files as $filePath => $fileName) {
$archive->addFile($filePath, $fileName);
}

return $exportedFile;
$archive->close();

return [$exportedFile, TextNormalizer::toKey($clacoForm->getResourceNode()->getName()).'.zip'];
}

private function formatFieldValue(Entry $entry, Field $field, $value, ?bool $stripHtml = false)
Expand Down

0 comments on commit ccbbfd2

Please sign in to comment.