<?php
/**
 * 五十九秒网络购物cms 友情链接实体类
 * ============================================================================
 * 版权所有 2009-2012 五十九秒网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.59miao.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: longzhang
 * 
*/
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
class AdModel extends Model{
	public function __construct() {
		parent::__construct();
		$this->_fields = array('id','name','adindex','url','site_logo','type','date');
		$this->_tables = array(DB_FREFIX.'ad');
		$this->_check = new AdCheck();	
		list(
				$this->_R['id']
		) = $this->getRequest()->getParam(array(
				isset($_GET['id']) ? $_GET['id'] : null				
		));
	}
	
	public function findAll() {
		return parent::select(array('id','name','adindex','url','site_logo','type'), 
											array('limit'=>$this->_limit, 'order'=>'id ASC'));
	}
	//用于新增修改	
	public function findOne() {			
			$_where = array("id='{$this->_R['id']}'");
			if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
			return parent::select(array('id','name','adindex','url','site_logo','type'),
												array('where'=>$_where, 'limit'=>'1'));
	}
	//用于获取最后一条数据
	public function findLastOne($id){
		$_where=array("id='{$id}'");
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
			return parent::select(array('id','name','adindex','url','site_logo','type'),
												array('where'=>$_where, 'limit'=>'1'));		
	}
	
	public function total() {
		return parent::total();
	}
	public function add() {		
		if (!$this->_check->addCheck($this)) $this->_check->error();
		$_addData = $this->getRequest()->add($this->_fields);	
		return parent::add($_addData);
	}
	
	public function delete() {
		$_where = array("id='{$this->_R['id']}'");
		return parent::delete($_where);
	}	
	public function update() {			
		$_where=array("id='{$this->_R['id']}'");
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
		if (!$this->_check->updateCheck($this)) $this->_check->error();
		$_updateData = $this->getRequest()->update($this->_fields);
		return parent::update($_where, $_updateData);
		
	}	
	//获取最后增长的id
	public function last_insert_id(){
		return parent::select(array('MAX( id ) AS maxid'),array('limit'=>'1'));
	}
}
?>