[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Table; 11 12 use Joomla\CMS\Access\Rules; 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Text; 15 use Joomla\Database\DatabaseDriver; 16 use Joomla\Registry\Registry; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('JPATH_PLATFORM') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Module table 24 * 25 * @since 1.5 26 */ 27 class Module extends Table 28 { 29 /** 30 * Indicates that columns fully support the NULL value in the database 31 * 32 * @var boolean 33 * @since 4.0.0 34 */ 35 protected $_supportNullValue = true; 36 37 /** 38 * Constructor. 39 * 40 * @param DatabaseDriver $db Database driver object. 41 * 42 * @since 1.5 43 */ 44 public function __construct(DatabaseDriver $db) 45 { 46 parent::__construct('#__modules', 'id', $db); 47 48 $this->access = (int) Factory::getApplication()->get('access'); 49 } 50 51 /** 52 * Method to compute the default name of the asset. 53 * The default name is in the form table_name.id 54 * where id is the value of the primary key of the table. 55 * 56 * @return string 57 * 58 * @since 3.2 59 */ 60 protected function _getAssetName() 61 { 62 $k = $this->_tbl_key; 63 64 return 'com_modules.module.' . (int) $this->$k; 65 } 66 67 /** 68 * Method to return the title to use for the asset table. 69 * 70 * @return string 71 * 72 * @since 3.2 73 */ 74 protected function _getAssetTitle() 75 { 76 return $this->title; 77 } 78 79 /** 80 * Method to get the parent asset id for the record 81 * 82 * @param Table $table A Table object (optional) for the asset parent 83 * @param integer $id The id (optional) of the content. 84 * 85 * @return integer 86 * 87 * @since 3.2 88 */ 89 protected function _getAssetParentId(Table $table = null, $id = null) 90 { 91 $assetId = null; 92 93 // This is a module that needs to parent with the extension. 94 if ($assetId === null) { 95 // Build the query to get the asset id of the parent component. 96 $query = $this->_db->getQuery(true) 97 ->select($this->_db->quoteName('id')) 98 ->from($this->_db->quoteName('#__assets')) 99 ->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote('com_modules')); 100 101 // Get the asset id from the database. 102 $this->_db->setQuery($query); 103 104 if ($result = $this->_db->loadResult()) { 105 $assetId = (int) $result; 106 } 107 } 108 109 // Return the asset id. 110 if ($assetId) { 111 return $assetId; 112 } else { 113 return parent::_getAssetParentId($table, $id); 114 } 115 } 116 117 /** 118 * Overloaded check function. 119 * 120 * @return boolean True if the instance is sane and able to be stored in the database. 121 * 122 * @see Table::check() 123 * @since 1.5 124 */ 125 public function check() 126 { 127 try { 128 parent::check(); 129 } catch (\Exception $e) { 130 $this->setError($e->getMessage()); 131 132 return false; 133 } 134 135 // Check for valid name 136 if (trim($this->title) === '') { 137 $this->setError(Text::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_MODULE')); 138 139 return false; 140 } 141 142 // Set publish_up, publish_down to null if not set 143 if (!$this->publish_up) { 144 $this->publish_up = null; 145 } 146 147 if (!$this->publish_down) { 148 $this->publish_down = null; 149 } 150 151 // Prevent to save too large content > 65535 152 if ((\strlen($this->content) > 65535) || (\strlen($this->params) > 65535)) { 153 $this->setError(Text::_('COM_MODULES_FIELD_CONTENT_TOO_LARGE')); 154 155 return false; 156 } 157 158 // Check the publish down date is not earlier than publish up. 159 if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) { 160 // Swap the dates. 161 $temp = $this->publish_up; 162 $this->publish_up = $this->publish_down; 163 $this->publish_down = $temp; 164 } 165 166 return true; 167 } 168 169 /** 170 * Overloaded bind function. 171 * 172 * @param array $array Named array. 173 * @param mixed $ignore An optional array or space separated list of properties to ignore while binding. 174 * 175 * @return mixed Null if operation was satisfactory, otherwise returns an error 176 * 177 * @see Table::bind() 178 * @since 1.5 179 */ 180 public function bind($array, $ignore = '') 181 { 182 if (isset($array['params']) && \is_array($array['params'])) { 183 $registry = new Registry($array['params']); 184 $array['params'] = (string) $registry; 185 } 186 187 // Bind the rules. 188 if (isset($array['rules']) && \is_array($array['rules'])) { 189 $rules = new Rules($array['rules']); 190 $this->setRules($rules); 191 } 192 193 return parent::bind($array, $ignore); 194 } 195 196 /** 197 * Stores a module. 198 * 199 * @param boolean $updateNulls True to update fields even if they are null. 200 * 201 * @return boolean True on success, false on failure. 202 * 203 * @since 3.7.0 204 */ 205 public function store($updateNulls = true) 206 { 207 if (!$this->ordering) { 208 $this->ordering = $this->getNextOrder($this->_db->quoteName('position') . ' = ' . $this->_db->quote($this->position)); 209 } 210 211 return parent::store($updateNulls); 212 } 213 }
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 |