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

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

class SpsoccerTableGameteam extends FOFTable{

	public function check() {

		$result = true;

		if (is_array($this->team_gallery)){
			if (!empty($this->team_gallery)){
				$this->team_gallery = json_encode($this->team_gallery);
			}
		}
		if (is_null($this->team_gallery) || empty($this->team_gallery)){
			$this->team_gallery = '';
		}

		return $result;
	}

	public function onAfterLoad(&$result) {

		// has team_gallery
		if(!is_array($this->team_gallery) && !empty($this->team_gallery) ) {
				$this->team_gallery =  json_decode($this->team_gallery, true);

				if (isset($this->team_gallery['gallery_images']) && $this->team_gallery['gallery_images']) {
					$team_gallery 		= array();
					$photos 			= $this->team_gallery['gallery_images'];
					if (isset($this->team_gallery['alt_text'])) {
						$alt_texts 			= $this->team_gallery['alt_text'];
					}
					
					$glkey 	= 1;
					foreach ($photos as $id => $photo) {
						if ($photo) {
							$team_gallery[$glkey] = array(
								'image' => $photo,
							);
							$glkey ++;
						}
					}
					$this->team_gallery = $team_gallery;
				} // if old repeatable field

		}



		return parent::onAfterLoad($result);
	}
}
