aggiunta vista singola circolare
This commit is contained in:
@ -1,64 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @version CVS: 1.0.0
|
|
||||||
* @package Com_Circolari
|
|
||||||
* @author Tommaso Cippitelli <tommaso.cippitelli@protocollicreativi.it>
|
|
||||||
* @copyright 2025 Tommaso Cippitelli
|
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Pcrt\Component\Circolari\Site\Controller;
|
namespace Pcrt\Component\Circolari\Site\Controller;
|
||||||
|
|
||||||
\defined('_JEXEC') or die;
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
use Joomla\CMS\Component\ComponentHelper;
|
use Joomla\CMS\MVC\Controller\BaseController;
|
||||||
use Joomla\CMS\Factory;
|
|
||||||
use Joomla\CMS\Language\Text;
|
|
||||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
|
||||||
|
|
||||||
/**
|
class DisplayController extends BaseController
|
||||||
* Display Component Controller
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
class DisplayController extends \Joomla\CMS\MVC\Controller\BaseController
|
|
||||||
{
|
{
|
||||||
/**
|
protected $default_view = 'circolare'; // default se manca ?view=
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param array $config An optional associative array of configuration settings.
|
|
||||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
|
||||||
* 'view_path' (this list is not meant to be comprehensive).
|
|
||||||
* @param MVCFactoryInterface $factory The factory.
|
|
||||||
* @param CMSApplication $app The JApplication for the dispatcher
|
|
||||||
* @param Input $input Input
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __construct($config = array(), ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
|
||||||
{
|
|
||||||
parent::__construct($config, $factory, $app, $input);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function display($cachable = false, $urlparams = [])
|
||||||
* Method to display a view.
|
{
|
||||||
*
|
// Se qualcuno forza un view strano, non rompiamo
|
||||||
* @param boolean $cachable If true, the view output will be cached.
|
$view = $this->input->getCmd('view', $this->default_view);
|
||||||
* @param boolean $urlparams An array of safe URL parameters and their variable types, for valid values see {@link InputFilter::clean()}.
|
if (!in_array($view, ['circolare'], true)) {
|
||||||
*
|
$view = $this->default_view;
|
||||||
* @return \Joomla\CMS\MVC\Controller\BaseController This object to support chaining.
|
$this->input->set('view', $view);
|
||||||
*
|
}
|
||||||
* @since 1.0.0
|
return parent::display($cachable, $urlparams);
|
||||||
*/
|
}
|
||||||
public function display($cachable = false, $urlparams = false)
|
|
||||||
{
|
|
||||||
|
|
||||||
$view = $this->input->getCmd('view', 'circolares');
|
|
||||||
$view = $view == "featured" ? 'circolares' : $view;
|
|
||||||
$this->input->set('view', $view);
|
|
||||||
|
|
||||||
|
|
||||||
parent::display($cachable, $urlparams);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
site/src/Model/CircolareModel.php
Normal file
33
site/src/Model/CircolareModel.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace Pcrt\Component\Circolari\Site\Model;
|
||||||
|
|
||||||
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
use Joomla\CMS\Factory;
|
||||||
|
use Joomla\CMS\MVC\Model\ItemModel;
|
||||||
|
|
||||||
|
class CircolareModel extends ItemModel
|
||||||
|
{
|
||||||
|
protected function populateState(): void
|
||||||
|
{
|
||||||
|
$app = Factory::getApplication();
|
||||||
|
$this->setState('circolare.id', (int) $app->input->getInt('id'));
|
||||||
|
parent::populateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItem($pk = null)
|
||||||
|
{
|
||||||
|
$pk = $pk ?: (int) $this->getState('circolare.id');
|
||||||
|
if (!$pk) return null;
|
||||||
|
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
$q = $db->getQuery(true)
|
||||||
|
->select('*')
|
||||||
|
->from($db->quoteName('#__circolari'))
|
||||||
|
->where($db->quoteName('id') . ' = ' . (int) $pk)
|
||||||
|
->where($db->quoteName('state') . ' = 1');
|
||||||
|
$db->setQuery($q);
|
||||||
|
|
||||||
|
return $db->loadObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,95 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @version CVS: 1.0.0
|
|
||||||
* @package Com_Circolari
|
|
||||||
* @author Tommaso Cippitelli <tommaso.cippitelli@protocollicreativi.it>
|
|
||||||
* @copyright 2025 Tommaso Cippitelli
|
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Pcrt\Component\Circolari\Site\Service;
|
namespace Pcrt\Component\Circolari\Site\Service;
|
||||||
|
|
||||||
// No direct access
|
\defined('_JEXEC') or die;
|
||||||
defined('_JEXEC') or die;
|
|
||||||
|
|
||||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
|
||||||
use Joomla\CMS\Component\Router\RouterView;
|
|
||||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
|
||||||
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
|
||||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
|
||||||
use Joomla\CMS\Factory;
|
|
||||||
use Joomla\CMS\Categories\Categories;
|
|
||||||
use Joomla\CMS\Application\SiteApplication;
|
use Joomla\CMS\Application\SiteApplication;
|
||||||
use Joomla\CMS\Categories\CategoryFactoryInterface;
|
|
||||||
use Joomla\CMS\Categories\CategoryInterface;
|
|
||||||
use Joomla\Database\DatabaseInterface;
|
|
||||||
use Joomla\CMS\Menu\AbstractMenu;
|
use Joomla\CMS\Menu\AbstractMenu;
|
||||||
use Joomla\CMS\Component\ComponentHelper;
|
use Joomla\CMS\Component\Router\RouterView;
|
||||||
|
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||||
|
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||||
|
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class CircolariRouter
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Router extends RouterView
|
class Router extends RouterView
|
||||||
{
|
{
|
||||||
private $noIDs;
|
public function __construct(SiteApplication $app, AbstractMenu $menu)
|
||||||
/**
|
{
|
||||||
* The category factory
|
$circolare = new RouterViewConfiguration('circolare');
|
||||||
*
|
$circolare->setKey('id');
|
||||||
* @var CategoryFactoryInterface
|
$this->registerView($circolare);
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $categoryFactory;
|
|
||||||
|
|
||||||
/**
|
parent::__construct($app, $menu);
|
||||||
* The category cache
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $categoryCache = [];
|
|
||||||
|
|
||||||
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
|
$this->attachRule(new MenuRules($this));
|
||||||
{
|
$this->attachRule(new StandardRules($this));
|
||||||
$params = ComponentHelper::getParams('com_circolari');
|
}
|
||||||
$this->noIDs = (bool) $params->get('sef_ids');
|
|
||||||
$this->categoryFactory = $categoryFactory;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parent::__construct($app, $menu);
|
|
||||||
|
|
||||||
$this->attachRule(new MenuRules($this));
|
|
||||||
$this->attachRule(new StandardRules($this));
|
|
||||||
$this->attachRule(new NomenuRules($this));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to get categories from cache
|
|
||||||
*
|
|
||||||
* @param array $options The options for retrieving categories
|
|
||||||
*
|
|
||||||
* @return CategoryInterface The object containing categories
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function getCategories(array $options = []): CategoryInterface
|
|
||||||
{
|
|
||||||
$key = serialize($options);
|
|
||||||
|
|
||||||
if (!isset($this->categoryCache[$key]))
|
|
||||||
{
|
|
||||||
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->categoryCache[$key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
37
site/src/View/Circolare/HtmlView.php
Normal file
37
site/src/View/Circolare/HtmlView.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace Pcrt\Component\Circolari\Site\View\Circolare;
|
||||||
|
|
||||||
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
use Joomla\CMS\Language\Text;
|
||||||
|
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||||
|
|
||||||
|
class HtmlView extends BaseHtmlView
|
||||||
|
{
|
||||||
|
protected $item;
|
||||||
|
|
||||||
|
public function display($tpl = null)
|
||||||
|
{
|
||||||
|
$this->item = $this->get('Item');
|
||||||
|
|
||||||
|
if (!$this->item) {
|
||||||
|
throw new \Exception(Text::_('COM_CIRCOLARI_ITEM_NOT_FOUND'), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 = '<article class="com-content-article item-page">'
|
||||||
|
. '<header class="page-header"><h1 class="page-title">'.$title.'</h1></header>'
|
||||||
|
. '<div class="article-body">'.$body.'</div>'
|
||||||
|
. '</article>';
|
||||||
|
|
||||||
|
$this->document->setBuffer($html, 'component');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::display($tpl);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
site/tmpl/circolare/default.php
Normal file
26
site/tmpl/circolare/default.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
use Joomla\CMS\HTML\HTMLHelper;
|
||||||
|
use Joomla\CMS\Language\Text;
|
||||||
|
|
||||||
|
/** @var \Pcrt\Component\Circolari\Site\View\Circolare\HtmlView $this */
|
||||||
|
$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">
|
||||||
|
<?php echo $item->description ?: $item->testo ?: $item->descrizione ?: '<em>(Nessun testo)</em>'; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (!empty($item->attachment)) : ?>
|
||||||
|
<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>
|
||||||
29
site/tmpl/circolare/default.xml
Normal file
29
site/tmpl/circolare/default.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<metadata>
|
||||||
|
<layout title="COM_CIRCOLARI_MENU_CIRCOLARE" option="com_circolari">
|
||||||
|
<help key="JHELP_MENUS_MENU_ITEM_GENERIC" />
|
||||||
|
</layout>
|
||||||
|
|
||||||
|
<!-- Parametri passati nella query -->
|
||||||
|
<fields name="request">
|
||||||
|
<fieldset name="request">
|
||||||
|
<!-- opzionale: se lo lasci vuoto userai la voce solo come “contenitore” per l’Itemid -->
|
||||||
|
<field name="id" type="number"
|
||||||
|
label="COM_CIRCOLARI_FIELD_ID_LABEL"
|
||||||
|
description="COM_CIRCOLARI_FIELD_ID_DESC"
|
||||||
|
required="false" />
|
||||||
|
<field name="view" type="hidden" default="circolare" />
|
||||||
|
</fieldset>
|
||||||
|
</fields>
|
||||||
|
|
||||||
|
<!-- Parametri pagina (avanzate) -->
|
||||||
|
<fields name="params">
|
||||||
|
<fieldset name="advanced" label="JGLOBAL_FIELDSET_ADVANCED">
|
||||||
|
<field name="page_title" type="text" label="JGLOBAL_TITLE" />
|
||||||
|
<field name="show_page_heading" type="radio" default="1" label="JGLOBAL_SHOW_PAGE_HEADING">
|
||||||
|
<option value="1">JYES</option>
|
||||||
|
<option value="0">JNO</option>
|
||||||
|
</field>
|
||||||
|
</fieldset>
|
||||||
|
</fields>
|
||||||
|
</metadata>
|
||||||
Reference in New Issue
Block a user