Assegnazione url corretto alla singola circolare
This commit is contained in:
@ -18,6 +18,14 @@
|
|||||||
type="text"
|
type="text"
|
||||||
label="JFIELD_ALIAS_LABEL"
|
label="JFIELD_ALIAS_LABEL"
|
||||||
description="JFIELD_ALIAS_DESC" />
|
description="JFIELD_ALIAS_DESC" />
|
||||||
|
<field
|
||||||
|
name="catid"
|
||||||
|
type="category"
|
||||||
|
extension="com_content"
|
||||||
|
label="JCATEGORY"
|
||||||
|
required="true"
|
||||||
|
default="11"
|
||||||
|
/>
|
||||||
<field name="description" filter="safehtml" type="textarea" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION" description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_DESCRIPTION" hint="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION"/>
|
<field name="description" filter="safehtml" type="textarea" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION" description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_DESCRIPTION" hint="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION"/>
|
||||||
<field name="attachment" type="media"
|
<field name="attachment" type="media"
|
||||||
label="COM_CIRCOLARI_FIELD_ATTACHMENT_LABEL"
|
label="COM_CIRCOLARI_FIELD_ATTACHMENT_LABEL"
|
||||||
|
|||||||
9
administrator/sql/updates/1.1.3.sql
Normal file
9
administrator/sql/updates/1.1.3.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
ALTER TABLE `#__circolari`
|
||||||
|
ADD COLUMN `catid` INT(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `modified_by`,
|
||||||
|
ADD INDEX `idx_catid` (`catid`);
|
||||||
|
|
||||||
|
ALTER TABLE `#__circolari`
|
||||||
|
ALTER `catid` SET DEFAULT 11;
|
||||||
|
|
||||||
|
-- opzionale, porta a 11 i record con catid 0/null
|
||||||
|
UPDATE `#__circolari` SET `catid` = 11 WHERE `catid` IS NULL OR `catid` = 0;
|
||||||
@ -127,6 +127,14 @@ class CircolareModel extends AdminModel
|
|||||||
$data = $this->item;
|
$data = $this->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((is_array($data) && empty($data['id'])) || (is_object($data) && empty($data->id))) {
|
||||||
|
if (is_array($data)) {
|
||||||
|
$data['catid'] = (int)($data['catid'] ?? 0) ?: 11;
|
||||||
|
} else {
|
||||||
|
$data->catid = (int)($data->catid ?? 0) ?: 11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -198,7 +198,7 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
|||||||
$this->ordering = self::getNextOrder();
|
$this->ordering = self::getNextOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ordering per nuovi record
|
// Ordering per nuovi record
|
||||||
if (property_exists($this, 'ordering') && (int) $this->id === 0) {
|
if (property_exists($this, 'ordering') && (int) $this->id === 0) {
|
||||||
$this->ordering = self::getNextOrder();
|
$this->ordering = self::getNextOrder();
|
||||||
}
|
}
|
||||||
@ -235,6 +235,11 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Default categoria (nuovi record o catid non impostato)
|
||||||
|
$this->catid = (int)($this->catid ?? 0) ?: 11;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return parent::check();
|
return parent::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,5 +318,4 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
|||||||
$this->_db->setQuery($q);
|
$this->_db->setQuery($q);
|
||||||
return ((int) $this->_db->loadResult()) > 0;
|
return ((int) $this->_db->loadResult()) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ HTMLHelper::_('bootstrap.tooltip');
|
|||||||
<legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_CIRCOLARI'); ?></legend>
|
<legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_CIRCOLARI'); ?></legend>
|
||||||
<?php echo $this->form->renderField('title'); ?>
|
<?php echo $this->form->renderField('title'); ?>
|
||||||
<?php echo $this->form->renderField('alias'); ?>
|
<?php echo $this->form->renderField('alias'); ?>
|
||||||
|
<?php echo $this->form->renderField('catid'); ?>
|
||||||
<?php echo $this->form->renderField('description'); ?>
|
<?php echo $this->form->renderField('description'); ?>
|
||||||
<?php echo $this->form->renderField('attachment'); ?>
|
<?php echo $this->form->renderField('attachment'); ?>
|
||||||
<?php echo $this->form->renderField('image'); ?>
|
<?php echo $this->form->renderField('image'); ?>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<author>Tommaso Cippitelli</author>
|
<author>Tommaso Cippitelli</author>
|
||||||
<authorEmail>tommaso.cippitelli@protocollicreativi.it</authorEmail>
|
<authorEmail>tommaso.cippitelli@protocollicreativi.it</authorEmail>
|
||||||
<authorUrl>http://</authorUrl>
|
<authorUrl>http://</authorUrl>
|
||||||
<version>CVS: 1.1.0</version>
|
<version>CVS: 1.1.3</version>
|
||||||
<description></description>
|
<description></description>
|
||||||
<namespace path="src">Pcrt\Component\Circolari</namespace>
|
<namespace path="src">Pcrt\Component\Circolari</namespace>
|
||||||
|
|
||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
<files folder="site">
|
<files folder="site">
|
||||||
<folder>src</folder>
|
<folder>src</folder>
|
||||||
|
<folder>services</folder>
|
||||||
<folder>tmpl</folder>
|
<folder>tmpl</folder>
|
||||||
</files>
|
</files>
|
||||||
<media destination="com_circolari" folder="media">
|
<media destination="com_circolari" folder="media">
|
||||||
|
|||||||
25
site/services/provider.php
Normal file
25
site/services/provider.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
use Joomla\DI\Container;
|
||||||
|
use Joomla\DI\ServiceProviderInterface;
|
||||||
|
|
||||||
|
return new class implements ServiceProviderInterface {
|
||||||
|
public function register(Container $c)
|
||||||
|
{
|
||||||
|
// Joomla 4/5
|
||||||
|
if (class_exists('Joomla\\CMS\\Extension\\Service\\Provider\\MVCComponent')) {
|
||||||
|
$cls = 'Joomla\\CMS\\Extension\\Service\\Provider\\MVCComponent';
|
||||||
|
$c->registerServiceProvider(new $cls('Pcrt\\Component\\Circolari'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback per ambienti older: comunque registra il namespace PSR-4
|
||||||
|
if (class_exists('JLoader') && \defined('JPATH_SITE')) {
|
||||||
|
\JLoader::registerNamespace(
|
||||||
|
'Pcrt\\Component\\Circolari\\Site',
|
||||||
|
JPATH_SITE . '/components/com_circolari/src',
|
||||||
|
false, false, 'psr4'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -5,22 +5,126 @@ namespace Pcrt\Component\Circolari\Site\Service;
|
|||||||
|
|
||||||
use Joomla\CMS\Application\SiteApplication;
|
use Joomla\CMS\Application\SiteApplication;
|
||||||
use Joomla\CMS\Menu\AbstractMenu;
|
use Joomla\CMS\Menu\AbstractMenu;
|
||||||
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Component\Router\RouterView;
|
use Joomla\CMS\Component\Router\RouterView;
|
||||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
|
||||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||||
|
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||||
|
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
||||||
|
|
||||||
class Router extends RouterView
|
class Router extends RouterView
|
||||||
{
|
{
|
||||||
public function __construct(SiteApplication $app, AbstractMenu $menu)
|
public function __construct(SiteApplication $app, AbstractMenu $menu)
|
||||||
{
|
{
|
||||||
|
// Parent: category (annidata → più segmenti)
|
||||||
|
$category = new RouterViewConfiguration('category');
|
||||||
|
$category->setKey('id')->setNestable();
|
||||||
|
$this->registerView($category);
|
||||||
|
|
||||||
|
// Child: circolare (lega la category tramite catid)
|
||||||
$circolare = new RouterViewConfiguration('circolare');
|
$circolare = new RouterViewConfiguration('circolare');
|
||||||
$circolare->setKey('id');
|
$circolare->setKey('id')->setParent($category, 'catid', 'id');
|
||||||
$this->registerView($circolare);
|
$this->registerView($circolare);
|
||||||
|
|
||||||
parent::__construct($app, $menu);
|
parent::__construct($app, $menu);
|
||||||
|
|
||||||
$this->attachRule(new MenuRules($this));
|
// Regole standard di routing
|
||||||
$this->attachRule(new StandardRules($this));
|
$this->attachRule(new StandardRules($this));
|
||||||
|
$this->attachRule(new MenuRules($this));
|
||||||
|
$this->attachRule(new NomenuRules($this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- BUILD ---------------- */
|
||||||
|
|
||||||
|
// Segmenti categoria = path completo (parent1/parent2/figlia)
|
||||||
|
public function getCategorySegment($id, $query)
|
||||||
|
{
|
||||||
|
$id = (int) ($id ?: 0);
|
||||||
|
if ($id <= 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
$path = (string) $db->setQuery(
|
||||||
|
$db->getQuery(true)
|
||||||
|
->select('path')
|
||||||
|
->from('#__categories')
|
||||||
|
->where('id = ' . $id)
|
||||||
|
->where("extension = 'com_content'")
|
||||||
|
)->loadResult();
|
||||||
|
|
||||||
|
return $path !== '' ? array_filter(explode('/', $path)) : [(string) $id];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ultimo segmento = SOLO alias della circolare
|
||||||
|
public function getCircolareSegment($id, $query)
|
||||||
|
{
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
$alias = (string) $db->setQuery(
|
||||||
|
$db->getQuery(true)
|
||||||
|
->select('alias')
|
||||||
|
->from('#__circolari')
|
||||||
|
->where('id = ' . (int) $id)
|
||||||
|
)->loadResult();
|
||||||
|
|
||||||
|
// Nessun fallback numerico: imponiamo l'alias
|
||||||
|
return [$alias];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- PARSE ---------------- */
|
||||||
|
|
||||||
|
// Ricava catid accumulando i segmenti e risolvendo per PATH completo
|
||||||
|
public function getCategoryId($segment, $query)
|
||||||
|
{
|
||||||
|
static $segments = [];
|
||||||
|
$segments[] = $segment;
|
||||||
|
$path = implode('/', $segments);
|
||||||
|
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
|
||||||
|
// match per path (univoco in com_content)
|
||||||
|
$id = (int) $db->setQuery(
|
||||||
|
$db->getQuery(true)
|
||||||
|
->select('id')
|
||||||
|
->from('#__categories')
|
||||||
|
->where('path = ' . $db->quote($path))
|
||||||
|
->where("extension = 'com_content'")
|
||||||
|
)->loadResult();
|
||||||
|
|
||||||
|
if ($id > 0) {
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback (singolo alias) se si visita direttamente un livello intermedio
|
||||||
|
$id = (int) $db->setQuery(
|
||||||
|
$db->getQuery(true)
|
||||||
|
->select('id')
|
||||||
|
->from('#__categories')
|
||||||
|
->where('alias = ' . $db->quote($segment))
|
||||||
|
->where("extension = 'com_content'")
|
||||||
|
->order('level DESC')
|
||||||
|
)->loadResult();
|
||||||
|
|
||||||
|
return $id ?: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alias circolare (+ catid già risolto) → id
|
||||||
|
public function getCircolareId($segment, $query)
|
||||||
|
{
|
||||||
|
$catid = (int) ($query['catid'] ?? 0);
|
||||||
|
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
$q = $db->getQuery(true)
|
||||||
|
->select('id')
|
||||||
|
->from('#__circolari')
|
||||||
|
->where('alias = ' . $db->quote($segment));
|
||||||
|
|
||||||
|
if ($catid > 0) {
|
||||||
|
$q->where('catid = ' . $catid);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->setQuery($q);
|
||||||
|
|
||||||
|
return (int) $db->loadResult() ?: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
site/tmpl/category/default.xml
Normal file
33
site/tmpl/category/default.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<metadata>
|
||||||
|
<!-- titolo del tipo voce di menu, visibile nel backend -->
|
||||||
|
<layout title="COM_CIRCOLARI_MENU_CATEGORY" option="com_circolari" />
|
||||||
|
|
||||||
|
<!-- campi che finiscono nella query dell'URL -->
|
||||||
|
<fields name="request">
|
||||||
|
<fieldset name="request">
|
||||||
|
<!-- forza la view "category" -->
|
||||||
|
<field name="view" type="hidden" default="category" />
|
||||||
|
<!-- scegli la categoria di Joomla (com_content) che fa da base del percorso -->
|
||||||
|
<field
|
||||||
|
name="id"
|
||||||
|
type="category"
|
||||||
|
extension="com_content"
|
||||||
|
label="JCATEGORY"
|
||||||
|
description="Seleziona la categoria di com_content da usare come base del percorso URL."
|
||||||
|
required="true"
|
||||||
|
default="11"
|
||||||
|
/>
|
||||||
|
</fieldset>
|
||||||
|
</fields>
|
||||||
|
|
||||||
|
<!-- parametri opzionali della voce (non obbligatori) -->
|
||||||
|
<fields name="params">
|
||||||
|
<fieldset name="basic" label="JOPTIONS">
|
||||||
|
<field name="show_category_title" type="radio" label="COM_CIRCOLARI_SHOW_CATEGORY_TITLE" default="0">
|
||||||
|
<option value="0">JHIDE</option>
|
||||||
|
<option value="1">JSHOW</option>
|
||||||
|
</field>
|
||||||
|
</fieldset>
|
||||||
|
</fields>
|
||||||
|
</metadata>
|
||||||
Reference in New Issue
Block a user