<?php
/**
* @version		1.0
* @package		JomLand TicketCenter
* @copyright	Copyright (C) 2010 JomLand.com. All rights reserved.
* @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined( '_JEXEC' ) or die( 'Restricted access' ); 

JLoader::import('joomla.application.component.model');
/*
if (!class_exists('JLTicketCenterModelCart')){
	JLoader::import( 'cart', JPATH_SITE.DS.'components'.DS.'com_jlticketcenter'.DS.'models');	
}*/

class modJLTCenterCartHelper
{
    public static function getCart(&$params)
    {
    	//$cart = JModel::getInstance('Cart','JLTicketCenterModel')->getCart();
    	

    	$cart = modJLTCenterCartHelper::getCartData();
    	
    	$pparams = JComponentHelper::getParams('com_jlticketcenter');
    	
    	$return = array('qty'=>0,'end_time'=>0);
    	if ($cart){
    		foreach ($cart  as $item){
    			$return['qty'] +=$item->quantity;
    			$return['end_time'] = $item->add_time+($pparams->get('cart_countdown',10)*60);
    		}
    	
    		if ($return['end_time']<=time() && $pparams->get('cart_countdown',10)>0){
    			unset ($return);
    			$return= array();
    		}
    	}
    	
		
		return $return;
	} //EOF getCart
	
	public static function getCartData(){
		$session = JFactory::getSession();

        $cart = null;

        /*var_dump($session->get('jlticketcenter_cart_id'));
        var_dump($session );
        die;*/

        if ($session->get('jlticketcenter_cart_id') != null){

            $db = JFactory::getDBO();
            $query = "SELECT cart.*,cart.`id` AS `cart_line_id`,e.`event_name`,e.`event_date`,v.`venue_name`
				 FROM `#__jltcenter_cart` cart
				 LEFT JOIN `#__jltcenter_events` e  ON  e.`id`=cart.`event_id`
				 LEFT JOIN `#__jltcenter_venue` v ON v.`id`=e.`venue_id`
				 WHERE cart.`uniqid`=".$session->get('jlticketcenter_cart_id');

            $db->setQuery($query);

            $cart  = $db->loadObjectList();
        }
		

		

		
		return $cart;
	}
}