File manager - Edit - /home/opticamezl/www/newok/administrator/components/com_rereplacer/src/Model/ItemModel.php
Back
<?php /** * @package ReReplacer * @version 14.4.1 * * @author Peter van Westen <info@regularlabs.com> * @link https://regularlabs.com * @copyright Copyright © 2025 Regular Labs All Rights Reserved * @license GNU General Public License version 2 or later */ namespace RegularLabs\Component\ReReplacer\Administrator\Model; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Form\Form as JForm; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\MVC\Model\AdminModel as JAdminModel; use Joomla\CMS\Object\CMSObject as JCMSObject; use Joomla\Utilities\ArrayHelper as JArray; use RegularLabs\Component\Conditions\Administrator\Model\ItemModel as Condition; use RegularLabs\Library\Input as RL_Input; use RegularLabs\Library\Parameters as RL_Parameters; use RegularLabs\Library\StringHelper as RL_String; defined('_JEXEC') or die; class ItemModel extends JAdminModel { /** * @var string The prefix to use with controller messages. */ protected $text_prefix = 'RL'; /** * @param array &$pks An array of record primary keys. * * @return boolean True if successful, false if an error occurs. */ public function delete(&$pks) { if ( ! parent::delete($pks)) { return false; } $this->removeConditions($pks); } /** * @param int $id * * @return boolean True on success. */ public function duplicate($id) { $item = $this->getItem($id); if (empty($item)) { return false; } // unset($item->_errors); unset($item->typeAlias); $from_id = $item->id; $item->id = 0; $item->published = 0; $this->incrementName($item->name, $item->id); $item = $this->validate(null, (array) $item); if ( ! parent::save($item)) { return false; } $to_id = $this->getState($this->getName() . '.id', 'id'); $this->copyConditions($from_id, $to_id); return true; } /** * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return JForm A Form object on success, false on failure */ public function getForm($data = [], $loadData = true) { // Get the form. $form = $this->loadForm('com_rereplacer.item', 'item', ['control' => 'jform', 'load_data' => $loadData]); if (empty($form)) { return false; } // Modify the form based on access controls. if ($this->canEditState((object) $data) != true) { // Disable fields for display. $form->setFieldAttribute('published', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('published', 'filter', 'unset'); } return $form; } /** * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { // Initialise variables. $pk = ( ! empty($pk)) ? $pk : (int) $this->getState($this->getName() . '.id'); $table = $this->getTable(); if ($pk > 0) { // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return false; } } $properties = $table->getProperties(1); $item = JArray::toObject($properties, JCMSObject::class); $params = RL_Parameters::getObjectFromRegistry($item->params, JPATH_ADMINISTRATOR . '/components/com_rereplacer/forms/item.xml'); foreach ($params as $key => $val) { if (isset($item->{$key})) { continue; } $item->{$key} = $val; } unset($item->params); return $item; } /** * @param array $data The form data. * * @return boolean True on success. */ public function save($data) { $task = RL_Input::getCmd('task'); if ($task == 'save2copy') { $data['published'] = 0; } $this->incrementName($data['name'], (int) $data['id']); if ( ! parent::save($data)) { return false; } if ($task != 'save2copy') { return true; } $from_id = RL_Input::getInt('id'); $to_id = $this->getState($this->getName() . '.id', 'id'); $this->copyConditions($from_id, $to_id); return true; } /** * Method to validate form data. */ public function validate($form, $data, $group = null) { // Check for valid name if (empty($data['name'])) { $this->setError(JText::_('RR_THE_ITEM_MUST_HAVE_A_NAME')); return false; } if (trim($data['search']) == '') { $this->setError(JText::_('RR_THE_ITEM_MUST_HAVE_SOMETHING_TO_SEARCH_FOR')); return false; } $params = []; $this->_db->setQuery('SHOW COLUMNS FROM #__rereplacer'); $dbkeys = $this->_db->loadColumn(); $newdata = []; foreach ($data as $key => $val) { if (in_array($key, $dbkeys)) { $newdata[$key] = $val; continue; } $params[$key] = $val; } $newdata['params'] = json_encode($params); return $newdata; } /** * @param object $record A record object. * * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. */ protected function canDelete($record) { if ($record->published != -2) { return false; } return parent::canDelete($record); } /** * @return mixed The data for the form. */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_rereplacer.edit.item.data', []); if (empty($data)) { $data = $this->getItem(); } $this->preprocessData('com_rereplacer.item', $data); return $data; } private function copyConditions($from_id, $to_id) { } private function incrementName(string &$name, int $id = 0) { while ($this->nameExists($name, $id)) { $name = RL_String::increment($name); } } private function nameExists($name, $id = 0) { $db = $this->getDbo(); $query = $db->getQuery(true) ->select('id') ->from('#__rereplacer') ->where($db->quoteName('name') . ' = ' . $db->quote($name)) ->where($db->quoteName('published') . ' != -2') ->setLimit(1); if ($id) { $query->where($db->quoteName('id') . ' != ' . (int) $id); } $db->setQuery($query); return (boolean) $db->loadResult(); } private function removeConditions($ids) { } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings