From 28a1553a31114775eceb3a0cd462c1ec61397143 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 21 May 2024 22:04:35 -0700 Subject: [PATCH] [TM-928] Include a link to the TM Admin view of sites, nurseries, site reports and nursery reports in export. --- app/Exports/V2/EntityExport.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Exports/V2/EntityExport.php b/app/Exports/V2/EntityExport.php index 01d692962..7481c9a8a 100644 --- a/app/Exports/V2/EntityExport.php +++ b/app/Exports/V2/EntityExport.php @@ -4,6 +4,7 @@ use App\Models\V2\Forms\Form; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Str; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; @@ -69,12 +70,24 @@ protected function getAttachedMappedForEntity($entity): array $mapped = [ $entity->ppc_external_id ?? $entity->old_id ?? $entity->id ?? null, $entity->uuid, + ]; + + if (in_array($this->form->type, ['site', 'nursery', 'site-report', 'nursery-report'])) { + $frontEndUrl = config('app.front_end'); + // Our environment variable definitions are inconsistent. + if (! Str::endsWith($frontEndUrl, '/')) { + $frontEndUrl .= '/'; + } + $mapped[] = $frontEndUrl . 'admin#/' . Str::camel($entity->shortName) . '/' . $entity->uuid . '/show'; + } + + $mapped = array_merge($mapped, [ $organisation->readable_type ?? null, $organisation->name ?? null, $entity->project->name ?? null, $entity->status ?? null, $entity->due_at ?? null, - ]; + ]); if (in_array($this->form->type, ['nursery', 'nursery-report', 'site', 'site-report', 'project-report'])) { $mapped[] = $entity->project->ppc_external_id ?? $entity->project->id ?? null; @@ -110,15 +123,19 @@ protected function getAttachedMappedForEntity($entity): array protected function getAttachedHeadingsForEntity(): array { - $initialHeadings = [ - 'id', - 'uuid', + $initialHeadings = ['id', 'uuid']; + + if (in_array($this->form->type, ['site', 'nursery', 'site-report', 'nursery-report'])) { + $initialHeadings[] = 'link_to_terramatch'; + } + + $initialHeadings = array_merge($initialHeadings, [ 'organization-readable_type', 'organization-name', 'project_name', 'status', 'due_date', - ]; + ]); if (in_array($this->form->type, ['nursery', 'nursery-report','site', 'site-report', 'project-report'])) { $initialHeadings[] = 'project-id';