<?php 
class assistant_model extends Model {
	function assistant_model(){
		parent::Model();
		$this->_tables['article_attach_category']	=	"article_attach_category";
		$this->_tables['ad_position']	=	"ad_position";
	}
	
	function getlist($model_value,$id){
				$this->db->where('channel_id',$id);
		return $this->db->get($model_value."_".$this->_tables['article_attach_category']);
	}
	
	function getone($model_value,$id){
		$this->db->where('article_attach_category',$id);
		return $this->db->get($model_value."_".$this->_tables['article_attach_category']);
	}
	
	function check($model_value,$data,$assistant_id=false){
		$this->db->where('channel_id',$data['channel_id']);
		$this->db->where('article_attach_name',$data['article_attach_name']);
		if($assistant_id!==false){
			$this->db->where("article_attach_category!=",$assistant_id);
		}
		return $this->db->get($model_value."_".$this->_tables['article_attach_category'])->result_array();
	}
	
	function getlist1($model_value,$id=0,$channel_id){
		$this->db->where('channel_id',$channel_id);
		if($id!==false){
			$this->db->where('article_attach_parent_id',$id);
		}
		return $this->db->get($model_value."_".$this->_tables['article_attach_category']);
	}
	
	function getassistantlist($model_value,$id=false){
				$this->db->where('channel_id',$id);
				$this->db->where('article_attach_parent_id','0');
		return $this->db->get($model_value."_".$this->_tables['article_attach_category']);
	}
	
	function add($model_value,$data){
		return $this->db->insert($model_value."_".$this->_tables['article_attach_category'],$data);
	}
	
	function delete($model_value,$id_list){
		return $this->db->delete($model_value."_".$this->_tables['article_attach_category'],$id_list);
	}
	
	function edit($model_value,$data){
		$id=$data['article_attach_category'];
		$this->db->where('article_attach_category',$id);
		return $this->db->update($model_value."_".$this->_tables['article_attach_category'], $data);
	}
	//删除频道的副分类
	function delete_channel_assistant($model_value,$channel_id){
		$sql="
			DELETE assistant,art_ass FROM ".$model_value."_article_attach_category AS assistant 
			JOIN ".$model_value."_article_attach AS art_ass ON art_ass.attach_category_id=assistant.article_attach_category 
			WHERE assistant.channel_id=$channel_id
		";
		return $this->db->query($sql);
	}
}
	
	