<?php

// 获取用户观看历史记录
require_once ("../user_include.inc");

ErrorLogger::doOutput("Compass...ajax_get_course_by_category.php....Start.", 0);

//获取参数
$unionId = ParamUtil::getRequestString("unionId", 0);
$page = ParamUtil::getRequestNumber("page", 0);

//检索用户是否存在
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$tmpUserMstList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMstList)) {
	responseNG("参数错误！");
}

$user = $tmpUserMstList[0];
//每页显示条数
$rowCount = 10;

$result = array();

$offset = $page * $rowCount;

//检索数据库查询观看记录
$param = array();
$param['user_id'] = $user->id;
$param['delete_flg'] = false;
$tmpUserMediaList = UserMediadat::getList($param,'registration_date','desc', $offset, $rowCount);
$allCount = UserMediadat::getListCount($param);

$userMediaList = array();
if(!empty($tmpUserMediaList)) {
	foreach($tmpUserMediaList as $tmpUserMediaDat) {
		$tmpMediaDat = CourseMediaDat::getById($tmpUserMediaDat->media_id);
		if(!empty($tmpMediaDat)) {
			$tmp = Array("courseId"=>$tmpMediaDat->course_id,"mediaId"=>$tmpMediaDat->id,"title"=>$tmpMediaDat->title, "media"=>$tmpMediaDat->media);
			$userMediaList[] = $tmp;
		}
	}
}

//接口返回数据
$result["allCount"] = $allCount;
$result["page"] = $page;
$result["rowCount"] = $rowCount;
$result["list"] = $userMediaList;


ErrorLogger::doOutput("Compass...ajax_get_course_by_category.php....End.", 0);


//返回结果
responseOK($result);

function responseNG($result) {
	$result = array("status"=>"NG", "result"=>$result);
	print json_encode($result);
	exit;
}
function responseOK($result) {
	$result = array("status"=>"OK", "result"=>$result);
	print json_encode($result);
	exit;
}
?>