<?php
class ArticleModel extends CmlModel {
	//保存文章
	public function addarticle($gcmsclass,$gcmsclassseo,$gcmstitle,$gcmstags,$gcmsdesc,$gcmscontent,$gcmspic,$gcmsauthor,$gcmstime,$status){
		$articleok=$this->db()->set('article', array('gcmsclass'=>$gcmsclass,'gcmsclassseo'=>$gcmsclassseo,'gcmstitle'=>$gcmstitle,'gcmstags'=>$gcmstags,'gcmsdesc'=>$gcmsdesc,'gcmscontent'=>$gcmscontent,'gcmspic'=>$gcmspic,'gcmsauthor'=>$gcmsauthor,'gcmstime'=>$gcmstime,'status'=>$status),true);
		$this->cache()->truncate();
		return $articleok;
	}
	//保存编辑文章
	public function editarticlesave($id,$gcmsclass,$gcmsclassseo,$gcmstitle,$gcmstags,$gcmsdesc,$gcmscontent,$gcmspic,$gcmsauthor,$status){
		$articleok=$this->db()->update('article-id-'.$id, array('gcmsclass'=>$gcmsclass,'gcmsclassseo'=>$gcmsclassseo,'gcmstitle'=>$gcmstitle,'gcmstags'=>$gcmstags,'gcmsdesc'=>$gcmsdesc,'gcmscontent'=>$gcmscontent,'gcmspic'=>$gcmspic,'gcmsauthor'=>$gcmsauthor,'status'=>$status),true);
		$this->cache()->truncate();
		return $articleok;
	}
	//按ID删除文章
	public function delarticle($id){
		$articleok=$this->db()->delete('article-id-'.$id);
		$this->cache()->truncate();
		return $articleok;
	}
	//按ID显示编辑文章
	public function editarticle($id){
		$articledata=$this->db()->get('article-id-'.$id);
		return $articledata;
	}
	//状态修改
	public function statusarticle($id,$status){
		$articleok=$this->db()->update('article-id-'.$id, array('status'=>$status));
		$this->cache()->truncate();
		return $articleok;
	}
	//文章管理列表
	public function indexarticle($classid,$sqlfirst,$pagesize){
		if($classid){
		$articledata=$this->db()->table('article')->where('gcmsclass',$classid)->columns($columns = array('id','gcmsclass','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
			}else{
			$articledata=$this->db()->table('article')->columns($columns = array('id','gcmsclass','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
			}
		return $articledata;
	}
	//取得文章总数，ID不为空则取该分类文章总数
	public function countarticle($classid){
		if($classid){
		$countdata=$this->db()->table('article')->where('gcmsclass',$classid)->count();
			}else{
		$countdata=$this->db()->table('article')->count();
			}
		return $countdata;
	}
	
	public function articleqq($gcmstitle){
		$articleok=$this->db()->get('article-gcmstitle-'.$gcmstitle);
		return $articleok;
	}
	
}