Skip to content

Commit

Permalink
[TM-1357] Quotation marks around fields within exports (#492)
Browse files Browse the repository at this point in the history
* changes

* changes

* [TM-1357 change delimiter]
  • Loading branch information
LimberHope authored Oct 4, 2024
1 parent be51e46 commit 54d134c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
16 changes: 2 additions & 14 deletions app/Exports/V2/BaseExportFormSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,11 @@ protected function getAnswer(array $field, array $answers): string
return $this->stringifyModel($answer, ['first_name', 'last_name', 'title', 'gender', 'percent_ownership', 'year_of_birth',]);

default:
if (is_string($answer)) {
$utf8Answer = mb_convert_encoding($answer, 'UTF-8', mb_detect_encoding($answer));
} else {
$utf8Answer = $answer ?? '';
}

return $utf8Answer;
return json_encode($answer);
}
}

if (is_string($answer)) {
$utf8Answer = mb_convert_encoding($answer, 'UTF-8', mb_detect_encoding($answer));
} else {
$utf8Answer = $answer ?? '';
}

return $utf8Answer ?? '';
return $answer ?? '';
}

protected function generateFieldMap(Form $form): array
Expand Down
10 changes: 5 additions & 5 deletions app/Exports/V2/EntityExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function map($entity): array
}

foreach ($this->auditFields as $key => $value) {
$mapped[] = mb_convert_encoding(data_get($entity, $key, ''), 'UTF-8', 'auto');
$mapped[] = data_get($entity, $key, '');
}

return $mapped;
Expand All @@ -91,8 +91,8 @@ protected function getAttachedMappedForEntity($entity): array

$mapped = array_merge($mapped, [
$organisation->readable_type ?? null,
mb_convert_encoding($organisation->name ?? null, 'UTF-8', 'auto'),
mb_convert_encoding($entity->project->name ?? null, 'UTF-8', 'auto'),
$organisation->name ?? null,
$entity->project->name ?? null,
$entity->status ?? null,
$entity->update_request_status ?? null,
$entity->due_at ?? null,
Expand All @@ -111,12 +111,12 @@ protected function getAttachedMappedForEntity($entity): array
}
if ($this->form->type === 'nursery-report') {
$mapped[] = $entity->nursery->old_id ?? ($entity->nursery->id ?? null);
$mapped[] = mb_convert_encoding($entity->nursery->name ?? null, 'UTF-8', 'auto');
$mapped[] = $entity->nursery->name ?? null;
}

if ($this->form->type === 'site-report') {
$mapped[] = $entity->site->ppc_external_id ?? $entity->site->id ?? null;
$mapped[] = mb_convert_encoding($entity->site->name ?? null, 'UTF-8', 'auto');
$mapped[] = $entity->site->name ?? null;
$sumTreeSpecies = $entity->treeSpecies()->sum('amount');
$mapped[] = $sumTreeSpecies > 0 ? $sumTreeSpecies : null;
$mapped[] = $entity->site->trees_planted_count ?? null;
Expand Down
4 changes: 2 additions & 2 deletions config/excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
|
*/
'csv' => [
'delimiter' => ';',
'delimiter' => ',',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => true,
'include_separator_line' => false,
'excel_compatibility' => false,
'output_encoding' => 'UTF-8',
'output_encoding' => '',
],

/*
Expand Down

0 comments on commit 54d134c

Please sign in to comment.