<?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 SpsoccerViewTournaments extends FOFViewForm{

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

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

		foreach ($this->items as &$this->item) {
			$this->item->url 		= JRoute::_('index.php?option=com_spsoccer&view=tournament&id=' . $this->item->spsoccer_tournament_id . ':' . $this->item->slug . SpsoccerHelper::getItemid('tournaments'));
			$groups 	= $model->getTournamentGroups($this->item->spsoccer_tournament_id);

			$this->item->image = SpsoccerHelper::hasImg($this->item->image);

			//count tournament teams
			$this->item->teams = 0;
			foreach ($groups as &$group) {
				$this->item->teams += count($group->groups_teams_info);
			}

		}

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

}
