@use('App\Models\CharityDocument') @props(['charity']) @php // Documents hang off (country_code, registration_number), so this is the // same set whichever tax-year row the page happens to be rendering. // publicUrl() is what decides between the charity's own server, a copy // held here, and a file only ever uploaded here — a row that points // nowhere yet is simply not shown. $documents = CharityDocument::forCharity($charity) ->get() ->filter(fn ($document) => $document->publicUrl() !== null); // Grouped in the order CharityDocument::TYPES declares, not the order the // rows came back in: annual reports are what a reader came for. $groups = collect(CharityDocument::TYPES) ->map(fn ($label, $type) => $documents->where('type', $type)->values()) ->filter(fn ($group) => $group->isNotEmpty()); $anyHeldHere = $documents->contains(fn ($document) => $document->isServedLocally()); @endphp @if ($groups->isNotEmpty())
Reports & Documents
@foreach ($groups as $type => $group)
{{ CharityDocument::TYPES[$type] }}
@foreach ($group as $document) @php $url = $document->publicUrl(); $local = $document->isServedLocally(); $origin = $document->externalUrl(); $host = $origin ? (parse_url($origin, PHP_URL_HOST) ?: '') : ''; $meta = collect([ $document->year, $document->isPdf() ? 'PDF' : null, $local ? $document->storedSizeForHumans() : null, // Where the file a visitor is about to open // actually lives. $local ? 'held on this site' : $host, ])->filter()->join(' · '); @endphp
{{ $document->displayTitle() }} {{ $meta }} {{-- A copy is only trustworthy if the address it was taken from is still on the page. Sibling, not nested: an anchor inside an anchor is invalid and the browser un-nests it. --}} @if ($local && $origin && ! $document->isUpload()) Original on {{ $host ?: 'the charity’s site' }} ↗ @endif
@endforeach
@endforeach

@if ($anyHeldHere) Published by the charity itself. Where a copy is held on this site it is stored unchanged, so the link survives the original being moved or taken down — the original address is linked alongside it. @else Published by the charity itself and linked here unchanged — ARK AID does not host these files. @endif

@endif