<?php
defined('PP_PATH') or exit;
class cms_faq extends model {
	function __construct() {
		$this->table = 'cms_faq';
		$this->pri = array('id');	// 主键
		$this->maxid = 'id';		// 自增字段
	}
	function __get($var) {
		if($var == 'cfg') {
			return $this->cfg = $this->runtime->xget();
		}else{
			return parent::__get($var);
		}
	}
	public function format(&$v, $dateformat = 'Y-m-d'){
		if(empty($v)) return FALSE;
	
		$v['date'] 		= date($dateformat, $v['dateline']);
		$v['lastdate'] 		= date($dateformat, $v['lasttime']);
		$v['url'] 		= $this->cfg['webdir'].'index.php?u=faq--pid-'.$v['pid'].'-id-'.$v['id'];

	}
	public function xdelete($table, $pid, $fid) {
		$this->cms_content->table = 'cms_'.$table;
		
		$this->cms_content_data->table = 'cms_faq_data';

		$data = $this->cms_content->read($pid);
		if(empty($data)) return '读取内容表出错！';
		if($data['faqs'] > 0) {
			$data['faqs']--;
			if(!$this->cms_content->update($data)) return '更新faq数量出错！';
		}
		$this->cms_content_data->delete($fid);
		return $this->delete($fid) ? '' : '删除失败！';
	}
}