@use('App\Models\CharityDocument') @use('App\Services\DocumentMirror') @use('Illuminate\Support\Facades\Storage') {{-- A button to one of the charity's own documents — the newest of the type this column is configured for. The value arrives as the JSON object HomepageColumns::compileLink() built in the query (the address, the year, the title, and where the file is held), so a whole page of links costs no extra round trip. Only one document fits here; every report the charity has is listed on its detail page. Contract (set by charity-list-row.blade.php): $col, $value, $groupClass. --}} @php $document = is_string($value) ? json_decode($value, true) : null; // A copy held on our own disk wins over the address it came from — that is // the whole point of the toggle, and an upload has no address at all. $stored = is_array($document) ? trim((string) ($document['stored_path'] ?? '')) : ''; $isLocal = $stored !== '' && str_starts_with($stored, DocumentMirror::DIRECTORY . '/') && ((string) ($document['source'] ?? '') === CharityDocument::SOURCE_UPLOAD || (int) ($document['serve_local'] ?? 0) === 1); $url = $isLocal ? Storage::disk('public')->url($stored) : (is_array($document) ? trim((string) ($document['url'] ?? '')) : ''); // Only ever a link the browser will follow — the rows are admin-entered // and this cell is public. Our own copy is served from this origin, so it // is a path rather than an absolute address. $isSafe = $url !== '' && ($isLocal || preg_match('#^https?://#i', $url) === 1); $year = is_array($document) && ($document['year'] ?? null) !== null ? (int) $document['year'] : null; $title = is_array($document) ? trim((string) ($document['title'] ?? '')) : ''; $typeLabel = CharityDocument::TYPES[$col->document_type ?? ''] ?? CharityDocument::TYPES[CharityDocument::DEFAULT_TYPE]; // The pill has room for a year and nothing else, so everything else the // admin filed goes in the tooltip. $hover = $title !== '' ? $title : trim($typeLabel . ' ' . ($year ?? '')); @endphp