Stabilization
This commit is contained in:
@ -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>
|
||||
</form>
|
||||
@ -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"
|
||||
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." />
|
||||
<field
|
||||
name="bottoni_firma"
|
||||
type="subform"
|
||||
formsource="administrator/components/com_circolari/forms/fields/bottoni_firma.xml"
|
||||
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">
|
||||
<option value="*">JALL</option>
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
|
||||
class CategoriaController extends FormController
|
||||
{
|
||||
protected $view_list = 'categorie';
|
||||
protected $view_item = 'categoria';
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -21,4 +21,5 @@ use Joomla\CMS\MVC\Controller\FormController;
|
||||
class FirmatipoController extends FormController
|
||||
{
|
||||
protected $view_list = 'firmetipi';
|
||||
protected $view_item = 'firmatipo';
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Circolari
|
||||
@ -50,8 +51,8 @@ class FirmatipoModel extends AdminModel
|
||||
*/
|
||||
protected $item = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
@ -86,25 +87,24 @@ class FirmatipoModel extends AdminModel
|
||||
|
||||
// Get the form.
|
||||
$form = $this->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();
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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)) : ?>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @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); ?>"
|
||||
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.addTab', 'myTab', 'etichetta', Text::_('COM_CIRCOLARI_TAB_ETICHETTA', true)); ?>
|
||||
<div class="row-fluid">
|
||||
@ -35,7 +36,7 @@ HTMLHelper::_('bootstrap.tooltip');
|
||||
<legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_ETICHETTA'); ?></legend>
|
||||
<?php echo $this->form->renderField('nome'); ?>
|
||||
<?php echo $this->form->renderField('descrizione'); ?>
|
||||
<?php echo $this->form->renderField('bottoni_firma'); ?>
|
||||
<?php echo $this->form->renderField('bottoni_firma'); ?>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
@ -48,10 +49,10 @@ HTMLHelper::_('bootstrap.tooltip');
|
||||
<?php echo $this->form->renderField('created_by'); ?>
|
||||
<?php echo $this->form->renderField('modified_by'); ?>
|
||||
|
||||
|
||||
|
||||
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
|
||||
|
||||
<input type="hidden" name="task" value=""/>
|
||||
<input type="hidden" name="task" value="" />
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
|
||||
</form>
|
||||
</form>
|
||||
Reference in New Issue
Block a user