<?php
/**
 * @package     SP Soccer
 * @author      JoomShaper http://www.joomshaper.com
 * @copyright   Copyright (C) 2010 - 2016 JoomShaper. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

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

class SpsoccerViewMatches extends FOFViewForm{

	public function display($tpl = null){
		// Get model
		$model = $this->getModel();
		$this->items = $model->getItemList();

		$tournament_model 	= FOFModel::getTmpInstance('Tournaments', 'SpsoccerModel');
		$match_model 		= FOFModel::getTmpInstance('Matches', 'SpsoccerModel');

		foreach ($this->items as $this->item) {
			$this->item->team1_info = $tournament_model->getTeamInfoById($this->item->teamone);
			$this->item->team2_info = $tournament_model->getTeamInfoById($this->item->teamtwo);
			$this->item->team1_info->logo = SpsoccerHelper::hasImg($this->item->team1_info->logo);
			$this->item->team2_info->logo = SpsoccerHelper::hasImg($this->item->team2_info->logo);
			// URL Generate
			$this->item->url 		= JRoute::_('index.php?option=com_spsoccer&view=match&id=' . $this->item->spsoccer_match_id . ':' . $this->item->slug . SpsoccerHelper::getItemid('matches'));
			//Match Date
			$this->item->match_date = JHtml::date($this->item->date, 'd M, Y');
			//Match Month
			$this->item->match_time = date ('h:i A',strtotime($this->item->time));
			//Match Location
			$this->item->match_location 	= $tournament_model->getVanueInfoById($this->item->spsoccer_vanue_id);
			//Tournament Name
			$this->item->tournament 		= $match_model->getTournamentInfo($this->item->spsoccer_tournament_id);
			//$this->item->session 			= $tournament_model->getVanueInfoById($this->item->spsoccer_session_id);
			$this->item->location_url = JRoute::_('index.php?option=com_spsoccer&view=vanue&id=' . $this->item->spsoccer_vanue_id . ':' . $this->item->match_location->slug . SpsoccerHelper::getItemid('vanues'));
		}

		return parent::display($tpl = null);
	}


}
