<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &讨论区基类文件&
 */

if (!defined('IS_RUN')) die('Forbidden');

class tj_group_cate extends tj_model {

	var $table = 'dbpre_group_cates';
    var $key = 'cateid';

	function __construct() {
		parent::__construct();
		$this->init_field();
	}

    function msm_groupouncement() {
        $this->__construct();
    }

	function init_field() {
		$this->add_field('cateid,bid,listorder,catename,count_group,uptime');
		$this->add_field_fun('cateid,bid,listorder,count_group', 'intval');
        $this->add_field_fun('catename', '_T');
	}

	function read_all($type=null) {
        $this->db->from($this->table);
		if($type) {
            $this->db->where('bid', $type);
        }
		$this->db->order_by('listorder');
        return $this->db->fetch_all_assoc();
    }
	
	function read_one($cateid) {
        $this->db->from($this->table);
        $this->db->where('cateid', $cateid);
       
        return $this->db->once_fetch_assoc();
    }
	
	
	
    function save(& $post, $cateid=NULL, $cache=TRUE) {
        $this->check_post($post);
		
        if(!$cateid) {
			global $_CO;
			$post['bid'] = $_CO['userbid'];
            $post['uptime'] = $this->global['timestamp'];
        }
        return parent::save($post, $cateid, $cache, FALSE);
    }
	
	function delgroupcate($cateid) {
		
        $this->db->where('cateid', $cateid);  
		
		$this->db->from($this->table);     

        $this->db->delete();
		
        
    }

    function check_post($post,$is_edit=false) {
        if(!$post['catename']) Note('讨论区名称不能为空！');
    }
}
?>