<?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 SpsoccerTableMatch extends FOFTable{

	public function check() {

		$result = true;

		//team One
		if (is_array($this->teamone_players))
		{
			if (!empty($this->teamone_players))
			{
				$this->teamone_players = json_encode($this->teamone_players);
			}
		}
		if (is_null($this->teamone_players) || empty($this->teamone_players))
		{
			$this->teamone_players = '';
		}

		//team two
		if (is_array($this->teamtwo_players))
		{
			if (!empty($this->teamtwo_players))
			{
				$this->teamtwo_players = json_encode($this->teamtwo_players);
			}
		}
		if (is_null($this->teamtwo_players) || empty($this->teamtwo_players))
		{
			$this->teamtwo_players = '';
		}

		return $result;
	}

	public function onAfterLoad(&$result) {

		// Team one
		if(!is_array($this->teamone_players)) {
			if(!empty($this->teamone_players)) {
				$this->teamone_players = json_decode($this->teamone_players, true);
			}
		}

		if(is_null($this->teamone_players) || empty($this->teamone_players)) {
			$this->teamone_players = array();
		}

		// Team two
		if(!is_array($this->teamtwo_players)) {
			if(!empty($this->teamtwo_players)) {
				$this->teamtwo_players = json_decode($this->teamtwo_players, true);
			}
		}

		if(is_null($this->teamtwo_players) || empty($this->teamtwo_players)) {
			$this->teamtwo_players = array();
		}



		return parent::onAfterLoad($result);
	}

}
