Current File : /home/pacjaorg/public_html/km/components/com_djclassifieds/models/ordershistory.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 DjclassifiedsModelOrdersHistory extends DJClassifiedsModel
{
	public static $_items_query = '';

	function getOrders()
	{
		$app = JFactory::getApplication();
		$user = JFactory::getUser();
		$par = $app->getParams('com_djclassifieds');

		$limit = $app->input->getInt('limit', $par->get('limit_djitem_show','7'));
		$limitstart	= $app->input->getInt('limitstart', 0);

		$query = "SELECT o.*, i.name as i_name, i.alias as i_alias, i.cat_id, i.c_alias, i.region_id, i.r_name, i.r_alias, i.user_id as i_user_id, i.username, i.group_id, i.u_email as email, i.currency "
				."FROM (SELECT id, item_id, item_name, price, quantity, date, 0 is_auction FROM #__djcf_orders WHERE user_id=".$user->id." AND status=1 "
				.($par->get('show_auctions', '0') ? "UNION ALL SELECT id, item_id, '', price, 1, date, 1 FROM #__djcf_auctions WHERE user_id=".$user->id." AND win=1 " : "")
				.") o "
				."LEFT JOIN (SELECT i.*, c.id c_id, c.alias as c_alias, r.id r_id, r.name as r_name, r.alias as r_alias, u.".$par->get('authorname','name')." as username, u.email as u_email, p.group_id 
						FROM #__djcf_items i
						LEFT JOIN #__djcf_categories c ON i.cat_id=c.id 
						LEFT JOIN #__users u ON u.id=i.user_id 
						LEFT JOIN #__djcf_profiles p ON i.user_id=p.user_id 
						LEFT JOIN #__djcf_regions r ON r.id=i.region_id 
						) i ON i.id=o.item_id "
				."ORDER BY o.date DESC";
		$app->triggerEvent('onDJClassifiedsOrdershistoryQuery', array(&$query, &$limitstart, &$limit));
		self::$_items_query = $query;
		$orders = $this->_getList($query, $limitstart, $limit);

		if($orders){
			$uid_arr = array();
			$id_arr = array();
			foreach($orders as $order){
				$id_arr[] = $order->item_id;
				if($order->i_user_id){
					$uid_arr[] = $order->i_user_id; 
				}
			}
			
			$items_img = DJClassifiedsImage::getAdsImages(implode(',', $id_arr), true);

			$user_items_c = $uid_arr ? $this->getUsersItemsCount(implode(',', $uid_arr)) : '';
			
			for($i=0;$i<count($orders);$i++){
				$orders[$i]->i_user_pd = new stdClass(); // backward compatibility
				$orders[$i]->i_user_pd->value = $this->getPurchaseDetails($orders[$i]->i_user_id); // backward compatibility
				$orders[$i]->i_user_items_count = '';
				if(isset($user_items_c[$orders[$i]->i_user_id])){
					$orders[$i]->i_user_items_count = $user_items_c[$orders[$i]->i_user_id]->user_items_c;
				}

				$orders[$i]->images = !empty($items_img[$orders[$i]->item_id]) ? $items_img[$orders[$i]->item_id] : array();

				$orders[$i]->item_uri = DJClassifiedsSEO::getItemRoute($orders[$i]->item_id.':'.$orders[$i]->i_alias,$orders[$i]->cat_id.':'.$orders[$i]->c_alias,$orders[$i]->region_id.':'.$orders[$i]->r_alias);
				$orders[$i]->profile_uri = DJClassifiedsSEO::getViewUri('profile', array('group_id' => $orders[$i]->group_id)).'&uid='.DJClassifiedsSEO::getUserSlug($orders[$i]->i_user_id, $orders[$i]->username);
			}
		}	

		return $orders;
	}
	
	function getCountOrders()
	{
		$db = JFactory::getDBO();
		$query = "SELECT count(id) FROM (".self::$_items_query.") as q";
		$db->setQuery($query);
		$items_count = $db->loadResult();

		return $items_count;
	}

	function getUsersItemsCount($users_ids)
	{
		$db	= JFactory::getDBO();
		$date_now = JFactory::getDate()->toSQL();
		$query = "SELECT user_id, COUNT(i.id) as user_items_c "
				."FROM #__djcf_items i "
				."WHERE i.published=1 AND i.blocked=0 AND i.date_exp>'".$date_now."' AND i.user_id IN (".$users_ids.") "
				."GROUP BY user_id";
		$db->setQuery($query);
		$user_items_c = $db->loadObjectList('user_id');

		return $user_items_c;
	}
}
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

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