<?php
class AfficheModel extends DBModel {
	public $_name = VODCMS_AFFICHE;	//公告表
	public function init(){
		
	}
	public  function AddAffiche($POST){
		if ($POST['title']){
			$POST['type'] = $POST['type'];
			$POST['content'] = $POST['content'];
			$POST['title'] = $POST['title'];
			$POST['addtime'] = time();
			return $this->_DB->insert($this->_name,$POST);
		}else{
			$this->error = _('公告标题不能为空!');
			return false;
		}
	}
	/*
	获取公告所有信息
	*/
	public function getAll($where = null){
		$select = $this->_DB->select();
		$sql = $select->from($this->_name)->where($where)->order('id DESC');
		//echo $sql;
		return $this->_DB->fetAll($sql);
	}
	/*
	获取一行记录
	*/
	public function getRow($where = null){
		$select = $this->_DB->select();
		$sql = $select->from($this->_name)->where($where)->order('id DESC');
		//echo $sql;
		return $this->_DB->fetRow($sql);
	}
	/*
	修改数据
	*/
	public function modifyAffiche($POST){
		if($POST['title']){
			$array = array();
			$array['title'] = $POST['title'];
			$array['type'] = $POST['type'];
			$array['content'] = $POST['content'];
			$array['addtime'] = time();
			return $this->_DB->update($this->_name, $array, array('id'=>(int)$POST['id']));
		}else{
			$this->error = _('公告标题不能为空！');
			return false;
		}
	}
	/*
	删除一行
	*/
	public function delete($where){
		return $this->_DB->delete($this->_name, $where);
	}
	/*
	隐藏公告
	*/
	public function lockedAffiche($where){
		$sql = 'UPDATE '.$this->_name.' SET locked=not(locked) WHERE '.$where;
		//echo $sql;
		return $this->_DB->Exec($sql);
	}
	/*更新点击数*/
	public function setClick($id){
		if ($id){
			return $this->_DB->update(VODCMS_AFFICHE, 'click=click+1', 'id='.(int)$id);
		}else {
			throw new Exception('没有传入有效的参数');
		}
	}

}