<?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
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

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

class rseventsViewEvents extends JView
{
	//Creates the Event Feed

	function display( )
	{
		global $mainframe;

		$doc 		= & JFactory::getDocument();
		$rseventsConfig = $mainframe->getUserState('rseventsConfig');

		// Get some data from the model
		JRequest::setVar('limit', $mainframe->getCfg('feed_limit'));
		$rows = & $this->get('data');

		foreach ( $rows as $row )
		{
			// strip html from feed item title
			$title = $this->escape( $row->EventName );
			$title = html_entity_decode( $title );

			// strip html from feed item category
			$category = $this->escape( $row->CategoryName );
			$category = html_entity_decode( $category );

			//Format date
			$startDate = date( $rseventsConfig['global.dateformat'], $row->EventStartDate );
			$endDate = date( $rseventsConfig['global.dateformat'], $row->EventEndDate);
			

			// url link to article
			// & used instead of &amp; as this is converted by feed creator
			$link = 'index.php?option=com_rsevents&view=events&layout=show&cid='. $row->IdEvent;
			$link = JRoute::_( $link );

			// feed item description text
			$description = JText::_( 'Title' ).': '.$title.'<br />';
			$description .= JText::_( 'Location' ).': <strong>'.$row->LocationName.'</strong> - '.$row->LocationCity.'<br />';
			$description .= JText::_( 'Categoty' ).': '.$category.'<br />';
			$description .= JText::_( 'Date' ).': '.$startDate.' - '.$endDate.'<br />';
			$description .= JText::_( 'Description' ).': '.$row->EventDescription;

			@$created =  ($row->EventCreation == 0) ? date( 'r', $row->EventStartDate) : date( 'r', $row->EventCreation) ;

			// load individual item creator class
			$item = new JFeedItem();
			$item->title 		= $title;
			$item->link 		= $link;
			$item->description 	= $description;
			$item->date			= $created;
			$item->category   	= $category;

			// loads item info into rss array
			$doc->addItem( $item );
		}
	}
}
?>