<?php
/**
 * 五十九秒网络购物cms 等级实体类
 * ============================================================================
 * 版权所有 2009-2012 五十九秒网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.59miao.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: longzhang
 * 
*/
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
class LevelModel extends Model {
	public function __construct() {
		parent::__construct();
		$this->_fields = array('id','level_name','info');
		$this->_tables = array(DB_FREFIX.'level');
		$this->_check = new LevelCheck();		
		list(
				$this->_R['id'],
				$this->_R['post_id'],			
				$this->_R['level_name']
		) = $this->getRequest()->getParam(array(
				isset($_GET['id']) ? $_GET['id'] : null,
				isset($_POST['id']) ? $_POST['id'] : null,					
				isset($_POST['level_name']) ? $_POST['level_name'] : null
		));
	}
	//获取所有等级显示等级列表
	public function findAll() {
		return parent::select(array('id','level_name','info'),array('limit'=>$this->_limit));
	}
	//获取所有等级不带limit
	public function findNoLimitAll(){
		return parent::select(array('id','level_name','info'));
	}
	
	//获取总记录
	public function total(){
		return parent::total();
	}
	//获取一条数据
	public function findOne() {
		$_where = array("id='{$this->_R['id']}'");
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
		return parent::select(array('id','level_name','info'),
											array('where'=>$_where, 'limit'=>'1'));
	}
	
	//增加等级
	public function add(){		
		$_where = array("level_name='{$this->_R['level_name']}'");		
		if (!$this->_check->addCheck($this, $_where)) $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['post_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);		
	}
}
?>