<?php

// 获取用户本人参加的志愿者活动列表
require_once ("../user_include.inc");

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

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

$result = array();

//参数检查
if(empty($unionId)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}



//判断用户是否存在
$param = array();
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$userList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($userList)) {
	$result["message"] = "用户不存在！";
	responseNG($result);
}

$userMst = $userList[0];

//每页显示条数
$rowCount = 10;
$offset = $page * $rowCount;
$pageCount = 0;

//查询用户参加的活动列表
$volunteerEventList = array();
$param = array();
$param['user_id'] = $userMst->id;
$param['delete_flg'] = false;
$volunteerEventMemberList = VolunteerEventMemberDat::getList($param,'id','desc', $offset, $rowCount);
$allCount = VolunteerEventMemberDat::getListCount($param);
$pageCount = ceil($allCount/$rowCount);
//组装数据
if(!empty($volunteerEventMemberList)) {
	foreach($volunteerEventMemberList as $tmp) {
		$volunteerEventDat = VolunteerEventDat::getById($tmp->volunteer_event_id);
		if(!empty($volunteerEventDat)) {
			$volunteerEventDat->status_title = EventStatus::getTitleByName($volunteerEventDat->status);
			$volunteerEventDat->scope = "校内";
			if($volunteerEventDat->include_social_user) {
				$volunteerEventDat->scope = "校内.社会人士";
			}
			$volunteerEventList[] = $volunteerEventDat;
		}
	}
}

//组装返回数据
$result["pageCount"] = $pageCount;
$result["volunteerEventList"] = $volunteerEventList;

ErrorLogger::doOutput("Compass...ajax_get_my_event_list.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;
}
?>