update component

This commit is contained in:
2025-09-23 11:54:33 +02:00
parent a05b127a0e
commit 1960c1b68c
16 changed files with 1197 additions and 535 deletions

View File

@ -144,7 +144,11 @@ if ($canAdmin) {
</div>
</div>
</div>
<?php if ($item->image): ?>
<div class="mb-4">
<img src="/<?php echo $item->image ?>" alt="" class="img-fluid h-50 w-100 shadow-sm" style="border-radius: 15px;">
</div>
<?php endif; ?>
<?php if ($item->firma_obbligatoria && $this->getModel()->userCanFirmare($item->id, $this->getModel()->currentUser->id) && !empty($buttons)) : ?>
<div class="mt-4">
<div class="d-flex flex-wrap gap-2" data-sign-group="circolare-<?php echo (int)$item->id; ?>">
@ -171,8 +175,7 @@ if ($canAdmin) {
</button>
<?php else: ?>
<form method="post"
action="<?=
Route::_('index.php?option=com_circolari&task=circolare.sign&id=' . (int)$item->id); ?>"
action="<?= Route::_('index.php?option=com_circolari&task=circolare.sign&id=' . (int)$item->id); ?>"
class="d-inline-block">
<input type="hidden" name="bottone_id" value="<?php echo $btnId; ?>">
<button type="submit"
@ -190,52 +193,139 @@ if ($canAdmin) {
<div class="article-body mt-3">
<?php echo $item->description; ?>
</div>
<h6>Allegati</h6>
<?php
$href = htmlspecialchars((string)($item->attachment ?? ''), ENT_QUOTES, 'UTF-8');
$label = htmlspecialchars((string)($item->allegato_titolo ?: 'Allegato'), ENT_QUOTES, 'UTF-8');
$title = 'Scarica ' . $label;
?>
<div class="row g-3 mb-2">
<div class="col-12 col-lg-6">
<div class="card card-documento card-bg card-icon rounded shadow-sm h-100">
<div class="card-body d-flex align-items-center">
<svg class="icon" aria-hidden="true" focusable="false" style="fill:#d1344c;">
<use xlink:href="/media/templates/site/tpl_istituzionale/images/sprites.svg#it-file-pdf"></use>
</svg>
<div class="card-icon-content">
<p class="mb-0">
<a
class="text-decoration-none"
href="<?php echo $href; ?>"
download
title="<?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>"
data-focus-mouse="false"
>
<strong><?php echo $label; ?></strong>
<span class="visually-hidden"> (file PDF)</span>
</a>
</p>
</div>
// 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
}
?>
<?php if (!empty($attachments)): ?>
<h6 class="mt-4"><?php echo JText::_('Allegati'); ?></h6>
<div class="row g-3 mb-2">
<?php foreach ($attachments as $att):
$hrefRaw = (string) ($att['href'] ?? '');
$labelRaw = (string) ($att['label'] ?? '');
// Fallback label = basename del file se non presente
$basename = basename(htmlspecialchars_decode($hrefRaw));
$label = trim($labelRaw) !== '' ? $labelRaw : $basename;
// Estensione per icona e testo accessibile
$ext = strtolower(pathinfo($basename, PATHINFO_EXTENSION));
if ($ext === 'jpeg') {
$ext = 'jpg';
} // coerenza
$iconId = _att_icon_id($ext);
$href = htmlspecialchars($hrefRaw, ENT_QUOTES, 'UTF-8');
$labelEsc = htmlspecialchars($label, ENT_QUOTES, 'UTF-8');
$titleAttr = 'Scarica ' . $label;
$titleEsc = htmlspecialchars($titleAttr, ENT_QUOTES, 'UTF-8');
// Testo accessibile sul tipo file (es. "file PDF", "file immagine", ecc.)
$a11yType = '';
switch ($iconId) {
case 'it-file-pdf':
$a11yType = ' (file PDF)';
break;
case 'it-file-image':
$a11yType = ' (file immagine)';
break;
case 'it-file-doc':
$a11yType = ' (documento)';
break;
case 'it-file-xls':
$a11yType = ' (foglio di calcolo)';
break;
case 'it-file-ppt':
$a11yType = ' (presentazione)';
break;
case 'it-file-zip':
$a11yType = ' (archivio compresso)';
break;
default:
$a11yType = $ext ? ' (file .' . htmlspecialchars($ext, ENT_QUOTES, 'UTF-8') . ')' : '';
}
?>
<div class="col-12 col-lg-6">
<div class="card card-documento card-bg card-icon rounded shadow-sm h-100">
<div class="card-body d-flex align-items-center">
<svg class="icon" aria-hidden="true" focusable="false" style="fill:#d1344c;">
<use xlink:href="<?php echo $spritePath . '#' . $iconId; ?>"></use>
</svg>
<div class="card-icon-content">
<p class="mb-0">
<a
class="text-decoration-none"
href="<?php echo $href; ?>"
download
title="<?php echo $titleEsc; ?>"
data-focus-mouse="false">
<strong><?php echo $labelEsc; ?></strong>
<span class="visually-hidden"><?php echo $a11yType; ?></span>
</a>
</p>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<style>
.card.card-icon .icon {
width: 34px;
height: 34px;
flex-shrink: 0;
margin: 0 8px 0 0;
}
<style>
.card.card-icon .icon {
width: 34px;
height: 34px;
flex-shrink: 0;
margin: 0 8px 0 0;
}
</style>
</style>
<?php if ($canAdmin): ?>
<?php if ($canAdmin & $item->firma_obbligatoria): ?>
<div class="card mt-4">
<div class="card-header d-flex justify-content-between align-items-center">
<strong>Firme ricevute</strong>