<?php
/**
 * 五十九秒网络购物cms 文章实体类
 * ============================================================================
 * 版权所有 2009-2012 五十九秒网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.59miao.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: longzhang
 * 
*/
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
class ArtileModel extends Model{
	public function __construct() {
		parent::__construct();		
		$this->_fields = array('id','title','keywords','info','source','ontop','hot','color','pid','content','date');
		$this->_tables = array(DB_FREFIX.'artile');
		$this->_check = new ArtileCheck();
		list(
				$this->_R['id'],				
				$this->_R['name']
		) = $this->getRequest()->getParam(array(
				isset($_GET['id']) ? $_GET['id'] : null,				
				isset($_POST['name']) ? $_POST['name'] : null
		));
	}	
	public function findAll(){
				
		$this->_tables = array(DB_FREFIX.'artile as a', DB_FREFIX.'artilenav b');
		return parent::select(array('a.id as id','a.title as title','a.keywords keywords','a.info as info','a.source as source','a.ontop as ontop','a.hot as hot','a.color as color','a.pid as pid', 'b.id as nav_pid','b.name as category'), 
											array('where'=>array('a.pid=b.id'),'limit'=>$this->_limit, 'order'=>'a.date DESC'));
	
	}	
	//显示最新更新的5条文章hot
	public function FindHot(){
		$this->_fields = array('id','title','keywords','info','source','ontop','hot','color','pid','date');
		$_where=array("hot='1'");
		return parent::select(array('id','title','color'),array('where'=>$_where,'order'=>'ontop desc'));
		
	}	
	//显示前台文章10条
	public function FindAllFrontTen($pid){
		$this->_fields = array('id','title','keywords','info','source','ontop','hot','color','pid','date');
		$_where=array("pid='{$pid}'");		
		return parent::select(array('id','title','color'),array('where'=>$_where,'limit'=>'10','order'=>'ontop desc'));
		
	}
	public function findOne() {	
		//验证是否存在这条数据		
		$_where = array("id='{$this->_R['id']}'");
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
		
		$_where = array("a.id='{$this->_R['id']}'","a.pid=b.id");
		$this->_tables = array(DB_FREFIX.'artile as a', DB_FREFIX.'artilenav b');
		return parent::select(array('a.id as id','a.title as title','a.keywords keywords','a.info as info','a.source as source','a.ontop as ontop','a.hot as hot','a.content as content','a.pid as pid', 'b.id as nav_pid'), 
											array('where'=>$_where,'limit'=>1, 'order'=>'a.date DESC'));
	}	
	public function total() {
		return parent::total();
	}	
	public function add(){		
		if (!$this->_check->addCheck($this)) $this->_check->error();
		$_addData = $this->getRequest()->add($this->_fields);
		$_addData['content']=stripslashes($_addData['content']);
		return parent::add($_addData);
	}	
	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);
		$_updateData['content']=stripslashes($_updateData['content']);		
		return parent::update($_where, $_updateData);
	}	
	public function delete(){
		$_where = array("id='{$this->_R['id']}'");
		return parent::delete($_where);
	}	
	public function isName(){
		$_where = array("name='{$this->_R['name']}'");
		$this->_check->ajax($this, $_where);
	}
}
?>