<?php
/**
* @version		3.0.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();

jimport( 'joomla.application.component.model' );

class JLTicketCenterModelVenues extends JModelLegacy
{
	
	private static $Performer_request 	= 2;
	private static $City_request 		= 4;
	private static $State_request 		= 5;
	private static $Country_request 	= 6;
	
	function getVenues(){
		$db =& JFactory::getDBO();

		$where_array = array();
		if (JRequest::getInt('city',0)>0){
			$where_array[] = "v.`city_id`=".JRequest::getInt('city',0);
		}
		elseif (JRequest::getInt('state',0)>0){
			$where_array[] = "v.`state_id`=".JRequest::getInt('state',0);
			
		}elseif (JRequest::getInt('country',0)>0){
			$where_array[] ="v.`country_id`=".JRequest::getInt('country',0);
		}
		
		
		$query = "SELECT v.*,country.`country`,state.`state_name`,city.`city_name`
				FROM `#__jltcenter_venue` v
				LEFT JOIN #__jltcenter_city city  ON city.`id`=v.`city_id`
				LEFT JOIN #__jltcenter_state state  ON state.`id`=v.`state_id`
				LEFT JOIN #__jltcenter_country country ON country.`id`=v.`country_id`
				WHERE ".implode(' AND ',$where_array)." 
				ORDER BY country.`country`,state.`state_name`,city.`city_name`,v.`venue_name`";
		
		
		$db->setQuery($query);
		//echo $db->getQuery();
		//die;
		$venues = $db->loadObjectList();
				
		
		return $venues ;
	}//EOF getVenues
	
	function getCity(){
		$db =& JFactory::getDBO();
		$query = 'SELECT city.`id`, city.`city_name`,city.`state_id`, city.`country_id`, city.`checked_out_time`, city.`ordering`,country.`country`,state.`state_name`'
			. ' FROM #__jltcenter_city city'
			. ' LEFT JOIN  #__jltcenter_country country ON country.`id`=city.`country_id`'
			.' LEFT JOIN  #__jltcenter_state state ON state.`id`=city.`state_id`'
			. " WHERE city.`id`=" .JRequest::getInt('city',0);
		
		$db->setQuery($query);
		$city = $db->loadObject();
		return $city;
	}//EOF getCity
	
	function getState(){
		$db =& JFactory::getDBO();
		$query = 'SELECT state.`id`, state.`country_id`, country.`country`,state.`state_name`'
			. ' FROM #__jltcenter_state state '
			. ' LEFT JOIN  #__jltcenter_country country ON country.`id`=state.`country_id`'
			. " WHERE state.`id`=" .JRequest::getInt('state',0);
		
		$db->setQuery($query);
		$state = $db->loadObject();
		
		return $state;
	}//EOF getState
	
	function getCountry(){
		$db =& JFactory::getDBO();
		$query = "SELECT * 
				FROM #__jltcenter_country 
				WHERE `id`=" .JRequest::getInt('country',0);
		
		$db->setQuery($query);
		
		$country = $db->loadObject();
		return $country;
	}//EOF getState
}//EOC