| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: category.php 19343 2010-11-03 18:12:02Z ian $ 4 * @package Joomla 5 * @subpackage Content 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport('joomla.application.component.model'); 19 20 /** 21 * Weblinks Component Weblink Model 22 * 23 * @package Joomla 24 * @subpackage Content 25 * @since 1.5 26 */ 27 class WeblinksModelCategory extends JModel 28 { 29 /** 30 * Category id 31 * 32 * @var int 33 */ 34 var $_id = null; 35 36 /** 37 * Category ata array 38 * 39 * @var array 40 */ 41 var $_data = null; 42 43 /** 44 * Category total 45 * 46 * @var integer 47 */ 48 var $_total = null; 49 50 /** 51 * Category data 52 * 53 * @var object 54 */ 55 var $_category = null; 56 57 /** 58 * Pagination object 59 * 60 * @var object 61 */ 62 var $_pagination = null; 63 64 /** 65 * Constructor 66 * 67 * @since 1.5 68 */ 69 function __construct() 70 { 71 parent::__construct(); 72 73 global $mainframe; 74 75 $config = JFactory::getConfig(); 76 77 // Get the pagination request variables 78 $this->setState('limit', $mainframe->getUserStateFromRequest('com_weblinks.limit', 'limit', $config->getValue('config.list_limit'), 'int')); 79 $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int')); 80 81 // In case limit has been changed, adjust limitstart accordingly 82 $this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0)); 83 84 $filter_order = JRequest::getCmd('filter_order', 'ordering'); 85 $filter_order_Dir = JRequest::getCmd('filter_order_Dir', 'ASC'); 86 87 if (!in_array($filter_order, array('title', 'hits', 'ordering'))) { 88 $filter_order = 'ordering'; 89 } 90 91 if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC', ''))) { 92 $filter_order_Dir = 'ASC'; 93 } 94 95 // Get the filter request variables 96 $this->setState('filter_order', $filter_order); 97 $this->setState('filter_order_dir', $filter_order_Dir); 98 99 $id = JRequest::getVar('id', 0, '', 'int'); 100 $this->setId((int)$id); 101 } 102 103 /** 104 * Method to set the category id 105 * 106 * @access public 107 * @param int Category ID number 108 */ 109 function setId($id) 110 { 111 // Set category ID and wipe data 112 $this->_id = $id; 113 $this->_category = null; 114 } 115 116 /** 117 * Method to get weblink item data for the category 118 * 119 * @access public 120 * @return array 121 */ 122 function getData() 123 { 124 // Lets load the content if it doesn't already exist 125 if (empty($this->_data)) 126 { 127 $query = $this->_buildQuery(); 128 $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit')); 129 130 $total = count($this->_data); 131 for($i = 0; $i < $total; $i++) 132 { 133 $item =& $this->_data[$i]; 134 $item->slug = $item->id.':'.$item->alias; 135 } 136 } 137 138 return $this->_data; 139 } 140 141 /** 142 * Method to get the total number of weblink items for the category 143 * 144 * @access public 145 * @return integer 146 */ 147 function getTotal() 148 { 149 // Lets load the content if it doesn't already exist 150 if (empty($this->_total)) 151 { 152 $query = $this->_buildQuery(); 153 $this->_total = $this->_getListCount($query); 154 } 155 156 return $this->_total; 157 } 158 159 /** 160 * Method to get a pagination object of the weblink items for the category 161 * 162 * @access public 163 * @return integer 164 */ 165 function getPagination() 166 { 167 // Lets load the content if it doesn't already exist 168 if (empty($this->_pagination)) 169 { 170 jimport('joomla.html.pagination'); 171 $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') ); 172 } 173 174 return $this->_pagination; 175 } 176 177 /** 178 * Method to get category data for the current category 179 * 180 * @since 1.5 181 */ 182 function getCategory() 183 { 184 // Load the Category data 185 if ($this->_loadCategory()) 186 { 187 // Initialize some variables 188 $user = &JFactory::getUser(); 189 190 // Make sure the category is published 191 if (!$this->_category->published) { 192 JError::raiseError(404, JText::_("Resource Not Found")); 193 return false; 194 } 195 // check whether category access level allows access 196 if ($this->_category->access > $user->get('aid', 0)) { 197 JError::raiseError(403, JText::_("ALERTNOTAUTH")); 198 return false; 199 } 200 } 201 return $this->_category; 202 } 203 204 /** 205 * Method to load category data if it doesn't exist. 206 * 207 * @access private 208 * @return boolean True on success 209 */ 210 function _loadCategory() 211 { 212 if (empty($this->_category)) 213 { 214 // current category info 215 $query = 'SELECT c.*, ' . 216 ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug '. 217 ' FROM #__categories AS c' . 218 ' WHERE c.id = '. (int) $this->_id . 219 ' AND c.section = "com_weblinks"'; 220 $this->_db->setQuery($query, 0, 1); 221 $this->_category = $this->_db->loadObject(); 222 } 223 return true; 224 } 225 226 function _buildQuery() 227 { 228 $filter_order = $this->getState('filter_order'); 229 $filter_order_dir = $this->getState('filter_order_dir'); 230 231 $filter_order = JFilterInput::clean($filter_order, 'cmd'); 232 $filter_order_dir = JFilterInput::clean($filter_order_dir, 'word'); 233 234 // We need to get a list of all weblinks in the given category 235 $query = 'SELECT *' . 236 ' FROM #__weblinks' . 237 ' WHERE catid = '. (int) $this->_id. 238 ' AND published = 1' . 239 ' AND archived = 0'. 240 ' ORDER BY '. $filter_order .' '. $filter_order_dir .', ordering'; 241 242 return $query; 243 } 244 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |