Current File : /home/pacjaorg/public_html/kmm/administrator/components/com_djclassifieds/models/regions.php
<?php
/**
 * @package DJ-Classifieds
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email: contact@dj-extensions.com
 */

defined ('_JEXEC') or die('Restricted access');

class DjClassifiedsModelRegions extends JModelList
{
	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'name', 'r.name',
				'id', 'r.id',				
				'price', 'r.price',				
				'published', 'r.published',
				'ordering', 'r.ordering',
				'region'
			);
		}
		parent::__construct($config);
	}
		
	protected function populateState($ordering = null, $direction = null)
	{
		$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
		$this->setState('filter.search', $search);		
		
		$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published', '');
		$this->setState('filter.published', $published);

		$region = $this->getUserStateFromRequest($this->context.'.filter.region', 'filter_region', '');
		$this->setState('filter.region', $region);
		
		// List state information.
		parent::populateState('name', 'asc');

		$order = $this->getUserStateFromRequest($this->context.'.filter.order', 'filter_order');
		if($order){
			$this->setState('list.ordering', $order);
		}
		$order_dir = $this->getUserStateFromRequest($this->context.'.filter.order_Dir', 'filter_order_Dir');
		if($order_dir){
			$this->setState('list.direction', $order_dir);
		}
	}

	protected function getStoreId($id = '')
	{
		// Compile the store id.
		$id	.= ':'.$this->getState('filter.search');
		$id	.= ':'.$this->getState('filter.region');
		$id	.= ':'.$this->getState('filter.published');
		
		return parent::getStoreId($id);
	}
	
	public function _buildWhere()
	{
		$where = '';

		$region = $this->getState('filter.region');
		if($region != '') {
			if($region == -1){
				$region = 0;
			}
			$where = ' AND r.parent_id = ' . (int) $region;
		}
		
		$search = $this->getState('filter.search');		
		if (!empty($search)) {
			$db = JFactory::getDBO();
			$search_id = $db->Quote($db->escape($search, true));
			$search = $db->Quote('%'.$db->escape($search, true).'%');
			$where .= " AND (CONCAT_WS(' ', r.name, r.alias) LIKE ".$search." OR r.id=".$search_id.")";
		}
		
		$published = $this->getState('filter.published'); 
		if (is_numeric($published)) {
			$where .= ' AND r.published = ' . (int) $published;
		}
		
		return $where;
	}	

	protected function getListQuery()
	{
		$orderCol = $this->getState('list.ordering');
		$orderDirn	= $this->getState('list.direction');

		$query = "SELECT r.*, rr.name as parent_name FROM #__djcf_regions r "
				."LEFT JOIN #__djcf_regions rr ON r.parent_id=rr.id "
				."WHERE 1 ".$this->_buildWhere()." ORDER BY r.".$orderCol.' '.$orderDirn;
		return $query;
	}

	function getItems()
	{
		if($this->getState('filter.region') != '' || $this->getState('filter.search') != '' || $this->getState('filter.published') != ''){
			return parent::getItems();
		}else{
			$orderCol = $this->getState('list.ordering');
			$orderDirn	= $this->getState('list.direction');
			$limitstart = $this->getState('list.start', 0);
			$limit = $this->getState('list.limit', 0);

			$regions = DJClassifiedsRegion::getRegAll('0', $orderCol, $orderDirn);

			if($limit){
				$regions = array_slice($regions, $limitstart, $limit);
			}else{
				$regions = array_slice($regions, 0);
			}

			return $regions;
		}
	}

	function getBatchForm()
	{
		return JForm::getInstance('batch_regions', JPATH_ROOT.'/administrator/components/com_djclassifieds/models/forms/batch_regions.xml');
	}
}
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

Site will be available soon. Thank you for your patience!