<?php 
namespace Common\Model;
use Think\Model;
class QuestionImgModel extends Model
{
	public function get_list($map='')
	{
		$result = $this->where($map)->order('id DESC')->select();
		foreach ($result as $key => $v){
				$v['imgurl']=$this->img_src($v['img']);
				$list[]=$v;
			}
		return $list;
	}
	public function del_img($ids='')
	{
		$ids = is_array($ids)?implode(",",$ids):$ids;
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']  = array('IN',$ids);
			$info=$this->get_list($map);
			foreach($info as $v)
			{
				$fname=C('UU_IMG_QUESTION_DIR').$v['img'];
				@unlink($fname);
			}
			$s=$this->delete($ids);
		}
		return $s;
	}
	//通过问题ID获取IMG
	public function get_img_qid($qid='')
	{
		$map['qid']=intval($qid);
		$img= $this -> where($map)->select();
		foreach($img as $v){
			$v['imgurl']=$this->img_src($v['img']);
			$v['thumb_imgurl']=$this->img_src($v['img'],true);
			$imgs[]=$v;
		}
		return $imgs;
	}
	//IMG SRC
	public function img_src($img='',$thumb=false)
	{
		if ($thumb)
		{
		$thumb=__ROOT__.'/'.C('UU_IMG_QUESTION_DIR').$img;
		$thumb=$thumb.'.thumb.'.substr(strrchr($thumb,'.'),1);
		return $thumb;
		}
		return __ROOT__.'/'.C('UU_IMG_QUESTION_DIR').$img;
	}
}
?>