-
-
+ // Normalizza lista allegati: prima prova array $item->attachments (nuova logica),
+ // altrimenti fallback ai vecchi campi singoli $item->attachment / $item->allegato_titolo.
+ $attachments = [];
+
+ // 1) Nuova logica: array di allegati dal Model (path, title, ordering)
+ if (!empty($item->attachments) && is_array($item->attachments)) {
+ foreach ($item->attachments as $att) {
+ $path = (string) ($att['path'] ?? ($att->path ?? ''));
+ if ($path === '') continue;
+ $title = (string) ($att['title'] ?? ($att->title ?? ''));
+ $ord = (int) ($att['ordering'] ?? ($att->ordering ?? 0));
+ $attachments[] = ['href' => $path, 'label' => $title, 'ordering' => $ord];
+ }
+ }
+
+ // 2) Fallback legacy: singolo allegato
+ if (empty($attachments) && !empty($item->attachment)) {
+ $attachments[] = [
+ 'href' => (string) $item->attachment,
+ 'label' => (string) ($item->allegato_titolo ?: ''),
+ 'ordering' => 0,
+ ];
+ }
+
+ // Ordina per ordering, poi per label
+ usort($attachments, function ($a, $b) {
+ $o = ($a['ordering'] <=> $b['ordering']);
+ if ($o !== 0) return $o;
+ return strcmp((string)$a['label'], (string)$b['label']);
+ });
+
+ // Mappa icone in base all'estensione (puoi adattare gli id alle tue sprite)
+ $spritePath = '/media/templates/site/tpl_istituzionale/images/sprites.svg';
+ function _att_icon_id(string $ext): string
+ {
+ $ext = strtolower($ext);
+ if (in_array($ext, ['pdf'], true)) return 'it-file-pdf';
+ if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg', 'tif', 'tiff', 'heic', 'heif'], true)) return 'it-file-image';
+ if (in_array($ext, ['doc', 'docx', 'rtf', 'odt'], true)) return 'it-file-doc';
+ if (in_array($ext, ['xls', 'xlsx', 'ods', 'csv'], true)) return 'it-file-xls';
+ if (in_array($ext, ['ppt', 'pptx', 'odp'], true)) return 'it-file-ppt';
+ if (in_array($ext, ['zip', 'rar', '7z', 'gz', 'bz2', 'tar'], true)) return 'it-file-zip';
+ return 'it-file'; // generico
+ }
+ ?>
+
+
+
+
-