| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @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 ContactModelFeatured 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 cotnact 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 ); 70 } 71 72 parent::__construct($config); 73 } 74 75 /** 76 * Method to get a list of items. 77 * 78 * @return mixed An array of objects on success, false on failure. 79 */ 80 public function getItems() 81 { 82 // Invoke the parent getItems method to get the main list 83 $items = parent::getItems(); 84 85 // Convert the params field into an object, saving original in _params 86 for ($i = 0, $n = count($items); $i < $n; $i++) { 87 $item = &$items[$i]; 88 if (!isset($this->_params)) { 89 $params = new JRegistry(); 90 $params->loadString($item->params); 91 $item->params = $params; 92 } 93 } 94 95 return $items; 96 } 97 98 /** 99 * Method to build an SQL query to load the list data. 100 * 101 * @return string An SQL query 102 * @since 1.6 103 */ 104 protected function getListQuery() 105 { 106 $user = JFactory::getUser(); 107 $groups = implode(',', $user->getAuthorisedViewLevels()); 108 109 // Create a new query object. 110 $db = $this->getDbo(); 111 $query = $db->getQuery(true); 112 113 // Select required fields from the categories. 114 $query->select($this->getState('list.select', 'a.*')); 115 $query->from($db->quoteName('#__contact_details').' AS a'); 116 $query->where('a.access IN ('.$groups.')'); 117 $query->where('a.featured=1'); 118 $query->join('INNER', '#__categories AS c ON c.id = a.catid'); 119 $query->where('c.access IN ('.$groups.')'); 120 // Filter by category. 121 if ($categoryId = $this->getState('category.id')) { 122 $query->where('a.catid = '.(int) $categoryId); 123 } 124 //sqlsrv change... aliased c.published to cat_published 125 // Join to check for category published state in parent categories up the tree 126 $query->select('c.published as cat_published, CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published'); 127 $subquery = 'SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent '; 128 $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt '; 129 $subquery .= 'WHERE parent.extension = ' . $db->quote('com_contact'); 130 // Find any up-path categories that are not published 131 // If all categories are published, badcats.id will be null, and we just use the contact state 132 $subquery .= ' AND parent.published != 1 GROUP BY cat.id '; 133 // Select state to unpublished if up-path category is unpublished 134 $publishedWhere = 'CASE WHEN badcats.id is null THEN a.published ELSE 0 END'; 135 $query->join('LEFT OUTER', '(' . $subquery . ') AS badcats ON badcats.id = c.id'); 136 137 // Filter by state 138 $state = $this->getState('filter.published'); 139 if (is_numeric($state)) { 140 $query->where('a.published = '.(int) $state); 141 142 // Filter by start and end dates. 143 $nullDate = $db->Quote($db->getNullDate()); 144 $date = JFactory::getDate(); 145 $nowDate = $db->Quote($date->toSql()); 146 $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); 147 $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); 148 $query->where($publishedWhere . ' = ' . (int) $state); 149 } 150 151 152 153 // Filter by language 154 if ($this->getState('filter.language')) { 155 $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')'); 156 } 157 158 // Add the list ordering clause. 159 $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 160 161 return $query; 162 } 163 164 /** 165 * Method to auto-populate the model state. 166 * 167 * Note. Calling getState in this method will result in recursion. 168 * 169 * @since 1.6 170 */ 171 protected function populateState($ordering = null, $direction = null) 172 { 173 // Initialise variables. 174 $app = JFactory::getApplication(); 175 $params = JComponentHelper::getParams('com_contact'); 176 177 // List state information 178 $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); 179 $this->setState('list.limit', $limit); 180 181 $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); 182 $this->setState('list.start', $limitstart); 183 184 $orderCol = JRequest::getCmd('filter_order', 'ordering'); 185 if (!in_array($orderCol, $this->filter_fields)) { 186 $orderCol = 'ordering'; 187 } 188 $this->setState('list.ordering', $orderCol); 189 190 $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); 191 if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { 192 $listOrder = 'ASC'; 193 } 194 $this->setState('list.direction', $listOrder); 195 196 $user = JFactory::getUser(); 197 if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))){ 198 // limit to published for people who can't edit or edit.state. 199 $this->setState('filter.published', 1); 200 201 // Filter by start and end dates. 202 $this->setState('filter.publish_date', true); 203 } 204 205 $this->setState('filter.language', $app->getLanguageFilter()); 206 207 // Load the parameters. 208 $this->setState('params', $params); 209 } 210 211 212 213 }
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 |