[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_fields 6 * 7 * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Fields\Administrator\Table; 12 13 use Joomla\CMS\Access\Rules; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Table\Table; 17 use Joomla\Database\DatabaseDriver; 18 use Joomla\Registry\Registry; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Groups Table 26 * 27 * @since 3.7.0 28 */ 29 class GroupTable extends Table 30 { 31 /** 32 * Indicates that columns fully support the NULL value in the database 33 * 34 * @var boolean 35 * @since 4.0.0 36 */ 37 protected $_supportNullValue = true; 38 39 /** 40 * Class constructor. 41 * 42 * @param DatabaseDriver $db DatabaseDriver object. 43 * 44 * @since 3.7.0 45 */ 46 public function __construct($db = null) 47 { 48 parent::__construct('#__fields_groups', 'id', $db); 49 50 $this->setColumnAlias('published', 'state'); 51 } 52 53 /** 54 * Method to bind an associative array or object to the JTable instance.This 55 * method only binds properties that are publicly accessible and optionally 56 * takes an array of properties to ignore when binding. 57 * 58 * @param mixed $src An associative array or object to bind to the JTable instance. 59 * @param mixed $ignore An optional array or space separated list of properties to ignore while binding. 60 * 61 * @return boolean True on success. 62 * 63 * @since 3.7.0 64 * @throws \InvalidArgumentException 65 */ 66 public function bind($src, $ignore = '') 67 { 68 if (isset($src['params']) && is_array($src['params'])) { 69 $registry = new Registry(); 70 $registry->loadArray($src['params']); 71 $src['params'] = (string) $registry; 72 } 73 74 // Bind the rules. 75 if (isset($src['rules']) && is_array($src['rules'])) { 76 $rules = new Rules($src['rules']); 77 $this->setRules($rules); 78 } 79 80 return parent::bind($src, $ignore); 81 } 82 83 /** 84 * Method to perform sanity checks on the JTable instance properties to ensure 85 * they are safe to store in the database. Child classes should override this 86 * method to make sure the data they are storing in the database is safe and 87 * as expected before storage. 88 * 89 * @return boolean True if the instance is sane and able to be stored in the database. 90 * 91 * @link https://docs.joomla.org/Special:MyLanguage/JTable/check 92 * @since 3.7.0 93 */ 94 public function check() 95 { 96 // Check for a title. 97 if (trim($this->title) == '') { 98 $this->setError(Text::_('COM_FIELDS_MUSTCONTAIN_A_TITLE_GROUP')); 99 100 return false; 101 } 102 103 $date = Factory::getDate()->toSql(); 104 $user = Factory::getUser(); 105 106 // Set created date if not set. 107 if (!(int) $this->created) { 108 $this->created = $date; 109 } 110 111 if ($this->id) { 112 $this->modified = $date; 113 $this->modified_by = $user->get('id'); 114 } else { 115 if (!(int) $this->modified) { 116 $this->modified = $this->created; 117 } 118 119 if (empty($this->created_by)) { 120 $this->created_by = $user->get('id'); 121 } 122 123 if (empty($this->modified_by)) { 124 $this->modified_by = $this->created_by; 125 } 126 } 127 128 if ($this->params === null) { 129 $this->params = '{}'; 130 } 131 132 return true; 133 } 134 135 /** 136 * Overloaded store function 137 * 138 * @param boolean $updateNulls True to update fields even if they are null. 139 * 140 * @return mixed False on failure, positive integer on success. 141 * 142 * @see Table::store() 143 * @since 4.0.0 144 */ 145 public function store($updateNulls = true) 146 { 147 return parent::store($updateNulls); 148 } 149 150 /** 151 * Method to compute the default name of the asset. 152 * The default name is in the form table_name.id 153 * where id is the value of the primary key of the table. 154 * 155 * @return string 156 * 157 * @since 3.7.0 158 */ 159 protected function _getAssetName() 160 { 161 $component = explode('.', $this->context); 162 163 return $component[0] . '.fieldgroup.' . (int) $this->id; 164 } 165 166 /** 167 * Method to return the title to use for the asset table. In 168 * tracking the assets a title is kept for each asset so that there is some 169 * context available in a unified access manager. Usually this would just 170 * return $this->title or $this->name or whatever is being used for the 171 * primary name of the row. If this method is not overridden, the asset name is used. 172 * 173 * @return string The string to use as the title in the asset table. 174 * 175 * @link https://docs.joomla.org/Special:MyLanguage/JTable/getAssetTitle 176 * @since 3.7.0 177 */ 178 protected function _getAssetTitle() 179 { 180 return $this->title; 181 } 182 183 /** 184 * Method to get the parent asset under which to register this one. 185 * By default, all assets are registered to the ROOT node with ID, 186 * which will default to 1 if none exists. 187 * The extended class can define a table and id to lookup. If the 188 * asset does not exist it will be created. 189 * 190 * @param Table $table A Table object for the asset parent. 191 * @param integer $id Id to look up 192 * 193 * @return integer 194 * 195 * @since 3.7.0 196 */ 197 protected function _getAssetParentId(Table $table = null, $id = null) 198 { 199 $component = explode('.', $this->context); 200 $db = $this->getDbo(); 201 $query = $db->getQuery(true) 202 ->select($db->quoteName('id')) 203 ->from($db->quoteName('#__assets')) 204 ->where($db->quoteName('name') . ' = :name') 205 ->bind(':name', $component[0]); 206 $db->setQuery($query); 207 208 if ($assetId = (int) $db->loadResult()) { 209 return $assetId; 210 } 211 212 return parent::_getAssetParentId($table, $id); 213 } 214 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |