| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_categories 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // Check to ensure this file is included in Joomla! 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modellist'); 13 14 /** 15 * Categories Component Categories Model 16 * 17 * @package Joomla.Administrator 18 * @subpackage com_categories 19 * @since 1.6 20 */ 21 class CategoriesModelCategories extends JModelList 22 { 23 /** 24 * Constructor. 25 * 26 * @param array An optional associative array of configuration settings. 27 * @see JController 28 * @since 1.6 29 */ 30 public function __construct($config = array()) 31 { 32 if (empty($config['filter_fields'])) { 33 $config['filter_fields'] = array( 34 'id', 'a.id', 35 'title', 'a.title', 36 'alias', 'a.alias', 37 'published', 'a.published', 38 'access', 'a.access', 'access_level', 39 'language', 'a.language', 40 'checked_out', 'a.checked_out', 41 'checked_out_time', 'a.checked_out_time', 42 'created_time', 'a.created_time', 43 'created_user_id', 'a.created_user_id', 44 'lft', 'a.lft', 45 'rgt', 'a.rgt', 46 'level', 'a.level', 47 'path', 'a.path', 48 ); 49 } 50 51 parent::__construct($config); 52 } 53 54 /** 55 * Method to auto-populate the model state. 56 * 57 * Note. Calling getState in this method will result in recursion. 58 * 59 * @param string An optional ordering field. 60 * @param string An optional direction (asc|desc). 61 * 62 * @return void 63 * @since 1.6 64 */ 65 protected function populateState($ordering = null, $direction = null) 66 { 67 // Initialise variables. 68 $app = JFactory::getApplication(); 69 $context = $this->context; 70 71 $extension = $app->getUserStateFromRequest('com_categories.categories.filter.extension', 'extension', 'com_content', 'cmd'); 72 73 $this->setState('filter.extension', $extension); 74 $parts = explode('.', $extension); 75 76 // extract the component name 77 $this->setState('filter.component', $parts[0]); 78 79 // extract the optional section name 80 $this->setState('filter.section', (count($parts) > 1) ? $parts[1] : null); 81 82 $search = $this->getUserStateFromRequest($context.'.search', 'filter_search'); 83 $this->setState('filter.search', $search); 84 85 $level = $this->getUserStateFromRequest($context.'.filter.level', 'filter_level', 0, 'int'); 86 $this->setState('filter.level', $level); 87 88 $access = $this->getUserStateFromRequest($context.'.filter.access', 'filter_access', 0, 'int'); 89 $this->setState('filter.access', $access); 90 91 $published = $this->getUserStateFromRequest($context.'.filter.published', 'filter_published', ''); 92 $this->setState('filter.published', $published); 93 94 $language = $this->getUserStateFromRequest($context.'.filter.language', 'filter_language', ''); 95 $this->setState('filter.language', $language); 96 97 // List state information. 98 parent::populateState('a.lft', 'asc'); 99 } 100 101 /** 102 * Method to get a store id based on model configuration state. 103 * 104 * This is necessary because the model is used by the component and 105 * different modules that might need different sets of data or different 106 * ordering requirements. 107 * 108 * @param string $id A prefix for the store id. 109 * 110 * @return string A store id. 111 * @since 1.6 112 */ 113 protected function getStoreId($id = '') 114 { 115 // Compile the store id. 116 $id .= ':'.$this->getState('filter.search'); 117 $id .= ':'.$this->getState('filter.extension'); 118 $id .= ':'.$this->getState('filter.published'); 119 $id .= ':'.$this->getState('filter.language'); 120 121 return parent::getStoreId($id); 122 } 123 124 /** 125 * @return string 126 * @since 1.6 127 */ 128 function getListQuery() 129 { 130 // Create a new query object. 131 $db = $this->getDbo(); 132 $query = $db->getQuery(true); 133 $user = JFactory::getUser(); 134 135 // Select the required fields from the table. 136 $query->select( 137 $this->getState( 138 'list.select', 139 'a.id, a.title, a.alias, a.note, a.published, a.access' . 140 ', a.checked_out, a.checked_out_time, a.created_user_id' . 141 ', a.path, a.parent_id, a.level, a.lft, a.rgt' . 142 ', a.language' 143 ) 144 ); 145 $query->from('#__categories AS a'); 146 147 // Join over the language 148 $query->select('l.title AS language_title'); 149 $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language'); 150 151 // Join over the users for the checked out user. 152 $query->select('uc.name AS editor'); 153 $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); 154 155 // Join over the asset groups. 156 $query->select('ag.title AS access_level'); 157 $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); 158 159 // Join over the users for the author. 160 $query->select('ua.name AS author_name'); 161 $query->join('LEFT', '#__users AS ua ON ua.id = a.created_user_id'); 162 163 // Filter by extension 164 if ($extension = $this->getState('filter.extension')) { 165 $query->where('a.extension = '.$db->quote($extension)); 166 } 167 168 // Filter on the level. 169 if ($level = $this->getState('filter.level')) { 170 $query->where('a.level <= '.(int) $level); 171 } 172 173 // Filter by access level. 174 if ($access = $this->getState('filter.access')) { 175 $query->where('a.access = ' . (int) $access); 176 } 177 178 // Implement View Level Access 179 if (!$user->authorise('core.admin')) 180 { 181 $groups = implode(',', $user->getAuthorisedViewLevels()); 182 $query->where('a.access IN ('.$groups.')'); 183 } 184 185 // Filter by published state 186 $published = $this->getState('filter.published'); 187 if (is_numeric($published)) { 188 $query->where('a.published = ' . (int) $published); 189 } 190 elseif ($published === '') { 191 $query->where('(a.published IN (0, 1))'); 192 } 193 194 // Filter by search in title 195 $search = $this->getState('filter.search'); 196 if (!empty($search)) { 197 if (stripos($search, 'id:') === 0) { 198 $query->where('a.id = '.(int) substr($search, 3)); 199 } 200 elseif (stripos($search, 'author:') === 0) { 201 $search = $db->Quote('%'.$db->escape(substr($search, 7), true).'%'); 202 $query->where('(ua.name LIKE '.$search.' OR ua.username LIKE '.$search.')'); 203 } 204 else { 205 $search = $db->Quote('%'.$db->escape($search, true).'%'); 206 $query->where('(a.title LIKE '.$search.' OR a.alias LIKE '.$search.' OR a.note LIKE '.$search.')'); 207 } 208 } 209 210 // Filter on the language. 211 if ($language = $this->getState('filter.language')) { 212 $query->where('a.language = '.$db->quote($language)); 213 } 214 215 // Add the list ordering clause 216 $listOrdering = $this->getState('list.ordering', 'a.lft'); 217 $listDirn = $db->escape($this->getState('list.direction', 'ASC')); 218 if ($listOrdering == 'a.access') { 219 $query->order('a.access '.$listDirn.', a.lft '.$listDirn); 220 } else { 221 $query->order($db->escape($listOrdering).' '.$listDirn); 222 } 223 224 //echo nl2br(str_replace('#__','jos_',$query)); 225 return $query; 226 } 227 }
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 |