<?php
class sblog_peopleControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	public function onDefault(){
		
		$this->smarty->display("sblog_people/index.html");
	}
	public function onList(){
		$userid=M("login")->userid;
		$order=" followed_num DESC,userid DESC";
		$start=get("per_page","i");
		$limit=12;
		$rscount=true;
		$type=get("type","h");
		switch($type){
			case "recommend":
				$where="status=1";
				break;
			case "Vip":
				$where="status=1 AND followed_num>3 ";
				break;
			case "new":
				$where="status in(0,1) ";
				$order="userid DESC";
				break;
			default:
				$where="status in(0,1)  ";
				$order="userid ASC";
				break;
		}
		$keyword=get('keyword',"h");
		if($keyword){
			$where.=" AND nickname like '%".$keyword."%' ";
		}
		$list=M("user")->Dselect(array(
			"where"=>$where,
			"limit"=>$limit,
			"start"=>$start,
			"fields"=>"userid,nickname,follow_num,followed_num,user_head,description",
			"order"=>$order
		),$rscount);
		if($list){
			$uids=array();
			foreach($list as $v){
				$uids[]=$v["userid"];
			}
			$fuids=M("follow")->selectCols(array(
				"fields"=>"t_userid",
				"where"=>" userid=".$userid." AND t_userid in("._implode($uids).")"
			));
			foreach($list as $k=>$v){
				if($fuids && in_array($v['userid'],$fuids)){
					$isfollow=1;
				}else{
					$isfollow=0;
				}
				$v["isfollow"]=$isfollow;
				$list[$k]=$v;
			}
		} 
		$per_page=$start+$limit;
		$per_page=$per_page<$rscount?$per_page:0;
		$this->smarty->goAssign(array(
			"list"=>$list,
			"per_page"=>$per_page
		));
		 
	}
}