Skip to content

Commit

Permalink
[TM-928] Include a link to the TM Admin view of sites, nurseries, sit…
Browse files Browse the repository at this point in the history
…e reports and nursery reports in export.
  • Loading branch information
roguenet committed May 22, 2024
1 parent 1f810cd commit 28a1553
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions app/Exports/V2/EntityExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 28a1553

Please sign in to comment.