Current File : /home/pacjaorg/public_html/kmm/administrator/components/com_djclassifieds/models/ghostads.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 DJClassifiedsModelGhostAds extends JModelList
{
	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'a.id', 'a.name', 'a.deleted', 'a.deleted_by', 'editor'	
			);
		}

		parent::__construct($config);
	}
	
	protected function populateState($ordering = null, $direction = null)
	{
		// List state information.
		parent::populateState('a.id', 'desc');

		$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
		$this->setState('filter.search', $search);

		// Load the parameters.
		$params = JComponentHelper::getParams('com_djclassifieds');
		$this->setState('params', $params);

		$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');

		return parent::getStoreId($id);
	}

	protected function getListQuery()
	{
		// Create a new query object.
		$db = $this->getDbo();
		$query = $db->getQuery(true);

		// Select the required fields from the table.
		$select_default = 'a.*, u.name AS editor';

		$query->select($this->getState('list.select', $select_default));

		$query->from('#__djcf_ghostads AS a');

		// Join over the users for the checked out user.
		$query->join('LEFT', '#__users AS u ON u.id=a.deleted_by');

		// Filter by search in title.
		$search = $this->getState('filter.search');
		if (!empty($search)) {
			$search_id = $db->Quote($db->escape($search, true));
			$search = $db->quote('%'.$db->escape($search, true).'%');
			$query->where('(a.name LIKE '.$search.' OR a.content LIKE '.$search.' OR a.id='.$search_id.' OR a.item_id='.$search_id.')');
		}

		// Add the list ordering clause.
		$orderCol	= $this->state->get('list.ordering', 'a.deleted');
		$orderDirn	= $this->state->get('list.direction', 'desc');

		$query->order($db->escape($orderCol.' '.$orderDirn));

		return $query;
	}
	
	public function getItems()
	{	
		$items = parent::getItems();

		foreach($items as $i_key => $item){
			$bids = $this->_getBids($item->item_id);
			if($bids){
				$bids_subform_arr = array();
				foreach($bids as $key => $bid){
					$bids_subform_arr['bids'.$key] = array(
						'bid_name' => $bid->u_name ? $bid->u_name : $bid->user_id,
						'bid_date' => $bid->date,
						'bid_value' => strip_tags(DJClassifiedsTheme::priceFormat($bid->price))
					);
				}

				$items[$i_key]->bids_data = $bids_subform_arr;
			}
		}

		return $items;
	}

	function _getBids($item_id)
	{
		$db = JFactory::getDBO();
		$query = "SELECT a.*, u.name as u_name "
				."FROM #__djcf_auctions a "
				."LEFT JOIN #__users u ON a.user_id=u.id "
				."WHERE a.item_id=".$item_id." "
				."ORDER BY a.date DESC";
		$db->setQuery($query);
		$bids = $db->loadObjectList();

    	return $bids;
    }
}
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

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