<?php

/*
 * Copyright (C) xgcms.com
 */

class tags_data extends base_model {
	
	function __construct(&$conf) {
		parent::__construct($conf);
		$this->table = 'tags_data';
		$this->primarykey = array('tid','tag_id');
	}
	public function get_list_by_tagid($tag_id,$page=1,$pagesize=20){
		$start=($page-1)*$pagesize;
		$list=$this->index_fetch(array('tag_id'=>$tag_id),array('dateline'=>-1),$start,$pagesize);
		$tids=array();
		foreach($list as $v){
			$tids[]=array($v['fid'],$v['tid']);
		}
		//$tids=array_unique($tids);
		return $list=$this->topic->mget($tids);
		
	}
	public function delete_by_tid($tid){
		$list=$this->index_fetch(array('tid'=>$tid),array(),0,100);
		foreach($list as $v){
			$this->tags->dec_topics($v['tag_id']);
			$this->delete($tid,$v['tag_id']);
		}
		
		
	}
	public function _create($arr){
		$rs=$this->read($arr['tid'],$arr['tag_id']);
		if(!$rs){
		   $this->create($arr);	
		}
	}
	
}
?>