<?php
class KeywordModel extends DBModel{
	public function Init(){
		
	}
	public function Add($POST){
		if (!$POST['keyword']){
			$this->error = _('请填写关键词!');
			return false;
		}
		$POST['addtime'] = time();
		if ($this->getrow(array('keyword'=> $POST['keyword']))){
			$this->error = _('您填写的关键词['.$POST['keyword'].']已经存在!');
			return false;
		}
		return $this->_DB->insert(VODCMS_KEYWORD, $POST);
	}
	public function Modify($POST){
		if (!$POST['keyword']){
			$this->error = _('请填写关键词!');
			return false;
		}
		return $this->_DB->update(VODCMS_KEYWORD, $POST, array('id'=>$POST['id']));
	}
	public function getAll($where=null, $limit=0){
		$select = $this->_DB->select();
		$link = INSTALLDIR.'content/search/type/title/keyword/';
		$select->from(VODCMS_KEYWORD, '*, CONCAT("'.$link.'", `keyword`, "/") as link');
		$select->where($where);
		$select->order('click DESC');
		if (!$limit){
			$sql = $select->toString();
			//echo $sql;
			$total = $this->_DB->getCount($sql);
			$this->_Page->set($total);
			$this->PrintPage = $this->_Page->PrintPage();
			return $this->_DB->fetAll($sql.$this->_Page->limit());
		}else{
			$select->limit($limit);
			$sql = $select->toString();
			return $this->_DB->fetAll($sql);
		}
	}
	public function delete($id){
		if (is_array($id)){
			$id = implode(',', array_map('intval', $id));
		}else{
			$id = intval($id);
		}
		return $this->_DB->delete(VODCMS_KEYWORD, 'id in ('.$id.')');
	}
	public function getRow($where=null){
		$select = $this->_DB->select();
		$select->from(VODCMS_KEYWORD)->where($where);
		$sql = $select->toString();
		return $this->_DB->fetRow($sql);
	}
}?>