<?php 
namespace Common\Taglib;
class cat{
	 public function run($attr){
		$type=$attr['type'];
		$pid=$attr['pid'];
		$id=intval($attr['id']);
		$field=trim($attr['field']);
		if ($type=='question' || $type=='1'){//问题分类
			$map['c_type']=1;
		}
		if ($type=='article' || $type=='2'){//文章分类
			$map['c_type']=2;
		}
		if ($pid<>''){
			$map['c_pid']=intval($pid);
		}
		if ($id>0){
			unset($map);
			$map['c_id']=$id;
		}
		$result=M('Category')->field($field)->where($map)->order('c_sort desc , c_id asc')->select();
		//echo M('Category')->field($field)->fetchSql(true)->where($map)->order('c_sort desc , c_id asc')->select();
		$list=array();
		if (!empty($result)){
			foreach ($result as $key => $v){
				if ($v['c_pid']>0){
					$v['qurl']=RU('question/lists',array('cat'=>$v['c_pid'],'cat1'=>$v['c_id']));
					$v['aurl']=RU('article/lists',array('cat'=>$v['c_pid'],'cat1'=>$v['c_id']));
				}else{
					$v['qurl']=RU('question/lists',array('cat'=>$v['c_id']));
					$v['aurl']=RU('article/lists',array('cat'=>$v['c_id']));
				}
				$v['c_pic']=$v['c_pic']?$v['c_pic']:'null.png';
				$list[]=$v;
			}
		}
		$return['list']=$list;
		$return['count']=count($list);
		return $return;
	 }
	 
	 
}
?>