ottimizzazione Visualizzazione lista e singoli
This commit is contained in:
@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Pcrt\Component\Circolari\Site\Model;
|
|
||||||
|
|
||||||
\defined('_JEXEC') or die;
|
|
||||||
|
|
||||||
use Joomla\CMS\MVC\Model\ListModel;
|
|
||||||
|
|
||||||
class CircolariModel extends ListModel
|
|
||||||
{
|
|
||||||
protected $context = 'com_circolari.circolari';
|
|
||||||
|
|
||||||
protected function getListQuery()
|
|
||||||
{
|
|
||||||
$db = $this->getDatabase();
|
|
||||||
$q = $db->getQuery(true)
|
|
||||||
->select('c.*') // evita errori per colonne mancanti
|
|
||||||
->from($db->quoteName('#__circolari') . ' AS c');
|
|
||||||
|
|
||||||
// Colonne realmente presenti
|
|
||||||
$cols = array_change_key_case(
|
|
||||||
$db->getTableColumns($db->replacePrefix('#__circolari'), false),
|
|
||||||
CASE_LOWER
|
|
||||||
);
|
|
||||||
|
|
||||||
// Stato (solo se esiste la colonna)
|
|
||||||
if (isset($cols['state'])) {
|
|
||||||
$q->where('COALESCE(c.state, 1) = 1');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filtro categoria (solo se esiste colonna e valore)
|
|
||||||
$catid = (int) $this->getState('filter.catid', 0);
|
|
||||||
if ($catid > 0 && isset($cols['catid'])) {
|
|
||||||
$q->where('c.catid = ' . $catid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ordinamento (ripiega su id se la colonna non c'è)
|
|
||||||
$orderCol = (string) $this->getState('list.ordering', 'c.id');
|
|
||||||
$orderDir = strtoupper((string) $this->getState('list.direction', 'DESC')) === 'ASC' ? 'ASC' : 'DESC';
|
|
||||||
$orderKey = ltrim(str_ireplace('c.', '', $orderCol));
|
|
||||||
if (!isset($cols[strtolower($orderKey)])) {
|
|
||||||
$orderCol = 'c.id';
|
|
||||||
}
|
|
||||||
$q->order($db->escape($orderCol . ' ' . $orderDir));
|
|
||||||
|
|
||||||
return $q;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getItems()
|
|
||||||
{
|
|
||||||
$items = parent::getItems();
|
|
||||||
if (!is_array($items)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
// Filtra eventuali elementi nulli/invalidi
|
|
||||||
return array_values(array_filter($items, static function ($it) {
|
|
||||||
return is_object($it) && isset($it->id) && (int) $it->id > 0;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Pcrt\Component\Circolari\Site\View\Circolare;
|
namespace Pcrt\Component\Circolari\Site\View\Circolare;
|
||||||
|
|
||||||
\defined('_JEXEC') or die;
|
\defined('_JEXEC') or die;
|
||||||
@ -20,31 +21,11 @@ class HtmlView extends BaseHtmlView
|
|||||||
$this->item = $this->get('Item');
|
$this->item = $this->get('Item');
|
||||||
|
|
||||||
// Se NON c'è l'item → mostra la lista
|
// Se NON c'è l'item → mostra la lista
|
||||||
if (!$this->item) {
|
if (!$this->item) {
|
||||||
$app = \Joomla\CMS\Factory::getApplication();
|
$this->setLayout('default');
|
||||||
$factory = $app->bootComponent('com_circolari')->getMVCFactory();
|
$this->addTemplatePath(JPATH_COMPONENT_SITE . '/tmpl/circolari');
|
||||||
|
return parent::display($tpl);
|
||||||
/** @var \Pcrt\Component\Circolari\Site\Model\CircolariModel $model */
|
}
|
||||||
$model = $factory->createModel('Circolari', 'Site', ['ignore_request' => true]);
|
|
||||||
|
|
||||||
// Imposta gli stati MANUALMENTE (niente populateState: è protected)
|
|
||||||
$model->setState('filter.catid', 0); // nessun filtro categoria
|
|
||||||
$model->setState('list.start', 0);
|
|
||||||
$model->setState('list.limit', 0); // 0 = nessun limite (tutte)
|
|
||||||
$model->setState('list.ordering', 'c.id'); // colonna di ordinamento
|
|
||||||
$model->setState('list.direction', 'DESC'); // direzione
|
|
||||||
|
|
||||||
// Recupera i dati
|
|
||||||
$this->state = $model->getState();
|
|
||||||
$this->items = $model->getItems();
|
|
||||||
$this->pagination = $model->getPagination();
|
|
||||||
|
|
||||||
// Usa il layout della lista (tmpl/circolari/default.php)
|
|
||||||
$this->setLayout('default');
|
|
||||||
$this->addTemplatePath(JPATH_COMPONENT_SITE . '/tmpl/circolari');
|
|
||||||
|
|
||||||
return parent::display($tpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering normale della singola
|
// Rendering normale della singola
|
||||||
return parent::display($tpl);
|
return parent::display($tpl);
|
||||||
|
|||||||
@ -7,15 +7,8 @@ use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
|||||||
|
|
||||||
class HtmlView extends BaseHtmlView
|
class HtmlView extends BaseHtmlView
|
||||||
{
|
{
|
||||||
public $items;
|
|
||||||
public $pagination;
|
|
||||||
public $state;
|
|
||||||
|
|
||||||
public function display($tpl = null)
|
public function display($tpl = null)
|
||||||
{
|
{
|
||||||
$this->state = $this->get('State');
|
return parent::display($tpl); // il template carica i moduli
|
||||||
$this->items = $this->get('Items');
|
|
||||||
$this->pagination = $this->get('Pagination');
|
|
||||||
return parent::display($tpl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,20 +7,20 @@ use Joomla\CMS\Language\Text;
|
|||||||
/** @var \Pcrt\Component\Circolari\Site\View\Circolare\HtmlView $this */
|
/** @var \Pcrt\Component\Circolari\Site\View\Circolare\HtmlView $this */
|
||||||
$item = $this->item;
|
$item = $this->item;
|
||||||
?>
|
?>
|
||||||
<article class="com-content-article item-page">
|
|
||||||
<header class="page-header">
|
|
||||||
<h1 class="page-title"><?php echo htmlspecialchars($item->title ?: 'Circolare'); ?></h1>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="article-body mt-3">
|
<div class="container my-5 mega-container">
|
||||||
<?php echo $item->description ?: $item->testo ?: $item->descrizione ?: '<em>(Nessun testo)</em>'; ?>
|
|
||||||
|
<div class="row mb-4 align-items-end">
|
||||||
|
<div class="col-md-9 col-12">
|
||||||
|
<h1 class="h2 mb-1"><?= $this->escape($item->title); ?></h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3 col-12 text-md-end mt-2 mt-md-0">
|
||||||
|
<a href="#" class="small text-decoration-none text-uppercase fw-bold">Condividi</a>
|
||||||
|
</div>
|
||||||
|
<div class="article-body mt-3">
|
||||||
|
<?php echo $item->description ?: $item->testo ?: $item->descrizione ?: '<em>(Nessun testo)</em>'; ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (!empty($item->attachment)) : ?>
|
</div>
|
||||||
<p class="mt-3">
|
|
||||||
<a href="<?php echo htmlspecialchars($item->attachment); ?>" target="_blank" rel="noopener">
|
|
||||||
<?php echo Text::_('COM_CIRCOLARI_DOWNLOAD_ATTACHMENT') ?: 'Scarica allegato'; ?>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<?php endif; ?>
|
|
||||||
</article>
|
|
||||||
@ -1,43 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
\defined('_JEXEC') or die;
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
use Joomla\CMS\Router\Route;
|
use Joomla\CMS\Helper\ModuleHelper;
|
||||||
use Joomla\CMS\Language\Text;
|
|
||||||
use Joomla\CMS\Factory;
|
|
||||||
|
|
||||||
$rows = $this->items ?? [];
|
// posizione dove pubblichi il tuo modulo (es. mod_circolari)
|
||||||
if (!is_array($rows)) $rows = (array) $rows;
|
$position = 'circolari-list';
|
||||||
$rows = array_values(array_filter($rows, static function ($it) {
|
|
||||||
return is_object($it) && !empty($it->id);
|
|
||||||
}));
|
|
||||||
|
|
||||||
$Itemid = (int) (Factory::getApplication()->input->getInt('Itemid') ?: 0);
|
$modules = ModuleHelper::getModules($position); // rispetta l'assegnazione alla voce di menu attiva
|
||||||
?>
|
if (empty($modules)) {
|
||||||
<div class="circolari-list">
|
echo '<div class="alert alert-warning">Nessun modulo assegnato alla posizione "' . htmlspecialchars($position) . '".</div>';
|
||||||
<?php if (!count($rows)) : ?>
|
} else {
|
||||||
<p><?php echo htmlspecialchars(Text::_('COM_CIRCOLARI_NO_ITEMS') ?: 'Nessuna circolare', ENT_QUOTES, 'UTF-8'); ?></p>
|
foreach ($modules as $module) {
|
||||||
<?php else : ?>
|
echo ModuleHelper::renderModule($module, ['style' => 'xhtml']); // oppure 'none', 'html5', ecc.
|
||||||
<ul class="circolari-list__ul">
|
}
|
||||||
<?php foreach ($rows as $item) : ?>
|
}
|
||||||
<?php
|
|
||||||
$url = Route::_(
|
|
||||||
'index.php?option=com_circolari&view=circolare'
|
|
||||||
. '&id=' . (int) $item->id
|
|
||||||
. '&catid=' . (int) ($item->catid ?? 0)
|
|
||||||
. ($Itemid ? '&Itemid=' . $Itemid : '')
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
<li class="circolari-list__li">
|
|
||||||
<a href="<?php echo $url; ?>">
|
|
||||||
<?php echo htmlspecialchars($item->title ?? ('#' . (int) $item->id), ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
</a>
|
|
||||||
<?php if (!empty($item->attachment)) : ?>
|
|
||||||
<small> — <a href="<?php echo htmlspecialchars($item->attachment, ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener">
|
|
||||||
<?php echo Text::_('COM_CIRCOLARI_READ_PDF') ?: 'PDF'; ?>
|
|
||||||
</a></small>
|
|
||||||
<?php endif; ?>
|
|
||||||
</li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user