| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 // No direct access. 8 defined('_JEXEC') or die; 9 10 jimport('joomla.application.component.modellist'); 11 12 /** 13 * Modules Component Module Model 14 * 15 * @package Joomla.Administrator 16 * @subpackage com_modules 17 * @since 1.5 18 */ 19 class ModulesModelModules extends JModelList 20 { 21 /** 22 * Constructor. 23 * 24 * @param array An optional associative array of configuration settings. 25 * @see JController 26 * @since 1.6 27 */ 28 public function __construct($config = array()) 29 { 30 if (empty($config['filter_fields'])) { 31 $config['filter_fields'] = array( 32 'id', 'a.id', 33 'title', 'a.title', 34 'checked_out', 'a.checked_out', 35 'checked_out_time', 'a.checked_out_time', 36 'published', 'a.published', 37 'access', 'a.access', 'access_level', 38 'ordering', 'a.ordering', 39 'module', 'a.module', 40 'language', 'a.language', 'language_title', 41 'publish_up', 'a.publish_up', 42 'publish_down', 'a.publish_down', 43 'client_id', 'a.client_id', 44 'position', 'a.position', 45 'pages', 46 'name', 'e.name', 47 ); 48 } 49 50 parent::__construct($config); 51 } 52 53 /** 54 * Method to auto-populate the model state. 55 * 56 * Note. Calling getState in this method will result in recursion. 57 * 58 * @since 1.6 59 */ 60 protected function populateState($ordering = null, $direction = null) 61 { 62 // Initialise variables. 63 $app = JFactory::getApplication('administrator'); 64 65 // Load the filter state. 66 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 67 $this->setState('filter.search', $search); 68 69 $accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int'); 70 $this->setState('filter.access', $accessId); 71 72 $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string'); 73 $this->setState('filter.state', $state); 74 75 $position = $this->getUserStateFromRequest($this->context.'.filter.position', 'filter_position', '', 'string'); 76 $this->setState('filter.position', $position); 77 78 $module = $this->getUserStateFromRequest($this->context.'.filter.module', 'filter_module', '', 'string'); 79 $this->setState('filter.module', $module); 80 81 $clientId = $this->getUserStateFromRequest($this->context.'.filter.client_id', 'filter_client_id', 0, 'int', false); 82 $previousId = $app->getUserState($this->context.'.filter.client_id_previous', null); 83 if($previousId != $clientId || $previousId === null){ 84 $this->getUserStateFromRequest($this->context.'.filter.client_id_previous', 'filter_client_id_previous', 0, 'int', true); 85 $app->setUserState($this->context.'.filter.client_id_previous', $clientId); 86 } 87 $this->setState('filter.client_id', $clientId); 88 89 $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', ''); 90 $this->setState('filter.language', $language); 91 92 // Load the parameters. 93 $params = JComponentHelper::getParams('com_modules'); 94 $this->setState('params', $params); 95 96 // List state information. 97 parent::populateState('position', 'asc'); 98 } 99 100 /** 101 * Method to get a store id based on model configuration state. 102 * 103 * This is necessary because the model is used by the component and 104 * different modules that might need different sets of data or different 105 * ordering requirements. 106 * 107 * @param string A prefix for the store id. 108 * 109 * @return string A store id. 110 */ 111 protected function getStoreId($id = '') 112 { 113 // Compile the store id. 114 $id .= ':'.$this->getState('filter.search'); 115 $id .= ':'.$this->getState('filter.access'); 116 $id .= ':'.$this->getState('filter.state'); 117 $id .= ':'.$this->getState('filter.position'); 118 $id .= ':'.$this->getState('filter.module'); 119 $id .= ':'.$this->getState('filter.client_id'); 120 $id .= ':'.$this->getState('filter.language'); 121 122 return parent::getStoreId($id); 123 } 124 /** 125 * Returns an object list 126 * 127 * @param string The query 128 * @param int Offset 129 * @param int The number of records 130 * @return array 131 */ 132 protected function _getList($query, $limitstart=0, $limit=0) 133 { 134 $ordering = $this->getState('list.ordering', 'ordering'); 135 if (in_array($ordering, array('pages', 'name'))) { 136 $this->_db->setQuery($query); 137 $result = $this->_db->loadObjectList(); 138 $this->translate($result); 139 $lang = JFactory::getLanguage(); 140 JArrayHelper::sortObjects($result, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale()); 141 $total = count($result); 142 $this->cache[$this->getStoreId('getTotal')] = $total; 143 if ($total < $limitstart) { 144 $limitstart = 0; 145 $this->setState('list.start', 0); 146 } 147 return array_slice($result, $limitstart, $limit ? $limit : null); 148 } 149 else { 150 if ($ordering == 'ordering') { 151 $query->order('a.position ASC'); 152 $ordering = 'a.ordering'; 153 } 154 if ($ordering == 'language_title') { 155 $ordering = 'l.title'; 156 } 157 $query->order($this->_db->quoteName($ordering) . ' ' . $this->getState('list.direction')); 158 if ($ordering == 'position') { 159 $query->order('a.ordering ASC'); 160 } 161 $result = parent::_getList($query, $limitstart, $limit); 162 $this->translate($result); 163 return $result; 164 } 165 } 166 167 /** 168 * Translate a list of objects 169 * 170 * @param array The array of objects 171 * @return array The array of translated objects 172 */ 173 protected function translate(&$items) 174 { 175 $lang = JFactory::getLanguage(); 176 $client = $this->getState('filter.client_id') ? 'administrator' : 'site'; 177 foreach($items as $item) { 178 $extension = $item->module; 179 $source = constant('JPATH_' . strtoupper($client)) . "/modules/$extension"; 180 $lang->load("$extension.sys", constant('JPATH_' . strtoupper($client)), null, false, false) 181 || $lang->load("$extension.sys", $source, null, false, false) 182 || $lang->load("$extension.sys", constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false) 183 || $lang->load("$extension.sys", $source, $lang->getDefault(), false, false); 184 $item->name = JText::_($item->name); 185 if (is_null($item->pages)) { 186 $item->pages = JText::_('JNONE'); 187 } elseif ($item->pages < 0) { 188 $item->pages = JText::_('COM_MODULES_ASSIGNED_VARIES_EXCEPT'); 189 } elseif ($item->pages > 0) { 190 $item->pages = JText::_('COM_MODULES_ASSIGNED_VARIES_ONLY'); 191 } else { 192 $item->pages = JText::_('JALL'); 193 } 194 } 195 } 196 197 /** 198 * Build an SQL query to load the list data. 199 * 200 * @return JDatabaseQuery 201 */ 202 protected function getListQuery() 203 { 204 // Create a new query object. 205 $db = $this->getDbo(); 206 $query = $db->getQuery(true); 207 208 // Select the required fields from the table. 209 $query->select( 210 $this->getState( 211 'list.select', 212 'a.id, a.title, a.note, a.position, a.module, a.language,' . 213 'a.checked_out, a.checked_out_time, a.published+2*(e.enabled-1) as published, a.access, a.ordering, a.publish_up, a.publish_down' 214 ) 215 ); 216 $query->from($db->quoteName('#__modules').' AS a'); 217 218 // Join over the language 219 $query->select('l.title AS language_title'); 220 $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language'); 221 222 // Join over the users for the checked out user. 223 $query->select('uc.name AS editor'); 224 $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); 225 226 // Join over the asset groups. 227 $query->select('ag.title AS access_level'); 228 $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); 229 230 // Join over the module menus 231 $query->select('MIN(mm.menuid) AS pages'); 232 $query->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = a.id'); 233 234 // Join over the extensions 235 $query->select('e.name AS name'); 236 $query->join('LEFT', '#__extensions AS e ON e.element = a.module'); 237 $query->group('a.id, a.title, a.note, a.position, a.module, a.language,a.checked_out,'. 238 'a.checked_out_time, a.published, a.access, a.ordering,l.title, uc.name, ag.title, e.name,'. 239 'l.lang_code, uc.id, ag.id, mm.moduleid, e.element, a.publish_up, a.publish_down,e.enabled'); 240 241 // Filter by access level. 242 if ($access = $this->getState('filter.access')) { 243 $query->where('a.access = '.(int) $access); 244 } 245 246 // Filter by published state 247 $state = $this->getState('filter.state'); 248 if (is_numeric($state)) { 249 $query->where('a.published = '.(int) $state); 250 } 251 elseif ($state === '') { 252 $query->where('(a.published IN (0, 1))'); 253 } 254 255 // Filter by position 256 $position = $this->getState('filter.position'); 257 if ($position && $position != 'none') { 258 $query->where('a.position = '.$db->Quote($position)); 259 } 260 261 elseif ($position == 'none') { 262 $query->where('a.position = '.$db->Quote('')); 263 } 264 265 // Filter by module 266 $module = $this->getState('filter.module'); 267 if ($module) { 268 $query->where('a.module = '.$db->Quote($module)); 269 } 270 271 // Filter by client. 272 $clientId = $this->getState('filter.client_id'); 273 if (is_numeric($clientId)) { 274 $query->where('a.client_id = ' . (int) $clientId . ' AND e.client_id ='. (int) $clientId); 275 } 276 277 // Filter by search in title 278 $search = $this->getState('filter.search'); 279 if (!empty($search)) 280 { 281 if (stripos($search, 'id:') === 0) { 282 $query->where('a.id = '.(int) substr($search, 3)); 283 } 284 else 285 { 286 $search = $db->Quote('%'.$db->escape($search, true).'%'); 287 $query->where('('.'a.title LIKE '.$search.' OR a.note LIKE '.$search.')'); 288 } 289 } 290 291 // Filter on the language. 292 if ($language = $this->getState('filter.language')) { 293 $query->where('a.language = ' . $db->quote($language)); 294 } 295 296 //echo nl2br(str_replace('#__','jos_',$query)); 297 return $query; 298 } 299 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |