generazione automatica alias
This commit is contained in:
@ -14,6 +14,10 @@
|
||||
<field name="created_by" type="createdby" default="0" label="JGLOBAL_FIELD_CREATED_BY_LABEL" description="JGLOBAL_FIELD_CREATED_BY_DESC" hidden="true" hint="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_CREATED_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_CIRCOLARI_FORM_LBL_CIRCOLARE_MODIFIED_BY"/>
|
||||
<field name="title" filter="safehtml" type="text" label="JGLOBAL_TITLE" description="JFIELD_TITLE_DESC" hint="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_TITLE"/>
|
||||
<field name="alias"
|
||||
type="text"
|
||||
label="JFIELD_ALIAS_LABEL"
|
||||
description="JFIELD_ALIAS_DESC" />
|
||||
<field name="description" filter="safehtml" type="textarea" label="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION" description="COM_CIRCOLARI_FORM_DESC_CIRCOLARE_DESCRIPTION" hint="COM_CIRCOLARI_FORM_LBL_CIRCOLARE_DESCRIPTION"/>
|
||||
<field name="attachment" type="media"
|
||||
label="COM_CIRCOLARI_FIELD_ATTACHMENT_LABEL"
|
||||
|
||||
@ -1 +1,9 @@
|
||||
/* Only premium users are allowed to update a component */
|
||||
ALTER TABLE `#__circolari`
|
||||
ADD COLUMN `alias` VARCHAR(255) NOT NULL DEFAULT '' AFTER `title`,
|
||||
ADD INDEX `idx_alias` (`alias`);
|
||||
|
||||
-- (facoltativo) prima valorizzazione "grezza" per i record esistenti
|
||||
UPDATE `#__circolari`
|
||||
SET `alias` = LOWER(REPLACE(TRIM(`title`), ' ', '-'))
|
||||
WHERE (`alias` = '' OR `alias` IS NULL) AND `title` IS NOT NULL;
|
||||
|
||||
1
administrator/sql/updates/1.1.0.sql
Normal file
1
administrator/sql/updates/1.1.0.sql
Normal file
@ -0,0 +1 @@
|
||||
/* Only premium users are allowed to update a component */
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Circolari
|
||||
@ -20,6 +21,7 @@ use \Joomla\CMS\Helper\TagsHelper;
|
||||
use \Joomla\CMS\Filter\OutputFilter;
|
||||
use \Joomla\CMS\Event\Model;
|
||||
use Joomla\CMS\Event\AbstractEvent;
|
||||
use Joomla\CMS\Application\ApplicationHelper;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,249 +31,289 @@ use Joomla\CMS\Event\AbstractEvent;
|
||||
*/
|
||||
class CircolareModel extends AdminModel
|
||||
{
|
||||
/**
|
||||
* @var string The prefix to use with controller messages.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $text_prefix = 'COM_CIRCOLARI';
|
||||
/**
|
||||
* @var string The prefix to use with controller messages.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $text_prefix = 'COM_CIRCOLARI';
|
||||
|
||||
/**
|
||||
* @var string Alias to manage history control
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $typeAlias = 'com_circolari.circolare';
|
||||
/**
|
||||
* @var string Alias to manage history control
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $typeAlias = 'com_circolari.circolare';
|
||||
|
||||
/**
|
||||
* @var null Item data
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $item = null;
|
||||
/**
|
||||
* @var null Item data
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $item = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param string $type The table type to instantiate
|
||||
* @param string $prefix A prefix for the table class name. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return Table A database object
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTable($type = 'Circolare', $prefix = 'Administrator', $config = array())
|
||||
{
|
||||
return parent::getTable($type, $prefix, $config);
|
||||
}
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param string $type The table type to instantiate
|
||||
* @param string $prefix A prefix for the table class name. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return Table A database object
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTable($type = 'Circolare', $prefix = 'Administrator', $config = array())
|
||||
{
|
||||
return parent::getTable($type, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return \JForm|boolean A \JForm object on success, false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Initialise variables.
|
||||
$app = Factory::getApplication();
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return \JForm|boolean A \JForm object on success, false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Initialise variables.
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Get the form.
|
||||
$form = $this->loadForm(
|
||||
'com_circolari.circolare',
|
||||
'circolare',
|
||||
array(
|
||||
'control' => 'jform',
|
||||
'load_data' => $loadData
|
||||
)
|
||||
);
|
||||
// Get the form.
|
||||
$form = $this->loadForm(
|
||||
'com_circolari.circolare',
|
||||
'circolare',
|
||||
array(
|
||||
'control' => 'jform',
|
||||
'load_data' => $loadData
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = Factory::getApplication()->getUserState('com_circolari.edit.circolare.data', array());
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = Factory::getApplication()->getUserState('com_circolari.edit.circolare.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
if ($this->item === null)
|
||||
{
|
||||
$this->item = $this->getItem();
|
||||
}
|
||||
if (empty($data)) {
|
||||
if ($this->item === null) {
|
||||
$this->item = $this->getItem();
|
||||
}
|
||||
|
||||
$data = $this->item;
|
||||
$data = $this->item;
|
||||
}
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
if ($item = parent::getItem($pk)) {
|
||||
if (isset($item->params)) {
|
||||
$item->params = json_encode($item->params);
|
||||
}
|
||||
|
||||
if ($item = parent::getItem($pk))
|
||||
{
|
||||
if (isset($item->params))
|
||||
{
|
||||
$item->params = json_encode($item->params);
|
||||
}
|
||||
// Do any procesing on fields here if needed
|
||||
}
|
||||
|
||||
// Do any procesing on fields here if needed
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to duplicate an Circolare
|
||||
*
|
||||
* @param array &$pks An array of primary key IDs.
|
||||
*
|
||||
* @return boolean True if successful.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function duplicate(&$pks)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
/**
|
||||
* Method to duplicate an Circolare
|
||||
*
|
||||
* @param array &$pks An array of primary key IDs.
|
||||
*
|
||||
* @return boolean True if successful.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function duplicate(&$pks)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
||||
// Access checks.
|
||||
if (!$user->authorise('core.create', 'com_circolari'))
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
|
||||
}
|
||||
// Access checks.
|
||||
if (!$user->authorise('core.create', 'com_circolari')) {
|
||||
throw new \Exception(Text::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
|
||||
}
|
||||
|
||||
$context = $this->option . '.' . $this->name;
|
||||
$context = $this->option . '.' . $this->name;
|
||||
|
||||
// Include the plugins for the save events.
|
||||
PluginHelper::importPlugin($this->events_map['save']);
|
||||
// Include the plugins for the save events.
|
||||
PluginHelper::importPlugin($this->events_map['save']);
|
||||
|
||||
$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->load($pk, true)) {
|
||||
// Reset the id to create a new record.
|
||||
$table->id = 0;
|
||||
|
||||
if (!$table->check())
|
||||
{
|
||||
throw new \Exception($table->getError());
|
||||
}
|
||||
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,
|
||||
]
|
||||
);
|
||||
// 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);
|
||||
// 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'] : [];
|
||||
// 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());
|
||||
}
|
||||
// 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());
|
||||
}
|
||||
// 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
|
||||
$this->cleanCache();
|
||||
|
||||
// Clean cache
|
||||
$this->cleanCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Prepare and sanitise the table prior to saving.
|
||||
*
|
||||
* @param Table $table Table Object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
jimport('joomla.filter.output');
|
||||
|
||||
/**
|
||||
* Prepare and sanitise the table prior to saving.
|
||||
*
|
||||
* @param Table $table Table Object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
jimport('joomla.filter.output');
|
||||
if (empty($table->id)) {
|
||||
// Set ordering to the last item if not set
|
||||
if (@$table->ordering === '') {
|
||||
$db = $this->getDbo();
|
||||
$db->setQuery('SELECT MAX(ordering) FROM #__circolari');
|
||||
$max = $db->loadResult();
|
||||
$table->ordering = $max + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($table->id))
|
||||
{
|
||||
// Set ordering to the last item if not set
|
||||
if (@$table->ordering === '')
|
||||
{
|
||||
$db = $this->getDbo();
|
||||
$db->setQuery('SELECT MAX(ordering) FROM #__circolari');
|
||||
$max = $db->loadResult();
|
||||
$table->ordering = $max + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
public function check()
|
||||
{
|
||||
// ordering per nuovi record
|
||||
if (property_exists($this, 'ordering') && (int) $this->id === 0) {
|
||||
$this->ordering = self::getNextOrder();
|
||||
}
|
||||
|
||||
// Titolo obbligatorio (se vuoi forzarlo)
|
||||
$this->title = trim((string) ($this->title ?? ''));
|
||||
if ($this->title === '') {
|
||||
$this->setError(Text::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- ALIAS: genera se vuoto, ripulisci, evita "solo numeri", garantisci univocità ---
|
||||
$this->alias = trim((string) ($this->alias ?? ''));
|
||||
|
||||
// Se mancante → dal titolo
|
||||
if ($this->alias === '') {
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->title);
|
||||
} else {
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->alias);
|
||||
}
|
||||
|
||||
// Evita alias vuoto o numerico puro
|
||||
if ($this->alias === '' || ctype_digit($this->alias)) {
|
||||
$seed = (int) ($this->id ?: time());
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->title . '-' . $seed);
|
||||
}
|
||||
|
||||
// Unicità alias nel contesto tabella
|
||||
$base = $this->alias;
|
||||
$i = 2;
|
||||
while ($this->aliasExists($this->alias, (int) $this->id)) {
|
||||
$this->alias = $base . '-' . $i;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return parent::check();
|
||||
}
|
||||
|
||||
protected function aliasExists(string $alias, int $excludeId = 0): bool
|
||||
{
|
||||
$q = $this->_db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
->from($this->_db->quoteName('#__circolari'))
|
||||
->where($this->_db->quoteName('alias') . ' = ' . $this->_db->quote($alias));
|
||||
|
||||
if ($excludeId > 0) {
|
||||
$q->where($this->_db->quoteName('id') . ' != ' . (int) $excludeId);
|
||||
}
|
||||
|
||||
$this->_db->setQuery($q);
|
||||
return ((int) $this->_db->loadResult()) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Circolari
|
||||
@ -25,6 +26,7 @@ use \Joomla\CMS\Filesystem\File;
|
||||
use \Joomla\Registry\Registry;
|
||||
use \Pcrt\Component\Circolari\Administrator\Helper\CircolariHelper;
|
||||
use \Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\CMS\Application\ApplicationHelper;
|
||||
|
||||
|
||||
/**
|
||||
@ -37,12 +39,12 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
use TaggableTableTrait;
|
||||
|
||||
/**
|
||||
* Indicates that columns fully support the NULL value in the database
|
||||
*
|
||||
* @var boolean
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $_supportNullValue = true;
|
||||
* Indicates that columns fully support the NULL value in the database
|
||||
*
|
||||
* @var boolean
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $_supportNullValue = true;
|
||||
|
||||
|
||||
/**
|
||||
@ -55,7 +57,6 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
$this->typeAlias = 'com_circolari.circolare';
|
||||
parent::__construct('#__circolari', 'id', $db);
|
||||
$this->setColumnAlias('published', 'state');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,37 +92,31 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
$input = Factory::getApplication()->input;
|
||||
$task = $input->getString('task', '');
|
||||
|
||||
if ($array['id'] == 0 && empty($array['created_by']))
|
||||
{
|
||||
if ($array['id'] == 0 && empty($array['created_by'])) {
|
||||
$array['created_by'] = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
if ($array['id'] == 0 && empty($array['modified_by']))
|
||||
{
|
||||
if ($array['id'] == 0 && empty($array['modified_by'])) {
|
||||
$array['modified_by'] = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
if ($task == 'apply' || $task == 'save')
|
||||
{
|
||||
if ($task == 'apply' || $task == 'save') {
|
||||
$array['modified_by'] = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
if (isset($array['params']) && is_array($array['params']))
|
||||
{
|
||||
if (isset($array['params']) && is_array($array['params'])) {
|
||||
$registry = new Registry;
|
||||
$registry->loadArray($array['params']);
|
||||
$array['params'] = (string) $registry;
|
||||
}
|
||||
|
||||
if (isset($array['metadata']) && is_array($array['metadata']))
|
||||
{
|
||||
if (isset($array['metadata']) && is_array($array['metadata'])) {
|
||||
$registry = new Registry;
|
||||
$registry->loadArray($array['metadata']);
|
||||
$array['metadata'] = (string) $registry;
|
||||
}
|
||||
|
||||
if (!$user->authorise('core.admin', 'com_circolari.circolare.' . $array['id']))
|
||||
{
|
||||
if (!$user->authorise('core.admin', 'com_circolari.circolare.' . $array['id'])) {
|
||||
$actions = Access::getActionsFromFile(
|
||||
JPATH_ADMINISTRATOR . '/components/com_circolari/access.xml',
|
||||
"/access/section[@name='circolare']/"
|
||||
@ -129,10 +124,8 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
$default_actions = Access::getAssetRules('com_circolari.circolare.' . $array['id'])->getData();
|
||||
$array_jaccess = array();
|
||||
|
||||
foreach ($actions as $action)
|
||||
{
|
||||
if (key_exists($action->name, $default_actions))
|
||||
{
|
||||
foreach ($actions as $action) {
|
||||
if (key_exists($action->name, $default_actions)) {
|
||||
$array_jaccess[$action->name] = $default_actions[$action->name];
|
||||
}
|
||||
}
|
||||
@ -141,8 +134,7 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
}
|
||||
|
||||
// Bind the rules for ACL where supported.
|
||||
if (isset($array['rules']) && is_array($array['rules']))
|
||||
{
|
||||
if (isset($array['rules']) && is_array($array['rules'])) {
|
||||
$this->setRules($array['rules']);
|
||||
}
|
||||
|
||||
@ -179,14 +171,11 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
{
|
||||
$rules = array();
|
||||
|
||||
foreach ($jaccessrules as $action => $jaccess)
|
||||
{
|
||||
foreach ($jaccessrules as $action => $jaccess) {
|
||||
$actions = array();
|
||||
|
||||
if ($jaccess)
|
||||
{
|
||||
foreach ($jaccess->getData() as $group => $allow)
|
||||
{
|
||||
if ($jaccess) {
|
||||
foreach ($jaccess->getData() as $group => $allow) {
|
||||
$actions[$group] = ((bool)$allow);
|
||||
}
|
||||
}
|
||||
@ -205,11 +194,45 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
public function check()
|
||||
{
|
||||
// If there is an ordering column and this is a new row then get the next ordering value
|
||||
if (property_exists($this, 'ordering') && $this->id == 0)
|
||||
{
|
||||
if (property_exists($this, 'ordering') && $this->id == 0) {
|
||||
$this->ordering = self::getNextOrder();
|
||||
}
|
||||
|
||||
// Ordering per nuovi record
|
||||
if (property_exists($this, 'ordering') && (int) $this->id === 0) {
|
||||
$this->ordering = self::getNextOrder();
|
||||
}
|
||||
|
||||
// Titolo obbligatorio (se preferisci non forzarlo, rimuovi questo blocco)
|
||||
$this->title = trim((string) ($this->title ?? ''));
|
||||
if ($this->title === '') {
|
||||
$this->setError(Text::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- ALIAS: genera se vuoto, pulisci, evita solo-numeri, rendilo unico ---
|
||||
$this->alias = trim((string) ($this->alias ?? ''));
|
||||
|
||||
// Se non presente → dal titolo
|
||||
if ($this->alias === '') {
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->title);
|
||||
} else {
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->alias);
|
||||
}
|
||||
|
||||
// Evita alias vuoto o numerico puro
|
||||
if ($this->alias === '' || ctype_digit($this->alias)) {
|
||||
$seed = (int) ($this->id ?: time());
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->title . '-' . $seed);
|
||||
}
|
||||
|
||||
// Unicità alias nella tabella
|
||||
$base = $this->alias;
|
||||
$i = 2;
|
||||
while ($this->aliasExists($this->alias, (int) $this->id)) {
|
||||
$this->alias = $base . '-' . $i;
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
return parent::check();
|
||||
@ -251,8 +274,7 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
$assetParent->loadByName('com_circolari');
|
||||
|
||||
// Return the found asset-parent-id
|
||||
if ($assetParent->id)
|
||||
{
|
||||
if ($assetParent->id) {
|
||||
$assetParentId = $assetParent->id;
|
||||
}
|
||||
|
||||
@ -262,18 +284,34 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
//XXX_CUSTOM_TABLE_FUNCTION
|
||||
|
||||
|
||||
/**
|
||||
* Delete a record by id
|
||||
*
|
||||
* @param mixed $pk Primary key value to delete. Optional
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($pk = null)
|
||||
{
|
||||
$this->load($pk);
|
||||
$result = parent::delete($pk);
|
||||
/**
|
||||
* Delete a record by id
|
||||
*
|
||||
* @param mixed $pk Primary key value to delete. Optional
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($pk = null)
|
||||
{
|
||||
$this->load($pk);
|
||||
$result = parent::delete($pk);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function aliasExists(string $alias, int $excludeId = 0): bool
|
||||
{
|
||||
$q = $this->_db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
->from($this->_db->quoteName('#__circolari'))
|
||||
->where($this->_db->quoteName('alias') . ' = ' . $this->_db->quote($alias));
|
||||
|
||||
if ($excludeId > 0) {
|
||||
$q->where($this->_db->quoteName('id') . ' != ' . (int) $excludeId);
|
||||
}
|
||||
|
||||
$this->_db->setQuery($q);
|
||||
return ((int) $this->_db->loadResult()) > 0;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ HTMLHelper::_('bootstrap.tooltip');
|
||||
<fieldset class="adminform">
|
||||
<legend><?php echo Text::_('COM_CIRCOLARI_FIELDSET_CIRCOLARI'); ?></legend>
|
||||
<?php echo $this->form->renderField('title'); ?>
|
||||
<?php echo $this->form->renderField('alias'); ?>
|
||||
<?php echo $this->form->renderField('description'); ?>
|
||||
<?php echo $this->form->renderField('attachment'); ?>
|
||||
<?php echo $this->form->renderField('image'); ?>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<author>Tommaso Cippitelli</author>
|
||||
<authorEmail>tommaso.cippitelli@protocollicreativi.it</authorEmail>
|
||||
<authorUrl>http://</authorUrl>
|
||||
<version>CVS: 1.0.0</version>
|
||||
<version>CVS: 1.1.0</version>
|
||||
<description></description>
|
||||
<namespace path="src">Pcrt\Component\Circolari</namespace>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user