[ 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) 2009 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\Language\Text; 13 use Joomla\Database\DatabaseDriver; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('JPATH_PLATFORM') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * Languages table. 21 * 22 * @since 1.7.0 23 */ 24 class Language extends Table 25 { 26 /** 27 * Constructor 28 * 29 * @param DatabaseDriver $db Database driver object. 30 * 31 * @since 1.7.0 32 */ 33 public function __construct(DatabaseDriver $db) 34 { 35 parent::__construct('#__languages', 'lang_id', $db); 36 } 37 38 /** 39 * Overloaded check method to ensure data integrity 40 * 41 * @return boolean True on success 42 * 43 * @since 1.7.0 44 */ 45 public function check() 46 { 47 try { 48 parent::check(); 49 } catch (\Exception $e) { 50 $this->setError($e->getMessage()); 51 52 return false; 53 } 54 55 if (trim($this->title) == '') { 56 $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_NO_TITLE')); 57 58 return false; 59 } 60 61 return true; 62 } 63 64 /** 65 * Overrides Table::store to check unique fields. 66 * 67 * @param boolean $updateNulls True to update fields even if they are null. 68 * 69 * @return boolean True on success. 70 * 71 * @since 2.5.0 72 */ 73 public function store($updateNulls = false) 74 { 75 $table = Table::getInstance('Language', 'JTable', array('dbo' => $this->getDbo())); 76 77 // Verify that the language code is unique 78 if ($table->load(array('lang_code' => $this->lang_code)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { 79 $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_LANG_CODE')); 80 81 return false; 82 } 83 84 // Verify that the sef field is unique 85 if ($table->load(array('sef' => $this->sef)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { 86 $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE')); 87 88 return false; 89 } 90 91 // Verify that the image field is unique 92 if ($this->image && $table->load(array('image' => $this->image)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { 93 $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE')); 94 95 return false; 96 } 97 98 return parent::store($updateNulls); 99 } 100 101 /** 102 * Method to compute the default name of the asset. 103 * The default name is in the form table_name.id 104 * where id is the value of the primary key of the table. 105 * 106 * @return string 107 * 108 * @since 3.8.0 109 */ 110 protected function _getAssetName() 111 { 112 return 'com_languages.language.' . $this->lang_id; 113 } 114 115 /** 116 * Method to return the title to use for the asset table. 117 * 118 * @return string 119 * 120 * @since 3.8.0 121 */ 122 protected function _getAssetTitle() 123 { 124 return $this->title; 125 } 126 127 /** 128 * Method to get the parent asset under which to register this one. 129 * By default, all assets are registered to the ROOT node with ID, 130 * which will default to 1 if none exists. 131 * The extended class can define a table and id to lookup. If the 132 * asset does not exist it will be created. 133 * 134 * @param Table $table A Table object for the asset parent. 135 * @param integer $id Id to look up 136 * 137 * @return integer 138 * 139 * @since 3.8.0 140 */ 141 protected function _getAssetParentId(Table $table = null, $id = null) 142 { 143 $assetId = null; 144 $asset = Table::getInstance('asset'); 145 146 if ($asset->loadByName('com_languages')) { 147 $assetId = $asset->id; 148 } 149 150 return $assetId ?? parent::_getAssetParentId($table, $id); 151 } 152 }
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 |