<?php
class commentapiControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("user","comment","product"));
	}
	
	public function product($object_id,$option=array(),$rscount=false,$cache=0,$expire=60){
		if($option['where']){
			$option['where']= " object_id=$object_id AND type_id=".PRODUCT_TYPE_ID." AND ".$option['where'];
		}else{
			$option['where']= " object_id=$object_id AND type_id=".PRODUCT_TYPE_ID." ";
		}
		if(!isset($option['limit'])){
			$option['limit']=10;	
		}
		if(!isset($option['order'])){
			$option['order']=" id DESC";
		}
		$data=$this->comment->setTable("comment",$object_id)->select($option,$rscount,$cache,$expire);
		if($data){
			foreach($data as $k=>$v){
				$uids[]=$v['userid'];
			}
			if($uids){
				$us=$this->user->getUserByIds($uids);
				foreach($data as $k=>$v){
					$v['nickname']=$us[$v['userid']]['nickname'];	
					$v['user_head']=$us[$v['userid']]['user_head'];
					$data[$k]=$v;	
				}
			}
		}
		
		return $data;
	}
	
}

?>