Location: PHPKode > projects > blog > blog/blog.php
<?php
/**
 *
 * @filesource
 * @copyright		Copyright 2008-2009, lesorb, Inc.
 * @link			http://www.lesorb.cn Blog Project
 * @package			app
 * @subpackage		app.models
 * @version			$Revision: 7296 $
 * @author			WangLiJun
 * @lastmodified	$2009-5-5$
 */
/**
 * Blog 模型类
 *
 * 商户博客(日志)模型类,主要用于 blogs table 操作
 */
class Blog extends AppModel {

/**
 * 模型名:Blog
 *
 * @var string
 * @access public
 */
	var $name = 'Blog';

/**
 * 使用的数据表:blogs
 *
 * @var string
 * @access public
 */
	var $useTable = 'blogs';

/**
 * Blog 模型 belongsTo 关联表
 *
 * The Associations below have been created with all possible keys, those that are not needed can be removed
 *
 * @var array
 * @access public
 */
	var $belongsTo = array(			
			'Blogclass' => array('className' => 'BlogClass',
								'foreignKey' => 'blogclass_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			),
	);

/**
 * Blog 模型验证规则
 *
 * @var array
 * @access public
 */
	var $validate = array(
		'title'=>array(
			'notEmpty' => array(
				'rule' => VALID_NOT_EMPTY,
				'message' =>'请您输入标题'
				),
			'notBlank' => array(
				'rule' => '/[^\\s]/',
				'message' => '请您输入标题'
				)
			),
		'description'=>array(
			'notEmpty' => array(
				'rule' => VALID_NOT_EMPTY,
				'message' =>'请您输入内容'
				),
			'notBlank' => array(
				'rule' => '/[^\\s]/',
				'message' => '请您输入内容'
				)
			)
	);

	var $actsAs = array(		
		'feed'	=> array('type'=>array(
					'data_type'=>'12_add',
					'link'=>'/BlogReplies/view/',
					'actor'=>'发表了日志',
					'icon' => 'com_blog'
			),
			'data' => array(	
				 'title' => 'title'
				, 'description' => 'description')
			)
	);
	/**
	 *
	 * Blog 模型相应的 table 字段增加或相减对应值
	 *
	 * @method	根据blog_id给相应的blog字段增加或相减对应值
	 *
	 * @name	plusBlogSomeFields
	 * @Param	integer id:blog_id
	 * 			integer someFields:one filed'name of blog
	 * 			boolean	plBoolean ture is plus ,false is lessen 
	 * 			integer nums is amount of plus or lessen,default 1
	 * @Return	boolean
	 */
	function plusBlogSomeFields($id=0,$someFields=null,$plBoolean=true,$nums=1) {

		$prefix = $this->tablePrefix;
		$fieldArr = array('view_count','replay_count');

		if($this->checkBlogId($id)){

			if(in_array($someFields,$fieldArr)){

				if($plBoolean){
					$query = "update {$prefix}blogs Blog set Blog.{$someFields}=Blog.{$someFields}+{$nums} where Blog.id={$id}";							
				}else{
					$query = "update {$prefix}blogs Blog set Blog.{$someFields}=Blog.{$someFields}-{$nums} where Blog.id={$id}";
				}

				$this->query($query);

				return true;
			}

			return false;
		}

		return false;
	}
	/**
	 *
	 * Blog 模型相应的 id 日志存在否
	 *
	 *@Param	integer	id
	 *@Return	boolean
	 */
	function checkBlogId($id){
		return $this->hasAny(array('Blog.id' => $id));
	}

}
?>
Return current item: blog