Location: PHPKode > projects > HikaShop > front/views/category/view.html.php
<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.4.3
 * @author		hikashop.com
 * @copyright	(C) 2010 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
class CategoryViewCategory extends JView{
	var $type = 'product';
	var $ctrl= 'category';
	var $nameListing = 'HIKA_CATEGORIES';
	var $nameForm = 'HIKA_CATEGORIES';
	var $icon = 'category';
	var $module=false;
	function display($tpl = null,$params=array()){
		$this->paramBase = HIKASHOP_COMPONENT.'.'.$this->getName();
		$function = $this->getLayout();
		$this->params = $params;
		if(method_exists($this,$function)) $this->$function();
		parent::display($tpl);
	}
	function listing(){
		$module = hikashop::get('helper.module');
		$module->initialize($this);
		$this->paramBase.='_'.$this->params->get('main_div_name');
		$filters = array();
		$app =& JFactory::getApplication();
		$pageInfo = null;
		$database	=& JFactory::getDBO();
		if($this->params->get('content_synchronize')){
			if(JRequest::getString('option','')==HIKASHOP_COMPONENT){
				if(JRequest::getString('ctrl','category')=='product'){
					$product_id = hikashop::getCID('product_id');
					if(!empty($product_id)){
						$query = 'SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id='.$product_id;
						$database->setQuery($query);
						$pageInfo->filter->cid = $database->loadResultArray();
					}else{
						$pageInfo->filter->cid = $this->params->get('selectparentlisting');
					}
				}elseif(JRequest::getString('ctrl','category')=='category'){
					$pageInfo->filter->cid = JRequest::getInt("cid",$this->params->get('selectparentlisting'));
				}else{
					$pageInfo->filter->cid = $this->params->get('selectparentlisting');
				}
			}else{
				$pageInfo->filter->cid = $this->params->get('selectparentlisting');
			}
		}else{
			if(empty($this->module)){
				$pageInfo->filter->cid = JRequest::getInt("cid",$this->params->get('selectparentlisting'));
			}else{
				$pageInfo->filter->cid = $this->params->get('selectparentlisting');
			}
		}
		if(!empty($pageInfo->filter->cid)){
			$acl_filters = array('category_type=\'product\'');
			hikashop::addACLFilters($acl_filters,'category_access');
			if(!empty($acl_filters)){
				if(!is_array($pageInfo->filter->cid)){
					$pageInfo->filter->cid = array($pageInfo->filter->cid);
				}
				$acl_filters[]='category_id IN ('.implode(',',$pageInfo->filter->cid).')';
				$query = 'SELECT category_id FROM '.hikashop::table('category').' WHERE '.implode(' AND ',$acl_filters);
				$database->setQuery($query);
				$pageInfo->filter->cid = $database->loadResultArray();
			}
		}
		if(empty($pageInfo->filter->cid)){
			$pageInfo->filter->cid = 'product';
		}
		$category_selected='';
		if(!is_array($pageInfo->filter->cid)){
			$category_selected = '_'.$pageInfo->filter->cid;
			$this->paramBase.=$category_selected;
		}
		$this->assignRef('category_selected',$category_selected);
		$pageInfo->filter->order->value = $app->getUserStateFromRequest( $this->paramBase.".filter_order", 'filter_order_'.$this->params->get('main_div_name').$category_selected,	'a.category_ordering','cmd' );
		$pageInfo->filter->order->dir	= $app->getUserStateFromRequest( $this->paramBase.".filter_order_Dir", 'filter_order_Dir_'.$this->params->get('main_div_name').$category_selected,	'asc',	'word' );
		$pageInfo->limit->value = $app->getUserStateFromRequest( $this->paramBase.'.list_limit', 'limit_'.$this->params->get('main_div_name').$category_selected, $this->params->get('limit'), 'int' );
		$pageInfo->limit->start = $app->getUserStateFromRequest( $this->paramBase.'.limitstart', 'limitstart_'.$this->params->get('main_div_name').$category_selected, 0, 'int' );
		if(empty($this->module)){
			$cid = JRequest::getInt("cid",0);
			if(empty($cid)){
				JRequest::setVar("no_cid",1);
			}
			if(is_array($pageInfo->filter->cid)){
				JRequest::setVar("cid",reset($pageInfo->filter->cid));
			}else{
				JRequest::setVar("cid",$pageInfo->filter->cid);
			}
			JRequest::setVar('menu_main_category',$this->params->get('selectparentlisting'));
		}
		$searchMap = array('a.category_name','a.category_description','a.category_id');
		$order = '';
		if(!empty($pageInfo->filter->order->value)){
			$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
		}
		$class = hikashop::get('class.category');
		$rows = $class->getChilds($pageInfo->filter->cid,$this->params->get('filter_type'),$filters,$order,$pageInfo->limit->start,$pageInfo->limit->value,true);
		if(!empty($class->query)){
			$database->setQuery('SELECT COUNT(*) '.$class->query);
			$pageInfo->elements->total = $database->loadResult();
			$pageInfo->elements->page = count($rows);
		}else{
			$pageInfo->elements->total = 0;
			$pageInfo->elements->page = 0;
		}
		if($pageInfo->elements->page){
			$ids = array();
			foreach($rows as $key => $row){
				$ids[]=$row->category_id;
				$rows[$key]->alias = JFilterOutput::stringURLSafe($row->category_name);
			}
			if($this->params->get('child_display_type')!='nochild'){
				$database	=& JFactory::getDBO();
				$query = 'SELECT * FROM '.hikashop::table('category').' WHERE category_parent_id IN ('.implode(',',$ids).') ORDER BY category_ordering;';
				$database->setQuery($query);
				$childs = $database->loadObjectList();
				foreach($rows as $k => $row){
					foreach($childs as $child){
						if($child->category_parent_id==$row->category_id){
							$child->alias = JFilterOutput::stringURLSafe($child->category_name);
							$rows[$k]->childs[]=$child;
							$limit = $this->params->get('child_limit');
							if(!empty($limit) && count($rows[$k]->childs)>=$limit){
								break;
							}
						}
					}
				}
			}
		}
		$this->assignRef('rows',$rows);
		$this->assignRef('modules',$this->modules);
		$image=hikashop::get('helper.image');
		$this->assignRef('image',$image);
		$this->assignRef('category_image',$category_image);
		$menu_id = '';
		if(empty($this->module)){
			if(is_array($pageInfo->filter->cid)){
				$pageInfo->filter->cid = reset($pageInfo->filter->cid);
			}
			$element = $class->get($pageInfo->filter->cid,true);
			$this->assignRef('element',$element);
			$title = $this->params->get('page_title');
			$document	=& JFactory::getDocument();
			if(empty($title)){
				$this->params->set('page_title',@$element->category_name);
			}
			$use_module = $this->params->get('use_module_name');
			if(!empty($use_module)){
				$document->setTitle($this->params->get('title'));
			}else{
				$document->setTitle($this->params->get('page_title'));
			}
			$pagination = hikashop::get('helper.pagination', $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value);
			$pagination->hikaSuffix = '_'.$this->params->get('main_div_name').$category_selected;
			$this->assignRef('pagination',$pagination);
			$this->params->set('show_limit',1);
			$pathway =& $app->getPathway();
			$categories = $class->getParents($cid,$this->params->get('selectparentlisting'));
			global $Itemid;
			if(!empty($Itemid)){
				$menu_id = '&Itemid='.$Itemid;
			}
			$one = true;
			foreach($categories as $category){
				if($one){
					$one = false;
				} 
				else{
					$pathway->addItem($category->category_name,hikashop::completeLink('category&task=listing&cid='.(int)$category->category_id.'&name='.strtolower(preg_replace('#[^a-z0-9-_]#i','',$category->category_name)).$menu_id));
				}
			}
		}else{
			$menu_id = $this->params->get('itemid',0);
			if(!empty($menu_id)){
				$menu_id = '&Itemid='.$menu_id;
			}else{
				$menu_id = '';
			}
		}
		$this->assignRef('pageInfo',$pageInfo);
		$this->assignRef('menu_id',$menu_id);
		$this->assignRef('params',$this->params);
	}
}
Return current item: HikaShop