Stabilization

This commit is contained in:
2025-09-01 17:43:30 +02:00
parent c929d7d01d
commit c206ce7e4b
11 changed files with 237 additions and 117 deletions

View File

@ -8,20 +8,41 @@
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>
<field name="ordering" type="number" default="0"/>
<field name="checked_out" type="hidden" filter="unset"/>
<field name="checked_out_time" type="hidden" filter="unset"/>
<field name="created_by" type="createdby" hidden="true"/>
<field name="modified_by" type="modifiedby" hidden="true"/>
<field name="title" type="text" label="JGLOBAL_TITLE" required="true" filter="safehtml"/>
<field name="alias" type="text" label="JFIELD_ALIAS_LABEL" description="JFIELD_ALIAS_DESC"/>
<field name="categoria_id" type="Categoria" label="Categoria" required="true"/>
<field name="usergroup_id" type="usergrouplist" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_USERGROUP" description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_USERGROUP" />
<field name="description" type="editor" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION" filter="safehtml" buttons="true"/>
<field name="attachment" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_ATTACHMENT" directory="documents/circolari" preview="false" upload="true"/>
<field name="image" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_IMAGE" directory="images" preview="true" upload="true"/>
<field name="tipologia_firma_id" type="Tipologiafirma" label="Tipologia firma" />
<field name="scadenza" type="CalSafe" label="Data Scadenza Firma" />
<field name="hits" type="number" readonly="true" label="JGLOBAL_HITS" default="0"/>
<field name="ordering" type="number" default="0" />
<field name="checked_out" type="hidden" filter="unset" />
<field name="checked_out_time" type="hidden" filter="unset" />
<field name="created_by" type="createdby" hidden="true" />
<field name="modified_by" type="modifiedby" hidden="true" />
<field name="title" type="text" label="JGLOBAL_TITLE" required="true" filter="safehtml" />
<field name="alias" type="text" label="JFIELD_ALIAS_LABEL" description="JFIELD_ALIAS_DESC" />
<field name="categoria_id" type="Categoria" label="Categoria" required="true" />
<field name="usergroup_id" type="usergrouplist"
label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_USERGROUP"
description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_USERGROUP" />
<field name="description" type="editor" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION"
filter="safehtml" buttons="true" />
<field name="attachment" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_ATTACHMENT"
directory="documents/circolari" preview="false" upload="true" />
<field name="image" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_IMAGE"
directory="images" preview="true" upload="true" />
<field name="firma_obbligatoria" type="radio"
label="Firma Obbligatoria"
default="0"
layout="joomla.form.field.radio.switcher">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="tipologia_firma_id" type="Tipologiafirma" label="Tipologia firma"
showon="firma_obbligatoria:1" />
<field name="scadenza" type="CalSafe" label="Data Scadenza Firma"
showon="firma_obbligatoria:1" />
<field name="hits" type="number" readonly="true" label="JGLOBAL_HITS" default="0" />
</fieldset>
</form>

View File

@ -15,11 +15,14 @@
<field name="modified_by" type="modifiedby" default="0" label="JGLOBAL_FIELD_MODIFIED_BY_LABEL" description="JGLOBAL_FIELD_MODIFIED_BY_DESC" hidden="true" hint="COM_HIGHLIGHTS_FORM_LBL_ETICHETTA_MODIFIED_BY"/>
<field name="nome" filter="safehtml" type="text" label="COM_HIGHLIGHTS_FORM_LBL_ETICHETTA_NOME" description="COM_HIGHLIGHTS_FORM_DESC_ETICHETTA_NOME" hint="COM_HIGHLIGHTS_FORM_LBL_ETICHETTA_NOME"/>
<field name="descrizione" filter="safehtml" type="textarea" label="Descrizione" hint="Descrizione"/>
<field name="bottoni_firma" type="subform"
<field
name="bottoni_firma"
type="subform"
formsource="administrator/components/com_circolari/forms/fields/bottoni_firma.xml"
multiple="true"
label="Bottoni della Firma"
description="Aggiungi uno o più bottoni personalizzati per questa firma." />
description="Aggiungi i bottoni associati a questo tipo di firma." />
<field name="lingua" type="contentlanguage" label="COM_HIGHLIGHTS_FORM_LBL_ETICHETTA_LINGUA" description="COM_HIGHLIGHTS_FORM_DESC_ETICHETTA_LINGUA" hint="COM_HIGHLIGHTS_FORM_LBL_ETICHETTA_LINGUA">
<option value="*">JALL</option>

View File

@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS `#__circolari` (`id` INT(11) UNSIGNED NOT NULL AUTO_I
`usergroup_id` INT(11) UNSIGNED NOT NULL DEFAULT 0,
`hits` INT(11) UNSIGNED NOT NULL DEFAULT 0,
`title` VARCHAR(255) DEFAULT "",
`alias` VARCHAR(255) NOT NULL DEFAULT '',
`description` TEXT,
`attachment` VARCHAR(255) DEFAULT "",
`image` VARCHAR(255) DEFAULT "",
@ -70,3 +71,17 @@ CREATE TABLE IF NOT EXISTS `#__circolari_categorie` (
UNIQUE KEY `idx_alias` (`alias`)
) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_unicode_ci;
-- Bottoni associati al tipo di firma
CREATE TABLE IF NOT EXISTS `#__circolari_firmetipi_bottoni` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`firmatipo_id` INT(11) UNSIGNED NOT NULL,
`label` VARCHAR(190) NOT NULL,
`ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `idx_firmatipo_id` (`firmatipo_id`),
CONSTRAINT `fk_firmetipi_bottoni_firmatipo`
FOREIGN KEY (`firmatipo_id`) REFERENCES `#__circolari_firmetipi` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_unicode_ci;

View File

@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
class CategoriaController extends FormController
{
protected $view_list = 'categorie';
protected $view_item = 'categoria';
}

View File

@ -73,7 +73,7 @@ class CategorieController extends AdminController
*
* @since 1.0.0
*/
public function getModel($name = 'FirmaTipo', $prefix = 'Administrator', $config = array())
public function getModel($name = 'categoria', $prefix = 'Administrator', $config = array())
{
return parent::getModel($name, $prefix, array('ignore_request' => true));
}

View File

@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
class FirmatipoController extends FormController
{
protected $view_list = 'firmetipi';
protected $view_item = 'firmatipo';
}

View File

@ -73,7 +73,7 @@ class FirmetipiController extends AdminController
*
* @since 1.0.0
*/
public function getModel($name = 'FirmaTipo', $prefix = 'Administrator', $config = array())
public function getModel($name = 'Firmatipo', $prefix = 'Administrator', $config = array())
{
return parent::getModel($name, $prefix, array('ignore_request' => true));
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @version CVS: 1.0.0
* @package Com_Circolari
@ -96,8 +97,7 @@ class FirmatipoModel extends AdminModel
if (empty($form))
{
if (empty($form)) {
return false;
}
@ -118,15 +118,12 @@ class FirmatipoModel extends AdminModel
// Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_circolari.edit.firmatipo.data', array());
if (empty($data))
{
if ($this->item === null)
{
if (empty($data)) {
if ($this->item === null) {
$this->item = $this->getItem();
}
$data = $this->item;
}
return $data;
@ -144,18 +141,108 @@ class FirmatipoModel extends AdminModel
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
if (isset($item->params))
{
if ($item = parent::getItem($pk)) {
if (isset($item->params)) {
$item->params = json_encode($item->params);
}
if ($item && (int) $item->id) {
$db = Factory::getDbo();
$q = $db->getQuery(true)
->select($db->quoteName(['label', 'ordering']))
->from($db->quoteName('#__circolari_firmetipi_bottoni'))
->where($db->quoteName('firmatipo_id') . ' = ' . (int) $item->id)
->order($db->escape('ordering ASC, id ASC'));
$db->setQuery($q);
$rows = (array) $db->loadObjectList();
// Adatta ai nomi del subform (etichetta/ordering)
$item->bottoni_firma = array_map(static function ($r) {
return [
'etichetta' => (string) ($r->label ?? ''),
'ordering' => (int) ($r->ordering ?? 0),
];
}, $rows);
} else {
// default per form nuovo
if (is_object($item)) {
$item->bottoni_firma = [];
}
}
// Do any procesing on fields here if needed
}
return $item;
}
public function save($data)
{
// Stacco il subform per non confondere la tabella principale
$bottoni = $data['bottoni_firma'] ?? null;
unset($data['bottoni_firma']);
// Salvo il firmatipo
$result = parent::save($data);
if (!$result) {
return false;
}
// Recupero l'ID del firmatipo appena salvato
$id = (int) ($data['id'] ?? 0);
if ($id <= 0) {
$id = (int) $this->getState($this->getName() . '.id');
}
if ($id <= 0) {
// Estremo: ricarico l'item corrente
$item = parent::getItem();
$id = (int) ($item->id ?? 0);
}
if ($id <= 0) {
$this->setError('Impossibile determinare lID del firmatipo dopo il salvataggio.');
return false;
}
// Se il campo non è presente nel POST (permessi/layout), non tocco i bottoni
if ($bottoni === null) {
return true;
}
$db = Factory::getDbo();
$db->transactionStart();
try {
// Pulisce i bottoni esistenti del firmatipo
$delete = $db->getQuery(true)
->delete($db->quoteName('#__circolari_firmetipi_bottoni'))
->where($db->quoteName('firmatipo_id') . ' = ' . $id);
$db->setQuery($delete)->execute();
// Re-inserisce dai dati del subform
foreach ((array) $bottoni as $row) {
$label = trim((string) ($row['etichetta'] ?? ''));
if ($label === '') {
continue; // salta righe vuote
}
$ordering = (int) ($row['ordering'] ?? 0);
$insert = $db->getQuery(true)
->insert($db->quoteName('#__circolari_firmetipi_bottoni'))
->columns($db->quoteName(['firmatipo_id','label','ordering']))
->values((int) $id . ', ' . $db->quote($label) . ', ' . (int) $ordering);
$db->setQuery($insert)->execute();
}
$db->transactionCommit();
} catch (\Throwable $e) {
$db->transactionRollback();
$this->setError($e->getMessage());
return false;
}
return true;
}
/**
@ -174,8 +261,7 @@ class FirmatipoModel extends AdminModel
$dispatcher = $this->getDispatcher();
// Access checks.
if (!$user->authorise('core.create', 'com_circolari'))
{
if (!$user->authorise('core.create', 'com_circolari')) {
throw new \Exception(Text::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
}
@ -186,16 +272,13 @@ class FirmatipoModel extends AdminModel
$table = $this->getTable();
foreach ($pks as $pk)
{
foreach ($pks as $pk) {
if ($table->load($pk, true))
{
if ($table->load($pk, true)) {
// Reset the id to create a new record.
$table->id = 0;
if (!$table->check())
{
if (!$table->check()) {
throw new \Exception($table->getError());
}
@ -235,12 +318,9 @@ class FirmatipoModel extends AdminModel
]
)
);
}
else
{
} else {
throw new \Exception($table->getError());
}
}
// Clean cache
@ -262,11 +342,9 @@ class FirmatipoModel extends AdminModel
{
jimport('joomla.filter.output');
if (empty($table->id))
{
if (empty($table->id)) {
// Set ordering to the last item if not set
if (@$table->ordering === '')
{
if (@$table->ordering === '') {
$db = $this->getDbo();
$db->setQuery('SELECT MAX(ordering) FROM #__circolari_firmetipi');
$max = $db->loadResult();

View File

@ -42,8 +42,8 @@ HTMLHelper::_('bootstrap.tooltip');
<?php echo $this->form->renderField('description'); ?>
<?php echo $this->form->renderField('attachment'); ?>
<?php echo $this->form->renderField('image'); ?>
<?php echo $this->form->renderField('tipologia_firma_id'); ?>
<?php echo $this->form->renderField('firma_obbligatoria'); ?>
<?php echo $this->form->renderField('tipologia_firma_id'); ?>
<?php echo $this->form->renderField('scadenza'); ?>
</fieldset>
</div>

View File

@ -107,7 +107,7 @@ if (!empty($saveOrder)) {
<?php echo htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8'); ?>
</a>
</td>
<td><?php echo $item->tipologia_nome; ?></td>
<td><?php echo $item->tipologia_firma_id; ?></td>
<td><?php echo $item->firma_obbligatoria ? 'Sì' : 'No'; ?></td>
<td><?php echo $item->scadenza; ?></td>
<?php if (isset($this->items[0]->ordering)) : ?>

View File

@ -1,4 +1,5 @@
<?php
/**
* @version CVS: 1.0.0
* @package Com_Highlights
@ -51,7 +52,7 @@ HTMLHelper::_('bootstrap.tooltip');
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>