diff --git a/site/src/Controller/DisplayController.php b/site/src/Controller/DisplayController.php
index c0e48eb..898aa0e 100644
--- a/site/src/Controller/DisplayController.php
+++ b/site/src/Controller/DisplayController.php
@@ -3,20 +3,29 @@ namespace Pcrt\Component\Circolari\Site\Controller;
\defined('_JEXEC') or die;
+use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
class DisplayController extends BaseController
{
- protected $default_view = 'circolare'; // default se manca ?view=
-
public function display($cachable = false, $urlparams = [])
{
- // Se qualcuno forza un view strano, non rompiamo
- $view = $this->input->getCmd('view', $this->default_view);
- if (!in_array($view, ['circolare'], true)) {
- $view = $this->default_view;
- $this->input->set('view', $view);
+ $app = Factory::getApplication();
+ $in = $app->input;
+
+ $view = $in->getCmd('view', '');
+ $id = $in->getInt('id', 0);
+
+ if ($id > 0) {
+ // Singolo solo se c'è l'id
+ $in->set('view', 'circolare');
+ } else {
+ // Nessun id: forziamo la lista (anche se il menu chiede "circolare")
+ if ($view === '' || $view === 'circolare' || $view === 'category') {
+ $in->set('view', 'circolari'); // <- lista
+ }
}
+
return parent::display($cachable, $urlparams);
}
}
diff --git a/site/src/Model/CircolareModel.php b/site/src/Model/CircolareModel.php
index 9168335..0bbcf6a 100644
--- a/site/src/Model/CircolareModel.php
+++ b/site/src/Model/CircolareModel.php
@@ -3,31 +3,56 @@ namespace Pcrt\Component\Circolari\Site\Model;
\defined('_JEXEC') or die;
-use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ItemModel;
+use Joomla\CMS\Factory;
class CircolareModel extends ItemModel
{
- protected function populateState(): void
+ protected function populateState()
{
$app = Factory::getApplication();
- $this->setState('circolare.id', (int) $app->input->getInt('id'));
+ $id = $app->input->getInt('id', 0);
+ $this->setState('circolare.id', $id);
+
+ $catid = $app->input->getInt('catid', 0);
+ $this->setState('filter.catid', $catid);
parent::populateState();
}
public function getItem($pk = null)
{
- $pk = $pk ?: (int) $this->getState('circolare.id');
- if (!$pk) return null;
+ $pk = (int) ($pk ?: $this->getState('circolare.id'));
- $db = Factory::getContainer()->get('DatabaseDriver');
+ if ($pk <= 0) {
+ return null;
+ }
+
+ $db = $this->getDatabase();
$q = $db->getQuery(true)
- ->select('*')
- ->from($db->quoteName('#__circolari'))
- ->where($db->quoteName('id') . ' = ' . (int) $pk)
- ->where($db->quoteName('state') . ' = 1');
- $db->setQuery($q);
+ ->select('c.*') // <<< evita errori di colonne
+ ->from($db->quoteName('#__circolari') . ' AS c')
+ ->where('c.id = ' . (int) $pk);
- return $db->loadObject();
+ // Se esistono le colonne, applica filtri
+ $cols = array_change_key_case(
+ $db->getTableColumns($db->replacePrefix('#__circolari'), false),
+ CASE_LOWER
+ );
+
+ // catid (se impostato e colonna esiste)
+ $catid = (int) $this->getState('filter.catid', 0);
+ if ($catid > 0 && isset($cols['catid'])) {
+ $q->where('c.catid = ' . $catid);
+ }
+
+ // stato (se colonna esiste)
+ if (isset($cols['state'])) {
+ $q->where('COALESCE(c.state, 1) = 1');
+ }
+
+ $db->setQuery($q);
+ $row = $db->loadObject();
+
+ return $row ?: null;
}
}
diff --git a/site/src/Model/CircolariModel.php b/site/src/Model/CircolariModel.php
new file mode 100644
index 0000000..b970660
--- /dev/null
+++ b/site/src/Model/CircolariModel.php
@@ -0,0 +1,59 @@
+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;
+ }));
+ }
+}
diff --git a/site/src/Service/Category.php b/site/src/Service/Category.php
deleted file mode 100644
index c39c186..0000000
--- a/site/src/Service/Category.php
+++ /dev/null
@@ -1,21 +0,0 @@
-
- * @copyright 2025 Tommaso Cippitelli
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
-
-namespace Pcrt\Component\Circolari\Site\Service;
-// No direct access
-defined('_JEXEC') or die;
-
-use \Joomla\CMS\Categories\Categories;
-/**
- * Content Component Category Tree
- *
- * @since 1.0.0
- */
-
diff --git a/site/src/View/Circolare/HtmlView.php b/site/src/View/Circolare/HtmlView.php
index 08146db..4e8a012 100644
--- a/site/src/View/Circolare/HtmlView.php
+++ b/site/src/View/Circolare/HtmlView.php
@@ -3,35 +3,50 @@ namespace Pcrt\Component\Circolari\Site\View\Circolare;
\defined('_JEXEC') or die;
-use Joomla\CMS\Language\Text;
+use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
+use Joomla\CMS\Language\Text;
class HtmlView extends BaseHtmlView
{
protected $item;
+ public $items = [];
+ public $pagination;
+ public $state;
public function display($tpl = null)
{
+ // Carica la singola
$this->item = $this->get('Item');
- if (!$this->item) {
- throw new \Exception(Text::_('COM_CIRCOLARI_ITEM_NOT_FOUND'), 404);
- }
+ // Se NON c'è l'item → mostra la lista
+ if (!$this->item) {
+ $app = \Joomla\CMS\Factory::getApplication();
+ $factory = $app->bootComponent('com_circolari')->getMVCFactory();
- // Se il layout non c'è, stampa un fallback minimale (debug-friendly)
- $tplPath = JPATH_COMPONENT_SITE . '/tmpl/circolare/default.php';
- if (!is_file($tplPath)) {
- $title = htmlspecialchars($this->item->title ?? 'Circolare');
- $body = $this->item->description ?? $this->item->testo ?? $this->item->descrizione ?? '';
- $html = ''.$title.'