<?php
/**
* @version 1.0.0
* @package RSEvents! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

defined( '_JEXEC' ) or die( 'Restricted access' ); 

class modRseventsCategHelper
{

	/**
	 * Method to get the events
	 *
	 * @access public
	 * @return array
	 */
	function getList(&$params)
	{
		global $mainframe;

		$db			=& JFactory::getDBO();
		
		$where = "";
		
		$categoryId = $params->get('catid');
		$limit		 = (int)$params->get('evnumber');
		if($limit == 0) $limit= 1000000;		

		$where .= " AND c.IdCategory = ".$categoryId;
		$where .= " AND e.published = 1 AND e.EventType = 1 ";
		
		
		$query="SELECT e.IdEvent , e.EventName , l.IdLocation , l.LocationName FROM #__rsevents_events e "
				." LEFT JOIN #__rsevents_locations l ON e.IdLocation=l.IdLocation LEFT JOIN #__rsevents_events_cat ec ON ec.IdEvent = e.IdEvent LEFT JOIN #__rsevents_categories c ON c.IdCategory = ec.IdCategory WHERE 1=1 ".$where." GROUP BY e.IdEvent ORDER BY e.EventStartDate ASC LIMIT ".$limit;
				
		$db->setQuery($query);
		$rows = $db->loadObjectList();
		
		$i		= 0;
		$lists	= array();
		if(!empty($rows))
		foreach ( $rows as $row )
		{
			$row->EventName = htmlspecialchars( $row->EventName, ENT_COMPAT, 'UTF-8');

			$lists[$i]->eventlink		= html_entity_decode(JRoute::_('index.php?option=com_rsevents&view=events&layout=show&cid='.$row->IdEvent));
			$lists[$i]->eventname		= $row->EventName;
			$lists[$i]->locationname	= htmlspecialchars( $row->LocationName, ENT_COMPAT, 'UTF-8' );
			$lists[$i]->locationlink 	= html_entity_decode(JRoute::_('index.php?option=com_rsevents&view=locations&layout=show&cid='.$row->IdLocation));
			$i++;
		}
		

		return $lists;
		
		
	}
}