<?php 
class activityApiControl extends skymvc{
	public $userid;
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("activity","activity_topic","activity_user","user","login"));
		$this->userid=$this->login->userid;
	}
	
	public function Top($limit=10){
		$data=$this->activity->select(array("where"=>" status=2 ","limit"=>10,"order"=>"topic_num DESC"));
	}
	
	public function topicList($option=array()){
		
		$data=$this->activity_topic->select($option);
		foreach($data as $k=>$v){
			$u=$this->user->selectRow(array("where"=>" userid=".$v['userid'],"fields"=>"nickname,user_head"));
			$v['user_head']=$u['user_head'];
			$v['nickname']=$u['nickname'];
			$data[$k]=$v;
		}
		return $data;
	}
	
	public function getTopicByid($act_id,$type=1,$limit=10){
		switch($type){
			case 2://最热门的
				$where=" act_id=".$act_id."  ";
				$order=" id DESC";
				
			default://最新的 1
				$where=" act_id=".$act_id."   ";
				$order=" id DESC";
		}
		if(ACTIVITY_TOPIC_STATUS_CHECK){
				$where.=" AND status=2 ";
		}
		$option=array(
			"where"=>$where,
			"limit"=>$limit,
			"order"=>$order
		);
		return $this->topiclist($option);
	}
	
	public function activity_role($id,$userid=0){
		$userid=$userid?$userid:$this->userid;
		return $this->activity_user->selectRow(array("where"=>"userid=".$userid." AND act_id=".$id." "));
	}
	
	public function checkRole($id,$type=1){
		$data=$this->activity_user->selectRow(array("where"=>"userid=".$this->userid." AND act_id=".$id." AND status=2 "));
		if(!$data){
			if(get('ajax')){
				exit(json_encode(array("error"=>1,"你还未加入成功")));
			}else{
				$this->gomsg("你还未加入成功");
			}
		}
		
		if($data['user_group']==1 && $type==2){
			if(get('ajax')){
				exit(json_encode(array("error"=>1,"你没有管理权限")));
			}else{
				$this->gomsg("你没有管理权限");
			}
		}
		
	}
		
}

?>