<?php
include_once '../../fly2/fly3.php';
include_once 'config.php';
include_once 'http_utils.php';


class CmsQuery {
	var
		$apipath = "http://sqa.moddev.kr:18888/new/hq/api/metacms/";
		
	function getProgramsByTags($tags)
	{
		$s = httpGetCacheable($this->apipath."program/fetch", array(
			tag=>$tags
		), 60*5);
		$programs = json_decode($s, true);
		return $programs;
	}	
	function getVideos($programid)
	{
		$s = httpGetCacheable($this->apipath."video/fetch", array(
			programid=>$programid
		), 60*5);	
		$videos = json_decode($s, true);
		return $videos;
	}
	
}
$app->action('index', function (&$view) {
	$view = 'index';	
	//return array(all=>$all, hospital=>$app->getHospital());
});

$app->action('videobytag', function() {
	$a = $_REQUEST;
	$app = new CmsQuery();
	$programs = $app->getProgramsByTags($a[tags]);
	$result = array();
	foreach($programs as $p) {
		$videos = $app->getVideos($p[id]);
		foreach($videos as $v){
			array_push($result, $v);
		}
	}
	reply_json($result);
});

$app->action('videobytag-fake', function() {
	$loadingad = '[{"id":"1200319646","episodetitle":"깨우세요금연본능","url":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ea%b9%a8%ec%9a%b0%ec%84%b8%ec%9a%94%ea%b8%88%ec%97%b0%eb%b3%b8%eb%8a%a5.mp4","urlHD":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ea%b9%a8%ec%9a%b0%ec%84%b8%ec%9a%94%ea%b8%88%ec%97%b0%eb%b3%b8%eb%8a%a5.mp4","urlSD":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ea%b9%a8%ec%9a%b0%ec%84%b8%ec%9a%94%ea%b8%88%ec%97%b0%eb%b3%b8%eb%8a%a5.mp4","summary":"깨우세요금연본능","programid":"14559751","episode":null,"creationtime":"2019-09-11 10:52:30","broadcasttime":"2019-09-11 10:09:00","discount":null,"price":null,"enabled":"1","customKey1":null,"customKey2":null,"image1":null,"image2":null,"programname":"광고샘플"},{"id":"1200319648","episodetitle":"손씻기6단계수칙교육영상","url":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ec%86%90%ec%94%bb%ea%b8%b06%eb%8b%a8%ea%b3%84%ec%88%98%ec%b9%99%ea%b5%90%ec%9c%a1%ec%98%81%ec%83%81.mp4","urlHD":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ec%86%90%ec%94%bb%ea%b8%b06%eb%8b%a8%ea%b3%84%ec%88%98%ec%b9%99%ea%b5%90%ec%9c%a1%ec%98%81%ec%83%81.mp4","urlSD":"http:\/\/vod.modcdn.net\/loading_ad\/VOD%eb%a1%9c%eb%94%a9%ea%b4%91%ea%b3%a0_%ec%86%90%ec%94%bb%ea%b8%b06%eb%8b%a8%ea%b3%84%ec%88%98%ec%b9%99%ea%b5%90%ec%9c%a1%ec%98%81%ec%83%81.mp4","summary":"손씻기6단계수칙교육영상","programid":"14559751","episode":null,"creationtime":"2019-09-11 11:01:14","broadcasttime":"2019-09-11 00:00:00","discount":null,"price":null,"enabled":"1","customKey1":null,"customKey2":null,"image1":null,"image2":null,"programname":"광고샘플"},{"id":"1202047310","episodetitle":"프로젝트402, 201910","url":"http:\/\/vod.modcdn.net\/loading_ad\/%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8402_%eb%b3%b4%ed%97%98%ec%82%ac%ea%b8%b0%eb%b0%a9%ec%a7%8020%ec%b4%88_201910.mp4","urlHD":"http:\/\/vod.modcdn.net\/loading_ad\/%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8402_%eb%b3%b4%ed%97%98%ec%82%ac%ea%b8%b0%eb%b0%a9%ec%a7%8020%ec%b4%88_201910.mp4","urlSD":"http:\/\/vod.modcdn.net\/loading_ad\/%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8402_%eb%b3%b4%ed%97%98%ec%82%ac%ea%b8%b0%eb%b0%a9%ec%a7%8020%ec%b4%88_201910.mp4","summary":"프로젝트402, 201910, 보험하기방지20초","programid":"14559751","episode":null,"creationtime":"2019-10-14 11:06:38","broadcasttime":"2019-10-14 12:10:00","discount":null,"price":null,"enabled":"1","customKey1":null,"customKey2":null,"image1":null,"image2":null,"programname":"광고샘플"}]';
	echo $loadingad;
    	return;
});

$app->action('videobytag-fast', function() {
	$a = $_REQUEST;
	$app = new CmsQuery();
	$programs = $app->getProgramsByTags($a[tags]);
	$result = array();
	foreach($programs as $p) {
		$videos = $app->getVideos($p[id]);
		foreach($videos as $v){
			array_push($result, $v);
		}
	}
	reply_json($result);
});

?>
