| [ 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 banner records. 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_banners 16 * @since 1.6 17 */ 18 class BannersModelBanners 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 'cid', 'a.cid', 'client_name', 33 'name', 'a.name', 34 'alias', 'a.alias', 35 'state', 'a.state', 36 'ordering', 'a.ordering', 37 'language', 'a.language', 38 'catid', 'a.catid', 'category_title', 39 'checked_out', 'a.checked_out', 40 'checked_out_time', 'a.checked_out_time', 41 'created', 'a.created', 42 'impmade', 'a.impmade', 43 'imptotal', 'a.imptotal', 44 'clicks', 'a.clicks', 45 'publish_up', 'a.publish_up', 46 'publish_down', 'a.publish_down', 47 'state', 'sticky', 'a.sticky', 48 ); 49 } 50 51 parent::__construct($config); 52 } 53 54 /** 55 * Method to get the maximum ordering value for each category. 56 * 57 * @since 1.6 58 */ 59 function &getCategoryOrders() 60 { 61 if (!isset($this->cache['categoryorders'])) { 62 $db = $this->getDbo(); 63 $query = $db->getQuery(true); 64 $query->select('MAX(ordering) as '.$db->quoteName('max').', catid'); 65 $query->select('catid'); 66 $query->from('#__banners'); 67 $query->group('catid'); 68 $db->setQuery($query); 69 $this->cache['categoryorders'] = $db->loadAssocList('catid', 0); 70 } 71 return $this->cache['categoryorders']; 72 } 73 74 /** 75 * Build an SQL query to load the list data. 76 * 77 * @return JDatabaseQuery 78 * @since 1.6 79 */ 80 protected function getListQuery() 81 { 82 // Initialise variables. 83 $db = $this->getDbo(); 84 $query = $db->getQuery(true); 85 86 // Select the required fields from the table. 87 $query->select( 88 $this->getState( 89 'list.select', 90 'a.id AS id, a.name AS name, a.alias AS alias,'. 91 'a.checked_out AS checked_out,'. 92 'a.checked_out_time AS checked_out_time, a.catid AS catid,' . 93 'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,'. 94 'a.impmade AS impmade, a.imptotal AS imptotal,' . 95 'a.state AS state, a.ordering AS ordering,'. 96 'a.purchase_type as purchase_type,'. 97 'a.language, a.publish_up, a.publish_down' 98 ) 99 ); 100 $query->from($db->quoteName('#__banners').' AS a'); 101 102 // Join over the language 103 $query->select('l.title AS language_title'); 104 $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language'); 105 106 // Join over the users for the checked out user. 107 $query->select('uc.name AS editor'); 108 $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); 109 110 // Join over the categories. 111 $query->select('c.title AS category_title'); 112 $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); 113 114 // Join over the clients. 115 $query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type'); 116 $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); 117 118 // Filter by published state 119 $published = $this->getState('filter.state'); 120 if (is_numeric($published)) { 121 $query->where('a.state = '.(int) $published); 122 } elseif ($published === '') { 123 $query->where('(a.state IN (0, 1))'); 124 } 125 126 // Filter by category. 127 $categoryId = $this->getState('filter.category_id'); 128 if (is_numeric($categoryId)) { 129 $query->where('a.catid = '.(int) $categoryId); 130 } 131 132 // Filter by client. 133 $clientId = $this->getState('filter.client_id'); 134 if (is_numeric($clientId)) { 135 $query->where('a.cid = '.(int) $clientId); 136 } 137 138 // Filter by search in title 139 $search = $this->getState('filter.search'); 140 if (!empty($search)) { 141 if (stripos($search, 'id:') === 0) { 142 $query->where('a.id = '.(int) substr($search, 3)); 143 } else { 144 $search = $db->Quote('%'.$db->escape($search, true).'%'); 145 $query->where('(a.name LIKE '.$search.' OR a.alias LIKE '.$search.')'); 146 } 147 } 148 149 // Filter on the language. 150 if ($language = $this->getState('filter.language')) { 151 $query->where('a.language = ' . $db->quote($language)); 152 } 153 154 // Add the list ordering clause. 155 $orderCol = $this->state->get('list.ordering', 'ordering'); 156 $orderDirn = $this->state->get('list.direction', 'ASC'); 157 if ($orderCol == 'ordering' || $orderCol == 'category_title') { 158 $orderCol = 'c.title '.$orderDirn.', a.ordering'; 159 } 160 if($orderCol == 'client_name') 161 $orderCol = 'cl.name'; 162 $query->order($db->escape($orderCol.' '.$orderDirn)); 163 164 //echo nl2br(str_replace('#__','jos_',$query)); 165 return $query; 166 } 167 168 /** 169 * Method to get a store id based on model configuration state. 170 * 171 * This is necessary because the model is used by the component and 172 * different modules that might need different sets of data or different 173 * ordering requirements. 174 * 175 * @param string $id A prefix for the store id. 176 * @return string A store id. 177 * @since 1.6 178 */ 179 protected function getStoreId($id = '') 180 { 181 // Compile the store id. 182 $id .= ':'.$this->getState('filter.search'); 183 $id .= ':'.$this->getState('filter.access'); 184 $id .= ':'.$this->getState('filter.state'); 185 $id .= ':'.$this->getState('filter.category_id'); 186 $id .= ':'.$this->getState('filter.language'); 187 188 return parent::getStoreId($id); 189 } 190 191 /** 192 * Returns a reference to the a Table object, always creating it. 193 * 194 * @param type The table type to instantiate 195 * @param string A prefix for the table class name. Optional. 196 * @param array Configuration array for model. Optional. 197 * @return JTable A database object 198 * @since 1.6 199 */ 200 public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array()) 201 { 202 return JTable::getInstance($type, $prefix, $config); 203 } 204 205 /** 206 * Method to auto-populate the model state. 207 * 208 * Note. Calling getState in this method will result in recursion. 209 * 210 * @since 1.6 211 */ 212 protected function populateState($ordering = null, $direction = null) 213 { 214 // Initialise variables. 215 $app = JFactory::getApplication('administrator'); 216 217 // Load the filter state. 218 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 219 $this->setState('filter.search', $search); 220 221 $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string'); 222 $this->setState('filter.state', $state); 223 224 $categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', ''); 225 $this->setState('filter.category_id', $categoryId); 226 227 $clientId = $this->getUserStateFromRequest($this->context.'.filter.client_id', 'filter_client_id', ''); 228 $this->setState('filter.client_id', $clientId); 229 230 $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', ''); 231 $this->setState('filter.language', $language); 232 233 // Load the parameters. 234 $params = JComponentHelper::getParams('com_banners'); 235 $this->setState('params', $params); 236 237 // List state information. 238 parent::populateState('a.name', 'asc'); 239 } 240 }
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 |