[ 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_languages 6 * 7 * @copyright (C) 2008 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\Languages\Administrator\Model; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 15 use Joomla\CMS\MVC\Model\ListModel; 16 use Joomla\CMS\Table\Table; 17 use Joomla\Database\ParameterType; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Languages Model Class 25 * 26 * @since 1.6 27 */ 28 class LanguagesModel extends ListModel 29 { 30 /** 31 * Constructor. 32 * 33 * @param array $config An optional associative array of configuration settings. 34 * @param MVCFactoryInterface $factory The factory. 35 * 36 * @see \Joomla\CMS\MVC\Model\BaseDatabaseModel 37 * @since 3.2 38 */ 39 public function __construct($config = array(), MVCFactoryInterface $factory = null) 40 { 41 if (empty($config['filter_fields'])) { 42 $config['filter_fields'] = array( 43 'lang_id', 'a.lang_id', 44 'lang_code', 'a.lang_code', 45 'title', 'a.title', 46 'title_native', 'a.title_native', 47 'sef', 'a.sef', 48 'image', 'a.image', 49 'published', 'a.published', 50 'ordering', 'a.ordering', 51 'access', 'a.access', 'access_level', 52 'home', 'l.home', 53 ); 54 } 55 56 parent::__construct($config, $factory); 57 } 58 59 /** 60 * Method to auto-populate the model state. 61 * 62 * Note. Calling getState in this method will result in recursion. 63 * 64 * @param string $ordering An optional ordering field. 65 * @param string $direction An optional direction (asc|desc). 66 * 67 * @return void 68 * 69 * @since 1.6 70 */ 71 protected function populateState($ordering = 'a.ordering', $direction = 'asc') 72 { 73 // Load the parameters. 74 $params = ComponentHelper::getParams('com_languages'); 75 $this->setState('params', $params); 76 77 // List state information. 78 parent::populateState($ordering, $direction); 79 } 80 81 /** 82 * Method to get a store id based on model configuration state. 83 * 84 * This is necessary because the model is used by the component and 85 * different modules that might need different sets of data or different 86 * ordering requirements. 87 * 88 * @param string $id A prefix for the store id. 89 * 90 * @return string A store id. 91 * 92 * @since 1.6 93 */ 94 protected function getStoreId($id = '') 95 { 96 // Compile the store id. 97 $id .= ':' . $this->getState('filter.search'); 98 $id .= ':' . $this->getState('filter.access'); 99 $id .= ':' . $this->getState('filter.published'); 100 101 return parent::getStoreId($id); 102 } 103 104 /** 105 * Method to build an SQL query to load the list data. 106 * 107 * @return string An SQL query 108 * 109 * @since 1.6 110 */ 111 protected function getListQuery() 112 { 113 // Create a new query object. 114 $db = $this->getDatabase(); 115 $query = $db->getQuery(true); 116 117 // Select all fields from the languages table. 118 $query->select( 119 $this->getState( 120 'list.select', 121 [ 122 $db->quoteName('a') . '.*', 123 ] 124 ) 125 ) 126 ->select( 127 [ 128 $db->quoteName('l.home'), 129 $db->quoteName('ag.title', 'access_level'), 130 ] 131 ) 132 ->from($db->quoteName('#__languages', 'a')) 133 ->join('LEFT', $db->quoteName('#__viewlevels', 'ag'), $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access')) 134 ->join( 135 'LEFT', 136 $db->quoteName('#__menu', 'l'), 137 $db->quoteName('l.language') . ' = ' . $db->quoteName('a.lang_code') 138 . ' AND ' . $db->quoteName('l.home') . ' = 1 AND ' . $db->quoteName('l.language') . ' <> ' . $db->quote('*') 139 ); 140 141 // Filter on the published state. 142 $published = (string) $this->getState('filter.published'); 143 144 if (is_numeric($published)) { 145 $published = (int) $published; 146 $query->where($db->quoteName('a.published') . ' = :published') 147 ->bind(':published', $published, ParameterType::INTEGER); 148 } elseif ($published === '') { 149 $query->where($db->quoteName('a.published') . ' IN (0, 1)'); 150 } 151 152 // Filter by search in title. 153 if ($search = $this->getState('filter.search')) { 154 $search = '%' . str_replace(' ', '%', trim($search)) . '%'; 155 $query->where($db->quoteName('a.title') . ' LIKE :search') 156 ->bind(':search', $search); 157 } 158 159 // Filter by access level. 160 if ($access = (int) $this->getState('filter.access')) { 161 $query->where($db->quoteName('a.access') . ' = :access') 162 ->bind(':access', $access, ParameterType::INTEGER); 163 } 164 165 // Add the list ordering clause. 166 $query->order($db->quoteName($db->escape($this->getState('list.ordering', 'a.ordering'))) 167 . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); 168 169 return $query; 170 } 171 172 /** 173 * Set the published language(s). 174 * 175 * @param array $cid An array of language IDs. 176 * @param integer $value The value of the published state. 177 * 178 * @return boolean True on success, false otherwise. 179 * 180 * @since 1.6 181 */ 182 public function setPublished($cid, $value = 0) 183 { 184 return Table::getInstance('Language', 'Joomla\\CMS\\Table\\')->publish($cid, $value); 185 } 186 187 /** 188 * Method to delete records. 189 * 190 * @param array $pks An array of item primary keys. 191 * 192 * @return boolean Returns true on success, false on failure. 193 * 194 * @since 1.6 195 */ 196 public function delete($pks) 197 { 198 // Sanitize the array. 199 $pks = (array) $pks; 200 201 // Get a row instance. 202 $table = Table::getInstance('Language', 'Joomla\\CMS\\Table\\'); 203 204 // Iterate the items to delete each one. 205 foreach ($pks as $itemId) { 206 if (!$table->delete((int) $itemId)) { 207 $this->setError($table->getError()); 208 209 return false; 210 } 211 } 212 213 // Clean the cache. 214 $this->cleanCache(); 215 216 return true; 217 } 218 219 /** 220 * Custom clean cache method, 2 places for 2 clients. 221 * 222 * @param string $group Optional cache group name. 223 * @param integer $clientId @deprecated 5.0 No longer used. 224 * 225 * @return void 226 * 227 * @since 1.6 228 */ 229 protected function cleanCache($group = null, $clientId = 0) 230 { 231 parent::cleanCache('_system'); 232 parent::cleanCache('com_languages'); 233 } 234 }
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 |