?
Path : /home/admin/public_html/old/promice/components/com_download/models/ |
Current File : /home/admin/public_html/old/promice/components/com_download/models/download.php |
<?php /** * @version $Id: category.php 10752 2008-08-23 01:53:31Z eddieajau $ * @package Joomla */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die( 'Restricted access' ); jimport('joomla.application.component.model'); /** * @package Joomla * @subpackage download * @since 1.5 */ class CategoriesModelDownload extends JModel{ var $_id = null; var $_data = null; var $_total = null; var $_products = null; var $_pagination = null; function __construct() { parent::__construct(); global $mainframe; $config = JFactory::getConfig(); $this->setState('limit', $mainframe->getUserStateFromRequest('com_shopping.limit', 'limit', $config->getValue('config.list_limit'), 'int')); $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int')); $this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0)); $id = JRequest::getVar('cid', 0, '', 'int'); $this->setId((int)$id); } /** * @access public * @param int Category ID number */ function setId($id){ // Set category ID and wipe data $this->_id = $id; $this->_products = null; } /** * @access public * @return array */ function getData() { if (empty($this->_data)) { $query = $this->_buildQuery(); $total = $this->getCheck_catid(); if($total <> 0 && !empty($total)){ $limitstart = 0; $limit = 6; $this->_data = $this->_getList($query, $limitstart, $limit); } else{ $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit')); } $total = count($this->_data); for($i = 0; $i < $total; $i++) { $item =& $this->_data[$i]; $item->slug = $item->id.':'.$item->alias; } } return $this->_data; } /** * @access public * @return integer */ function getColumnTemplate(){ $query = 'SELECT show_template' . ' FROM #__download_category'; $this->_db->setQuery($query); $column = $this->_db->loadObject(); return $column; } /** * @access public * @return integer */ function getTotal(){ if (empty($this->_total)){ $query = $this->_buildQuery(); $this->_total = $this->_getListCount($query); } return $this->_total; } /** * @access public * @return integer */ function getPagination(){ if (empty($this->_pagination)){ jimport('joomla.html.pagination'); $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') ); } return $this->_pagination; } /** * @access pravite * @return string query */ function _buildQuery(){ //if category is not contain sub-category is show item of category else show new item $total = $this->getCheck_catid(); if(empty($total) || $total==0){ $query = 'SELECT *' . ' FROM #__download_products' . ' WHERE cat_id = '. (int) $this->_id. ' AND published = 1' ; } else{ $query = 'SELECT *' . ' FROM #__download_products ' . ' WHERE published = 1 ORDER BY id DESC '; ; } return $query; } /** * @access public * @return array */ function getProduct(){ $cid = JRequest::getInt('cid', 0); $pid = JRequest::getInt('pid', 0); if (empty($this->_product)){ $query = "SELECT * FROM #__download_products WHERE cat_id = ' {$cid} ' AND id = ' {$pid} ' AND published=1"; $this->_db->setQuery($query); $this->_product = $this->_db->loadObject(); } return $this->_product; } /** * @access public * @return integer * @check category have sub-cat */ function getCheck_catid(){ $select = 'SELECT parent_id' . ' FROM #__download_category' . ' WHERE parent_id = '. (int) $this->_id. ' AND published = 1' ; $this->_db->setQuery( $select ); $total = $this->_db->loadResult(); return $total; } } ?>