| [ 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 * Newsfeeds Component Category Model 14 * 15 * @package Joomla.Site 16 * @subpackage com_newsfeeds 17 * @since 1.5 18 */ 19 class NewsfeedsModelCategory extends JModelList 20 { 21 /** 22 * Category items data 23 * 24 * @var array 25 */ 26 protected $_item = null; 27 28 protected $_articles = null; 29 30 protected $_siblings = null; 31 32 protected $_children = null; 33 34 protected $_parent = null; 35 36 /** 37 * The category that applies. 38 * 39 * @access protected 40 * @var object 41 */ 42 protected $_category = null; 43 44 /** 45 * The list of other newfeed categories. 46 * 47 * @access protected 48 * @var array 49 */ 50 protected $_categories = null; 51 52 /** 53 * Constructor. 54 * 55 * @param array An optional associative array of configuration settings. 56 * @see JController 57 * @since 1.6 58 */ 59 public function __construct($config = array()) 60 { 61 if (empty($config['filter_fields'])) { 62 $config['filter_fields'] = array( 63 'id', 'a.id', 64 'name', 'a.name', 65 'numarticles', 'a.numarticles', 66 'link', 'a.link', 67 'ordering', 'a.ordering', 68 ); 69 } 70 71 parent::__construct($config); 72 } 73 74 /** 75 * Method to get a list of items. 76 * 77 * @return mixed An array of objects on success, false on failure. 78 */ 79 public function getItems() 80 { 81 // Invoke the parent getItems method to get the main list 82 $items = parent::getItems(); 83 84 // Convert the params field into an object, saving original in _params 85 for ($i = 0, $n = count($items); $i < $n; $i++) { 86 $item = &$items[$i]; 87 if (!isset($this->_params)) { 88 $params = new JRegistry(); 89 $item->params = $params; 90 $params->loadString($item->params); 91 } 92 } 93 94 return $items; 95 } 96 97 /** 98 * Method to build an SQL query to load the list data. 99 * 100 * @return string An SQL query 101 * @since 1.6 102 */ 103 protected function getListQuery() 104 { 105 $user = JFactory::getUser(); 106 $groups = implode(',', $user->getAuthorisedViewLevels()); 107 108 // Create a new query object. 109 $db = $this->getDbo(); 110 $query = $db->getQuery(true); 111 112 // Select required fields from the categories. 113 $query->select($this->getState('list.select', 'a.*')); 114 $query->from($db->quoteName('#__newsfeeds').' AS a'); 115 $query->where('a.access IN ('.$groups.')'); 116 117 // Filter by category. 118 if ($categoryId = $this->getState('category.id')) { 119 $query->where('a.catid = '.(int) $categoryId); 120 $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); 121 $query->where('c.access IN ('.$groups.')'); 122 } 123 124 // Filter by state 125 $state = $this->getState('filter.published'); 126 if (is_numeric($state)) { 127 $query->where('a.published = '.(int) $state); 128 } 129 130 // Filter by start and end dates. 131 $nullDate = $db->Quote($db->getNullDate()); 132 $date = JFactory::getDate(); 133 $nowDate = $db->Quote($date->format($db->getDateFormat())); 134 135 if ($this->getState('filter.publish_date')){ 136 $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); 137 $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); 138 } 139 140 // Filter by language 141 if ($this->getState('filter.language')) { 142 $query->where('a.language in ('.$db->Quote(JFactory::getLanguage()->getTag()).','.$db->Quote('*').')'); 143 } 144 145 // Add the list ordering clause. 146 $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 147 148 return $query; 149 } 150 151 /** 152 * Method to auto-populate the model state. 153 * 154 * Note. Calling getState in this method will result in recursion. 155 * 156 * @since 1.6 157 */ 158 protected function populateState($ordering = null, $direction = null) 159 { 160 // Initialise variables. 161 $app = JFactory::getApplication(); 162 $params = JComponentHelper::getParams('com_newsfeeds'); 163 164 // List state information 165 $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); 166 $this->setState('list.limit', $limit); 167 168 $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); 169 $this->setState('list.start', $limitstart); 170 171 $orderCol = JRequest::getCmd('filter_order', 'ordering'); 172 if (!in_array($orderCol, $this->filter_fields)) { 173 $orderCol = 'ordering'; 174 } 175 $this->setState('list.ordering', $orderCol); 176 177 $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); 178 if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { 179 $listOrder = 'ASC'; 180 } 181 $this->setState('list.direction', $listOrder); 182 183 $id = JRequest::getVar('id', 0, '', 'int'); 184 $this->setState('category.id', $id); 185 186 $user = JFactory::getUser(); 187 if ((!$user->authorise('core.edit.state', 'com_newsfeeds')) && (!$user->authorise('core.edit', 'com_newsfeeds'))){ 188 // limit to published for people who can't edit or edit.state. 189 $this->setState('filter.published', 1); 190 191 // Filter by start and end dates. 192 $this->setState('filter.publish_date', true); 193 } 194 195 $this->setState('filter.language', $app->getLanguageFilter()); 196 197 // Load the parameters. 198 $this->setState('params', $params); 199 } 200 201 /** 202 * Method to get category data for the current category 203 * 204 * @param int An optional ID 205 * 206 * @return object 207 * @since 1.5 208 */ 209 public function getCategory() 210 { 211 if(!is_object($this->_item)) 212 { 213 $app = JFactory::getApplication(); 214 $menu = $app->getMenu(); 215 $active = $menu->getActive(); 216 $params = new JRegistry(); 217 218 if($active) 219 { 220 $params->loadString($active->params); 221 } 222 223 $options = array(); 224 $options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0); 225 $categories = JCategories::getInstance('Newsfeeds', $options); 226 $this->_item = $categories->get($this->getState('category.id', 'root')); 227 if(is_object($this->_item)) 228 { 229 $this->_children = $this->_item->getChildren(); 230 $this->_parent = false; 231 if($this->_item->getParent()) 232 { 233 $this->_parent = $this->_item->getParent(); 234 } 235 $this->_rightsibling = $this->_item->getSibling(); 236 $this->_leftsibling = $this->_item->getSibling(false); 237 } else { 238 $this->_children = false; 239 $this->_parent = false; 240 } 241 } 242 243 return $this->_item; 244 } 245 246 /** 247 * Get the parent category. 248 * 249 * @param int An optional category id. If not supplied, the model state 'category.id' will be used. 250 * 251 * @return mixed An array of categories or false if an error occurs. 252 */ 253 public function getParent() 254 { 255 if (!is_object($this->_item)) 256 { 257 $this->getCategory(); 258 } 259 return $this->_parent; 260 } 261 262 /** 263 * Get the sibling (adjacent) categories. 264 * 265 * @return mixed An array of categories or false if an error occurs. 266 */ 267 function &getLeftSibling() 268 { 269 if (!is_object($this->_item)) 270 { 271 $this->getCategory(); 272 } 273 return $this->_leftsibling; 274 } 275 276 function &getRightSibling() 277 { 278 if(!is_object($this->_item)) 279 { 280 $this->getCategory(); 281 } 282 return $this->_rightsibling; 283 } 284 285 /** 286 * Get the child categories. 287 * 288 * @param int An optional category id. If not supplied, the model state 'category.id' will be used. 289 * 290 * @return mixed An array of categories or false if an error occurs. 291 */ 292 function &getChildren() 293 { 294 if(!is_object($this->_item)) 295 { 296 $this->getCategory(); 297 } 298 return $this->_children; 299 } 300 }
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 |