| [ 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 * Methods supporting a list of weblink records. 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_weblinks 16 * @since 1.6 17 */ 18 class WeblinksModelWeblinks extends JModelList 19 { 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 'alias', 'a.alias', 35 'checked_out', 'a.checked_out', 36 'checked_out_time', 'a.checked_out_time', 37 'catid', 'a.catid', 'category_title', 38 'state', 'a.state', 39 'access', 'a.access', 'access_level', 40 'created', 'a.created', 41 'created_by', 'a.created_by', 42 'ordering', 'a.ordering', 43 'featured', 'a.featured', 44 'language', 'a.language', 45 'hits', 'a.hits', 46 'publish_up', 'a.publish_up', 47 'publish_down', 'a.publish_down', 48 'url', 'a.url', 49 ); 50 } 51 52 parent::__construct($config); 53 } 54 55 56 /** 57 * Method to auto-populate the model state. 58 * 59 * Note. Calling getState in this method will result in recursion. 60 * 61 * @since 1.6 62 */ 63 protected function populateState($ordering = null, $direction = null) 64 { 65 // Initialise variables. 66 $app = JFactory::getApplication('administrator'); 67 68 // Load the filter state. 69 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 70 $this->setState('filter.search', $search); 71 72 $accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int'); 73 $this->setState('filter.access', $accessId); 74 75 $published = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string'); 76 $this->setState('filter.state', $published); 77 78 $categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', ''); 79 $this->setState('filter.category_id', $categoryId); 80 81 $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', ''); 82 $this->setState('filter.language', $language); 83 84 // Load the parameters. 85 $params = JComponentHelper::getParams('com_weblinks'); 86 $this->setState('params', $params); 87 88 // List state information. 89 parent::populateState('a.title', 'asc'); 90 } 91 92 /** 93 * Method to get a store id based on model configuration state. 94 * 95 * This is necessary because the model is used by the component and 96 * different modules that might need different sets of data or different 97 * ordering requirements. 98 * 99 * @param string $id A prefix for the store id. 100 * @return string A store id. 101 * @since 1.6 102 */ 103 protected function getStoreId($id = '') 104 { 105 // Compile the store id. 106 $id.= ':' . $this->getState('filter.search'); 107 $id.= ':' . $this->getState('filter.access'); 108 $id.= ':' . $this->getState('filter.state'); 109 $id.= ':' . $this->getState('filter.category_id'); 110 $id.= ':' . $this->getState('filter.language'); 111 112 return parent::getStoreId($id); 113 } 114 115 /** 116 * Build an SQL query to load the list data. 117 * 118 * @return JDatabaseQuery 119 * @since 1.6 120 */ 121 protected function getListQuery() 122 { 123 // Create a new query object. 124 $db = $this->getDbo(); 125 $query = $db->getQuery(true); 126 $user = JFactory::getUser(); 127 128 // Select the required fields from the table. 129 $query->select( 130 $this->getState( 131 'list.select', 132 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' . 133 'a.hits,' . 134 'a.state, a.access, a.ordering,'. 135 'a.language, a.publish_up, a.publish_down' 136 ) 137 ); 138 $query->from($db->quoteName('#__weblinks').' AS a'); 139 140 // Join over the language 141 $query->select('l.title AS language_title'); 142 $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language'); 143 144 // Join over the users for the checked out user. 145 $query->select('uc.name AS editor'); 146 $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); 147 148 // Join over the asset groups. 149 $query->select('ag.title AS access_level'); 150 $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); 151 152 // Join over the categories. 153 $query->select('c.title AS category_title'); 154 $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); 155 156 // Filter by access level. 157 if ($access = $this->getState('filter.access')) { 158 $query->where('a.access = '.(int) $access); 159 } 160 161 // Implement View Level Access 162 if (!$user->authorise('core.admin')) 163 { 164 $groups = implode(',', $user->getAuthorisedViewLevels()); 165 $query->where('a.access IN ('.$groups.')'); 166 } 167 168 // Filter by published state 169 $published = $this->getState('filter.state'); 170 if (is_numeric($published)) { 171 $query->where('a.state = '.(int) $published); 172 } elseif ($published === '') { 173 $query->where('(a.state IN (0, 1))'); 174 } 175 176 // Filter by category. 177 $categoryId = $this->getState('filter.category_id'); 178 if (is_numeric($categoryId)) { 179 $query->where('a.catid = '.(int) $categoryId); 180 } 181 182 // Filter by search in title 183 $search = $this->getState('filter.search'); 184 if (!empty($search)) { 185 if (stripos($search, 'id:') === 0) { 186 $query->where('a.id = '.(int) substr($search, 3)); 187 } else { 188 $search = $db->Quote('%'.$db->escape($search, true).'%'); 189 $query->where('(a.title LIKE '.$search.' OR a.alias LIKE '.$search.')'); 190 } 191 } 192 193 // Filter on the language. 194 if ($language = $this->getState('filter.language')) { 195 $query->where('a.language = ' . $db->quote($language)); 196 } 197 198 // Add the list ordering clause. 199 $orderCol = $this->state->get('list.ordering'); 200 $orderDirn = $this->state->get('list.direction'); 201 if ($orderCol == 'a.ordering' || $orderCol == 'category_title') { 202 $orderCol = 'c.title '.$orderDirn.', a.ordering'; 203 } 204 $query->order($db->escape($orderCol.' '.$orderDirn)); 205 206 //echo nl2br(str_replace('#__','jos_',$query)); 207 return $query; 208 } 209 }
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 |