diff --git a/administrator/sql/install.mysql.utf8.sql b/administrator/sql/install.mysql.utf8.sql
index c2f870d..0d52dd1 100644
--- a/administrator/sql/install.mysql.utf8.sql
+++ b/administrator/sql/install.mysql.utf8.sql
@@ -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;
+
diff --git a/administrator/src/Controller/CategoriaController.php b/administrator/src/Controller/CategoriaController.php
index b7c9ec6..8be3f04 100644
--- a/administrator/src/Controller/CategoriaController.php
+++ b/administrator/src/Controller/CategoriaController.php
@@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
class CategoriaController extends FormController
{
protected $view_list = 'categorie';
+ protected $view_item = 'categoria';
}
diff --git a/administrator/src/Controller/CategorieController.php b/administrator/src/Controller/CategorieController.php
index f82b4d1..41ed0ed 100644
--- a/administrator/src/Controller/CategorieController.php
+++ b/administrator/src/Controller/CategorieController.php
@@ -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));
}
diff --git a/administrator/src/Controller/FirmatipoController.php b/administrator/src/Controller/FirmatipoController.php
index 7c9548e..90ff9a2 100644
--- a/administrator/src/Controller/FirmatipoController.php
+++ b/administrator/src/Controller/FirmatipoController.php
@@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
class FirmatipoController extends FormController
{
protected $view_list = 'firmetipi';
+ protected $view_item = 'firmatipo';
}
diff --git a/administrator/src/Controller/FirmetipiController.php b/administrator/src/Controller/FirmetipiController.php
index 21361ea..4756fb9 100644
--- a/administrator/src/Controller/FirmetipiController.php
+++ b/administrator/src/Controller/FirmetipiController.php
@@ -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));
}
diff --git a/administrator/src/Model/FirmatipoModel.php b/administrator/src/Model/FirmatipoModel.php
index d23efaf..788ef44 100644
--- a/administrator/src/Model/FirmatipoModel.php
+++ b/administrator/src/Model/FirmatipoModel.php
@@ -1,4 +1,5 @@
loadForm(
- 'com_circolari.firmaTipo',
- 'firmaTipo',
- array(
- 'control' => 'jform',
- 'load_data' => $loadData
- )
- );
+ 'com_circolari.firmaTipo',
+ 'firmaTipo',
+ array(
+ 'control' => 'jform',
+ 'load_data' => $loadData
+ )
+ );
-
- if (empty($form))
- {
+
+ if (empty($form)) {
return false;
}
return $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.
$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;
@@ -143,21 +140,111 @@ class FirmatipoModel extends AdminModel
*/
public function getItem($pk = null)
{
-
- if ($item = parent::getItem($pk))
- {
- if (isset($item->params))
- {
- $item->params = json_encode($item->params);
- }
-
- // Do any procesing on fields here if needed
+
+ if ($item = parent::getItem($pk)) {
+ if (isset($item->params)) {
+ $item->params = json_encode($item->params);
}
- 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 l’ID 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
*
@@ -171,11 +258,10 @@ class FirmatipoModel extends AdminModel
{
$app = Factory::getApplication();
$user = $app->getIdentity();
- $dispatcher = $this->getDispatcher();
+ $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,61 +272,55 @@ class FirmatipoModel extends AdminModel
$table = $this->getTable();
- foreach ($pks as $pk)
- {
-
- if ($table->load($pk, true))
- {
- // Reset the id to create a new record.
- $table->id = 0;
+ foreach ($pks as $pk) {
- if (!$table->check())
- {
- throw new \Exception($table->getError());
- }
-
+ if ($table->load($pk, true)) {
+ // Reset the id to create a new record.
+ $table->id = 0;
- // 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
- {
+ if (!$table->check()) {
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
@@ -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();
diff --git a/administrator/tmpl/circolare/edit.php b/administrator/tmpl/circolare/edit.php
index c62dcf9..e9e50e9 100644
--- a/administrator/tmpl/circolare/edit.php
+++ b/administrator/tmpl/circolare/edit.php
@@ -42,8 +42,8 @@ HTMLHelper::_('bootstrap.tooltip');
form->renderField('description'); ?>
form->renderField('attachment'); ?>
form->renderField('image'); ?>
- form->renderField('tipologia_firma_id'); ?>
form->renderField('firma_obbligatoria'); ?>
+ form->renderField('tipologia_firma_id'); ?>
form->renderField('scadenza'); ?>
diff --git a/administrator/tmpl/circolares/default.php b/administrator/tmpl/circolares/default.php
index ea11e0a..b237a5d 100644
--- a/administrator/tmpl/circolares/default.php
+++ b/administrator/tmpl/circolares/default.php
@@ -107,7 +107,7 @@ if (!empty($saveOrder)) {
title, ENT_QUOTES, 'UTF-8'); ?>
- | tipologia_nome; ?> |
+ tipologia_firma_id; ?> |
firma_obbligatoria ? 'Sì' : 'No'; ?> |
scadenza; ?> |
items[0]->ordering)) : ?>
diff --git a/administrator/tmpl/firmatipo/edit.php b/administrator/tmpl/firmatipo/edit.php
index 1200fc3..850f909 100644
--- a/administrator/tmpl/firmatipo/edit.php
+++ b/administrator/tmpl/firmatipo/edit.php
@@ -1,4 +1,5 @@
item->id); ?>"
method="post" enctype="multipart/form-data" name="adminForm" id="etichetta-form" class="form-validate form-horizontal">
-
+
'etichetta')); ?>
@@ -35,7 +36,7 @@ HTMLHelper::_('bootstrap.tooltip');
form->renderField('nome'); ?>
form->renderField('descrizione'); ?>
- form->renderField('bottoni_firma'); ?>
+ form->renderField('bottoni_firma'); ?>
@@ -48,10 +49,10 @@ HTMLHelper::_('bootstrap.tooltip');
form->renderField('created_by'); ?>
form->renderField('modified_by'); ?>
-
+
-
+
-
+
\ No newline at end of file