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

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

class SpsoccerTableVanue extends FOFTable{

	public function check() {

		$result = true;

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

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

		return $result;
	}

	public function onAfterLoad(&$result) {
		// has gallery
		if(!is_array($this->gallery) && !empty($this->gallery) ) {
				$this->gallery =  json_decode($this->gallery, true);



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

		}



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