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