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">JARCHIVED</option>
<option value="-2">JTRASHED</option> <option value="-2">JTRASHED</option>
</field> </field>
<field name="ordering" type="number" default="0"/> <field name="ordering" type="number" default="0" />
<field name="checked_out" type="hidden" filter="unset"/> <field name="checked_out" type="hidden" filter="unset" />
<field name="checked_out_time" type="hidden" filter="unset"/> <field name="checked_out_time" type="hidden" filter="unset" />
<field name="created_by" type="createdby" hidden="true"/> <field name="created_by" type="createdby" hidden="true" />
<field name="modified_by" type="modifiedby" 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="title" type="text" label="JGLOBAL_TITLE" required="true" filter="safehtml" />
<field name="categoria_id" type="Categoria" label="Categoria" required="true"/> <field name="alias" type="text" label="JFIELD_ALIAS_LABEL" description="JFIELD_ALIAS_DESC" />
<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="categoria_id" type="Categoria" label="Categoria" required="true" />
<field name="attachment" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_ATTACHMENT" directory="documents/circolari" preview="false" upload="true"/> <field name="usergroup_id" type="usergrouplist"
<field name="image" type="media" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_IMAGE" directory="images" preview="true" upload="true"/> label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_USERGROUP"
<field name="tipologia_firma_id" type="Tipologiafirma" label="Tipologia firma" /> description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_USERGROUP" />
<field name="scadenza" type="CalSafe" label="Data Scadenza Firma" /> <field name="description" type="editor" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION"
<field name="hits" type="number" readonly="true" label="JGLOBAL_HITS" default="0"/> 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> </fieldset>
</form> </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="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="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="descrizione" filter="safehtml" type="textarea" label="Descrizione" hint="Descrizione"/>
<field name="bottoni_firma" type="subform" <field
formsource="administrator/components/com_circolari/forms/fields/bottoni_firma.xml" name="bottoni_firma"
multiple="true" type="subform"
label="Bottoni della Firma" formsource="administrator/components/com_circolari/forms/fields/bottoni_firma.xml"
description="Aggiungi uno o più bottoni personalizzati per questa firma." /> multiple="true"
label="Bottoni della 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"> <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> <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, `usergroup_id` INT(11) UNSIGNED NOT NULL DEFAULT 0,
`hits` INT(11) UNSIGNED NOT NULL DEFAULT 0, `hits` INT(11) UNSIGNED NOT NULL DEFAULT 0,
`title` VARCHAR(255) DEFAULT "", `title` VARCHAR(255) DEFAULT "",
`alias` VARCHAR(255) NOT NULL DEFAULT '',
`description` TEXT, `description` TEXT,
`attachment` VARCHAR(255) DEFAULT "", `attachment` VARCHAR(255) DEFAULT "",
`image` VARCHAR(255) DEFAULT "", `image` VARCHAR(255) DEFAULT "",
@ -70,3 +71,17 @@ CREATE TABLE IF NOT EXISTS `#__circolari_categorie` (
UNIQUE KEY `idx_alias` (`alias`) UNIQUE KEY `idx_alias` (`alias`)
) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_unicode_ci; ) 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 class CategoriaController extends FormController
{ {
protected $view_list = 'categorie'; protected $view_list = 'categorie';
protected $view_item = 'categoria';
} }

View File

@ -73,7 +73,7 @@ class CategorieController extends AdminController
* *
* @since 1.0.0 * @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)); 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 class FirmatipoController extends FormController
{ {
protected $view_list = 'firmetipi'; protected $view_list = 'firmetipi';
protected $view_item = 'firmatipo';
} }

View File

