aggiunta firma circolari
This commit is contained in:
@ -18,9 +18,7 @@
|
||||
<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"
|
||||
@ -38,6 +36,17 @@
|
||||
|
||||
</field>
|
||||
|
||||
|
||||
<field
|
||||
name="usergroup_ids"
|
||||
type="usergrouplist"
|
||||
label="Gruppi abilitati alla firma"
|
||||
description="Seleziona i gruppi che possono firmare la circolare"
|
||||
multiple="true"
|
||||
required="false"
|
||||
showon="firma_obbligatoria:1"
|
||||
/>
|
||||
|
||||
<field name="tipologia_firma_id" type="Tipologiafirma" label="Tipologia firma"
|
||||
showon="firma_obbligatoria:1" />
|
||||
<field name="scadenza" type="CalSafe" label="Data Scadenza Firma"
|
||||
|
||||
12
administrator/sql/updates/1.1.7.sql
Normal file
12
administrator/sql/updates/1.1.7.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- tabella ponte: quali gruppi possono firmare quale circolare
|
||||
CREATE TABLE IF NOT EXISTS `#__circolari_usergroups` (
|
||||
`circolare_id` INT NOT NULL,
|
||||
`usergroup_id` INT NOT NULL,
|
||||
`required` TINYINT(1) NOT NULL DEFAULT 0, -- opzionale: firma obbligatoria del gruppo
|
||||
`can_firmare` TINYINT(1) NOT NULL DEFAULT 1, -- opzionale: futura granularità
|
||||
PRIMARY KEY (`circolare_id`, `usergroup_id`),
|
||||
KEY `idx_group` (`usergroup_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
ALTER TABLE `#__circolari` DROP COLUMN `usergroup_id`;
|
||||
@ -135,6 +135,17 @@ class CircolareModel extends AdminModel
|
||||
}
|
||||
}
|
||||
|
||||
$id = (int) ($data->id ?? $this->getState($this->getName() . '.id'));
|
||||
if ($id) {
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$q = $db->getQuery(true)
|
||||
->select($db->quoteName('usergroup_id'))
|
||||
->from($db->quoteName('#__circolari_usergroups'))
|
||||
->where($db->quoteName('circolare_id') . ' = ' . (int) $id);
|
||||
$db->setQuery($q);
|
||||
$data->usergroup_ids = $db->loadColumn() ?: [];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -324,4 +335,47 @@ class CircolareModel extends AdminModel
|
||||
$this->_db->setQuery($q);
|
||||
return ((int) $this->_db->loadResult()) > 0;
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
$ok = parent::save($data);
|
||||
if (!$ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = (int) $this->getState($this->getName() . '.id');
|
||||
$groups = array_map('intval', $data['usergroup_ids'] ?? []);
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$db->transactionStart();
|
||||
|
||||
try {
|
||||
// ripulisci associazioni esistenti
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__circolari_usergroups'))
|
||||
->where($db->quoteName('circolare_id') . ' = ' . (int) $id)
|
||||
)->execute();
|
||||
|
||||
// reinserisci le nuove
|
||||
if (!empty($groups)) {
|
||||
$q = $db->getQuery(true)
|
||||
->insert($db->quoteName('#__circolari_usergroups'))
|
||||
->columns([$db->quoteName('circolare_id'), $db->quoteName('usergroup_id')]);
|
||||
|
||||
foreach ($groups as $gid) {
|
||||
$q->values((int) $id . ',' . (int) $gid);
|
||||
}
|
||||
$db->setQuery($q)->execute();
|
||||
}
|
||||
|
||||
$db->transactionCommit();
|
||||
} catch (\Throwable $e) {
|
||||
$db->transactionRollback();
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ HTMLHelper::_('bootstrap.tooltip');
|
||||
<?php echo $this->form->renderField('attachment'); ?>
|
||||
<?php echo $this->form->renderField('image'); ?>
|
||||
<?php echo $this->form->renderField('firma_obbligatoria'); ?>
|
||||
<?php echo $this->form->renderField('tipologia_firma_id'); ?>
|
||||
<?php echo $this->form->renderField('usergroup_ids'); ?>
|
||||
<?php echo $this->form->renderField('scadenza'); ?>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
@ -82,7 +82,7 @@ if (!empty($saveOrder)) {
|
||||
|
||||
<th scope="col" class="w-3 d-none d-lg-table-cell">
|
||||
|
||||
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?> </th>
|
||||
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
|
||||
Reference in New Issue
Block a user