Current File : /home/pacjaorg/public_html/km/administrator/components/com_djclassifieds/models/promotions.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 DjClassifiedsModelPromotions extends JModelList
{
	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'name', 'p.name',
				'id', 'p.id',				
				'label', 'p.label',
				'description', 'p.description',
				'price', 'p.price',
				'points', 'p.points',
				'published', 'p.published',
				'ordering', 'p.ordering'
			);
		}

		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);
		
		// List state information.
		parent::populateState('p.ordering', '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.published');
		
		return parent::getStoreId($id);
	}
	
	public function _buildWhere()
	{
		$where = '';

		$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 (p.name LIKE ".$search." OR p.id=".$search_id.")";
		}
		
		$published = $this->getState('filter.published');
		if (is_numeric($published)) {
			$where .= ' AND p.published = ' . (int) $published;
		}

		return $where;
	}

	protected function getListQuery()
	{
		$orderCol = $this->getState('list.ordering', 'f.label');
		$orderDirn	= $this->getState('list.direction');
	
		$query = "SELECT p.* FROM #__djcf_promotions p WHERE 1 ".$this->_buildWhere()." ORDER BY ".$orderCol." ".$orderDirn." ";

		return $query;
	}

}
?>
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

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