| [ 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 defined('_JEXEC') or die; 8 9 jimport('joomla.application.component.modellist'); 10 11 /** 12 * Menu Item List Model for Menus. 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_menus 16 * @since 1.6 17 */ 18 class MenusModelItems extends JModelList 19 { 20 /** 21 * Constructor. 22 * 23 * @param array An optional associative array of configuration settings. 24 * @see JController 25 * @since 1.6 26 */ 27 public function __construct($config = array()) 28 { 29 if (empty($config['filter_fields'])) { 30 $config['filter_fields'] = array( 31 'id', 'a.id', 32 'menutype', 'a.menutype', 33 'title', 'a.title', 34 'alias', 'a.alias', 35 'published', 'a.published', 36 'access', 'a.access', 'access_level', 37 'language', 'a.language', 38 'checked_out', 'a.checked_out', 39 'checked_out_time', 'a.checked_out_time', 40 'lft', 'a.lft', 41 'rgt', 'a.rgt', 42 'level', 'a.level', 43 'path', 'a.path', 44 'client_id', 'a.client_id', 45 'home', 'a.home', 46 ); 47 if (JFactory::getApplication()->get('menu_associations', 0)) { 48 $config['filter_fields'][] = 'association'; 49 } 50 } 51 52 parent::__construct($config); 53 } 54 55 /** 56 * Method to auto-populate the model state. 57 * 58 * Note. Calling getState in this method will result in recursion. 59 * 60 * @return void 61 * @since 1.6 62 */ 63 protected function populateState($ordering = null, $direction = null) 64 { 65 $app = JFactory::getApplication('administrator'); 66 67 $search = $this->getUserStateFromRequest($this->context.'.search', 'filter_search'); 68 $this->setState('filter.search', $search); 69 70 $published = $this->getUserStateFromRequest($this->context.'.published', 'filter_published', ''); 71 $this->setState('filter.published', $published); 72 73 $access = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', 0, 'int'); 74 $this->setState('filter.access', $access); 75 76 $parentId = $this->getUserStateFromRequest($this->context.'.filter.parent_id', 'filter_parent_id', 0, 'int'); 77 $this->setState('filter.parent_id', $parentId); 78 79 $level = $this->getUserStateFromRequest($this->context.'.filter.level', 'filter_level', 0, 'int'); 80 $this->setState('filter.level', $level); 81 82 $menuType = JRequest::getVar('menutype', null); 83 if ($menuType) { 84 if ($menuType != $app->getUserState($this->context.'.filter.menutype')) { 85 $app->setUserState($this->context.'.filter.menutype', $menuType); 86 JRequest::setVar('limitstart', 0); 87 } 88 } 89 else { 90 $menuType = $app->getUserState($this->context.'.filter.menutype'); 91 92 if (!$menuType) { 93 $menuType = $this->getDefaultMenuType(); 94 } 95 } 96 97 $this->setState('filter.menutype', $menuType); 98 99 $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', ''); 100 $this->setState('filter.language', $language); 101 102 // Component parameters. 103 $params = JComponentHelper::getParams('com_menus'); 104 $this->setState('params', $params); 105 106 // List state information. 107 parent::populateState('a.lft', 'asc'); 108 } 109 110 /** 111 * Method to get a store id based on model configuration state. 112 * 113 * This is necessary because the model is used by the component and 114 * different modules that might need different sets of data or different 115 * ordering requirements. 116 * 117 * @param string $id A prefix for the store id. 118 * 119 * @return string A store id. 120 * @since 1.6 121 */ 122 protected function getStoreId($id = '') 123 { 124 // Compile the store id. 125 $id .= ':'.$this->getState('filter.access'); 126 $id .= ':'.$this->getState('filter.published'); 127 $id .= ':'.$this->getState('filter.language'); 128 $id .= ':'.$this->getState('filter.search'); 129 $id .= ':'.$this->getState('filter.parent_id'); 130 $id .= ':'.$this->getState('filter.menutype'); 131 132 return parent::getStoreId($id); 133 } 134 135 /** 136 * Finds the default menu type. 137 * 138 * In the absence of better information, this is the first menu ordered by title. 139 * 140 * @return string The default menu type 141 * @since 1.6 142 */ 143 protected function getDefaultMenuType() 144 { 145 // Create a new query object. 146 $db = $this->getDbo(); 147 $query = $db->getQuery(true) 148 ->select('menutype') 149 ->from('#__menu_types') 150 ->order('title'); 151 $db->setQuery($query, 0, 1); 152 $menuType = $db->loadResult(); 153 154 return $menuType; 155 } 156 157 /** 158 * Builds an SQL query to load the list data. 159 * 160 * @return JDatabaseQuery A query object. 161 */ 162 protected function getListQuery() 163 { 164 // Create a new query object. 165 $db = $this->getDbo(); 166 $query = $db->getQuery(true); 167 $user = JFactory::getUser(); 168 $app = JFactory::getApplication(); 169 170 // Select all fields from the table. 171 $query->select($this->getState('list.select', 'a.id, a.menutype, a.title, a.alias, a.note, a.path, a.link, a.type, a.parent_id, a.level, a.published as apublished, a.component_id, a.ordering, a.checked_out, a.checked_out_time, a.browserNav, a.access, a.img, a.template_style_id, a.params, a.lft, a.rgt, a.home, a.language, a.client_id')); 172 $query->select('CASE a.type' . 173 ' WHEN ' . $db->quote('component') . ' THEN a.published+2*(e.enabled-1) ' . 174 ' WHEN ' . $db->quote('url') . ' THEN a.published+2 ' . 175 ' WHEN ' . $db->quote('alias') . ' THEN a.published+4 ' . 176 ' WHEN ' . $db->quote('separator') . ' THEN a.published+6 ' . 177 ' END AS published'); 178 $query->from($db->quoteName('#__menu').' AS a'); 179 180 // Join over the language 181 $query->select('l.title AS language_title, l.image as image'); 182 $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language'); 183 184 // Join over the users. 185 $query->select('u.name AS editor'); 186 $query->join('LEFT', $db->quoteName('#__users').' AS u ON u.id = a.checked_out'); 187 188 //Join over components 189 $query->select('c.element AS componentname'); 190 $query->join('LEFT', $db->quoteName('#__extensions').' AS c ON c.extension_id = a.component_id'); 191 192 // Join over the asset groups. 193 $query->select('ag.title AS access_level'); 194 $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); 195 196 // Join over the associations. 197 if ($app->get('menu_associations', 0)) { 198 $query->select('COUNT(asso2.id)>1 as association'); 199 $query->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context='.$db->quote('com_menus.item')); 200 $query->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key'); 201 $query->group('a.id'); 202 } 203 204 // Join over the extensions 205 $query->select('e.name AS name'); 206 $query->join('LEFT', '#__extensions AS e ON e.extension_id = a.component_id'); 207 208 // Exclude the root category. 209 $query->where('a.id > 1'); 210 $query->where('a.client_id = 0'); 211 212 // Filter on the published state. 213 $published = $this->getState('filter.published'); 214 if (is_numeric($published)) { 215 $query->where('a.published = '.(int) $published); 216 } elseif ($published === '') { 217 $query->where('(a.published IN (0, 1))'); 218 } 219 220 // Filter by search in title, alias or id 221 if ($search = trim($this->getState('filter.search'))) { 222 if (stripos($search, 'id:') === 0) { 223 $query->where('a.id = '.(int) substr($search, 3)); 224 } elseif (stripos($search, 'link:') === 0) { 225 if ($search = substr($search, 5)) { 226 $search = $db->Quote('%'.$db->escape($search, true).'%'); 227 $query->where('a.link LIKE '.$search); 228 } 229 } else { 230 $search = $db->Quote('%'.$db->escape($search, true).'%'); 231 $query->where('('.'a.title LIKE '.$search.' OR a.alias LIKE '.$search.' OR a.note LIKE '.$search.')'); 232 } 233 } 234 235 // Filter the items over the parent id if set. 236 $parentId = $this->getState('filter.parent_id'); 237 if (!empty($parentId)) { 238 $query->where('p.id = '.(int)$parentId); 239 } 240 241 // Filter the items over the menu id if set. 242 $menuType = $this->getState('filter.menutype'); 243 if (!empty($menuType)) { 244 $query->where('a.menutype = '.$db->quote($menuType)); 245 } 246 247 // Filter on the access level. 248 if ($access = $this->getState('filter.access')) { 249 $query->where('a.access = '.(int) $access); 250 } 251 252 // Implement View Level Access 253 if (!$user->authorise('core.admin')) 254 { 255 $groups = implode(',', $user->getAuthorisedViewLevels()); 256 $query->where('a.access IN ('.$groups.')'); 257 } 258 259 // Filter on the level. 260 if ($level = $this->getState('filter.level')) { 261 $query->where('a.level <= '.(int) $level); 262 } 263 264 // Filter on the language. 265 if ($language = $this->getState('filter.language')) { 266 $query->where('a.language = '.$db->quote($language)); 267 } 268 269 // Add the list ordering clause. 270 $query->order($db->escape($this->getState('list.ordering', 'a.lft')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 271 272 //echo nl2br(str_replace('#__','jos_',(string)$query)).'<hr/>'; 273 return $query; 274 } 275 }
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 |