@ -73,7 +73,7 @@ class FirmetipiController extends AdminController
* *
* @since 1.0.0 * @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)); return parent::getModel($name, $prefix, array('ignore_request' => true));
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @version CVS: 1.0.0 * @version CVS: 1.0.0
* @package Com_Circolari * @package Com_Circolari
@ -50,8 +51,8 @@ class FirmatipoModel extends AdminModel
*/ */
protected $item = null; protected $item = null;
/** /**
* Returns a reference to the a Table object, always creating it. * Returns a reference to the a Table object, always creating it.
@ -86,25 +87,24 @@ class FirmatipoModel extends AdminModel
// Get the form. // Get the form.
$form = $this->loadForm( $form = $this->loadForm(
'com_circolari.firmaTipo', 'com_circolari.firmaTipo',
'firmaTipo', 'firmaTipo',
array( array(
'control' => 'jform', 'control' => 'jform',
'load_data' => $loadData 'load_data' => $loadData
) )
); );
if (empty($form))
{ if (empty($form)) {
return false; return false;
} }
return $form; return $form;
} }
/** /**
* Method to get the data that should be injected in the form. * Method to get the data that should be injected in the form.
@ -118,15 +118,12 @@ class FirmatipoModel extends AdminModel
// Check the session for previously entered form data. // Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_circolari.edit.firmatipo.data', array()); $data = Factory::getApplication()->getUserState('com_circolari.edit.firmatipo.data', array());
if (empty($data)) if (empty($data)) {
{ if ($this->item === null) {
if ($this->item === null)
{
$this->item = $this->getItem(); $this->item = $this->getItem();
} }
$data = $this->item; $data = $this->item;
} }
return $data; return $data;
@ -143,21 +140,111 @@ class FirmatipoModel extends AdminModel
*/ */
public function getItem($pk = null) public function getItem($pk = null)
{ {
if ($item = parent::getItem($pk)) if ($item = parent::getItem($pk)) {
{ if (isset($item->params)) {
if (isset($item->params)) $item->params = json_encode($item->params);
{
$item->params = json_encode($item->params);
}
// Do any procesing on fields here if needed
} }
return $item; 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;
}
/** /**
* Method to duplicate an Etichetta * Method to duplicate an Etichetta
* *
@ -171,11 +258,10 @@ class FirmatipoModel extends AdminModel
{ {
$app = Factory::getApplication(); $app = Factory::getApplication();
$user = $app->getIdentity(); $user = $app->getIdentity();
$dispatcher = $this->getDispatcher(); $dispatcher = $this->getDispatcher();
// Access checks. // 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')); throw new \Exception(Text::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
} }
@ -186,61 +272,55 @@ class FirmatipoModel extends AdminModel
$table = $this->getTable(); $table = $this->getTable();
foreach ($pks as $pk) foreach ($pks as $pk) {
{
if ($table->load($pk, true))
{
// Reset the id to create a new record.
$table->id = 0;
if (!$table->check()) if ($table->load($pk, true)) {
{ // Reset the id to create a new record.
throw new \Exception($table->getError()); $table->id = 0;
}
// Create the before save event. if (!$table->check()) {
$beforeSaveEvent = AbstractEvent::create(
$this->event_before_save,
[
'context' => $context,
'subject' => $table,
'isNew' => true,
'data' => $table,
]
);
// Trigger the before save event.
$dispatchResult = Factory::getApplication()->getDispatcher()->dispatch($this->event_before_save, $beforeSaveEvent);
// Check if dispatch result is an array and handle accordingly
$result = isset($dispatchResult['result']) ? $dispatchResult['result'] : [];
// Proceed with your logic
if (in_array(false, $result, true) || !$table->store()) {
throw new \Exception($table->getError());
}
// Trigger the after save event.
Factory::getApplication()->getDispatcher()->dispatch(
$this->event_after_save,
AbstractEvent::create(
$this->event_after_save,
[
'context' => $context,
'subject' => $table,
'isNew' => true,
'data' => $table,
]
)
);
}
else
{
throw new \Exception($table->getError()); throw new \Exception($table->getError());
} }
// Create the before save event.
$beforeSaveEvent = AbstractEvent::create(
$this->event_before_save,
[
'context' => $context,
'subject' => $table,
'isNew' => true,
'data' => $table,
]
);
// Trigger the before save event.
$dispatchResult = Factory::getApplication()->getDispatcher()->dispatch($this->event_before_save, $beforeSaveEvent);
// Check if dispatch result is an array and handle accordingly
$result = isset($dispatchResult['result']) ? $dispatchResult['result'] : [];
// Proceed with your logic
if (in_array(false, $result, true) || !$table->store()) {
throw new \Exception($table->getError());
}
// Trigger the after save event.
Factory::getApplication()->getDispatcher()->dispatch(
$this->event_after_save,
AbstractEvent::create(
$this->event_after_save,
[
'context' => $context,
'subject' => $table,
'isNew' => true,
'data' => $table,
]
)
);
} else {
throw new \Exception($table->getError());
}
} }
// Clean cache // Clean cache
@ -262,11 +342,9 @@ class FirmatipoModel extends AdminModel
{ {
jimport('joomla.filter.output'); jimport('joomla.filter.output');
if (empty($table->id)) if (empty($table->id)) {
{
// Set ordering to the last item if not set // Set ordering to the last item if not set
if (@$table->ordering === '') if (@$table->ordering === '') {
{
$db = $this->getDbo(); $db = $this->getDbo();
$db->setQuery('SELECT MAX(ordering) FROM #__circolari_firmetipi'); $db->setQuery('SELECT MAX(ordering) FROM #__circolari_firmetipi');
$max = $db->loadResult(); $max = $db->loadResult();

View File

@ -42,8 +42,8 @@ HTMLHelper::_('bootstrap.tooltip');
<?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'); ?>
<?php echo $this->form->renderField('tipologia_firma_id'); ?>
<?php echo $this->form->renderField('firma_obbligatoria'); ?> <?php echo $this->form->renderField('firma_obbligatoria'); ?>
<?php echo $this->form->renderField('tipologia_firma_id'); ?>
<?php echo $this->form->renderField('scadenza'); ?> <?php echo $this->form->renderField('scadenza'); ?>
</fieldset> </fieldset>
</div> </div>

View File

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

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @version CVS: 1.0.0 * @version CVS: 1.0.0
* @package Com_Highlights * @package Com_Highlights
@ -26,7 +27,7 @@ HTMLHelper::_('bootstrap.tooltip');
action="<?php echo Route::_('index.php?option=com_circolari&layout=edit&id=' . (int) $this->item->id); ?>" action="<?php echo Route::_('index.php?option=com_circolari&layout=edit&id=' . (int) $this->item->id); ?>"
method="post" enctype="multipart/form-data" name="adminForm" id="etichetta-form" class="form-validate form-horizontal"> method="post" enctype="multipart/form-data" name="adminForm" id="etichetta-form" class="form-validate form-horizontal">
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => 'etichetta')); ?> <?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => 'etichetta')); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'etichetta', Text::_('COM_CIRCOLARI_TAB_ETICHETTA', true)); ?> <?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'etichetta', Text::_('COM_CIRCOLARI_TAB_ETICHETTA', true)); ?>
<div class="row-fluid"> <div class="row-fluid">
@ -35,7 +36,7 @@ HTMLHelper::_('bootstrap.tooltip');
<legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_ETICHETTA'); ?></legend> <legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_ETICHETTA'); ?></legend>
<?php echo $this->form->renderField('nome'); ?> <?php echo $this->form->renderField('nome'); ?>
<?php echo $this->form->renderField('descrizione'); ?> <?php echo $this->form->renderField('descrizione'); ?>
<?php echo $this->form->renderField('bottoni_firma'); ?> <?php echo $this->form->renderField('bottoni_firma'); ?>
</fieldset> </fieldset>
</div> </div>
@ -48,10 +49,10 @@ HTMLHelper::_('bootstrap.tooltip');
<?php echo $this->form->renderField('created_by'); ?> <?php echo $this->form->renderField('created_by'); ?>
<?php echo $this->form->renderField('modified_by'); ?> <?php echo $this->form->renderField('modified_by'); ?>
<?php echo HTMLHelper::_('uitab.endTabSet'); ?> <?php echo HTMLHelper::_('uitab.endTabSet'); ?>
<input type="hidden" name="task" value=""/> <input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?> <?php echo HTMLHelper::_('form.token'); ?>
</form> </form>