<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &考试成绩基类文件& BY CC
 */

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

class tj_result extends tj_model {

	var $table = 'dbpre_result';
    var $key = 'rid';
	var $sysnote;//系统日志表
	var $user;//当前操作用户

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

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

	function init_field() {
		$this->add_field('rid,uid,examid,sid,mark,is_sms');
		$this->add_field_fun('rid,uid,examid,sid,is_sms', 'intval');
	}

	function read_all($type=null) {
        $this->db->from($this->table);
		if($type) $this->db->where('examid', $type);
        $this->db->select('rid,uid,examid,sid,mark,is_sms');
        return $this->db->fetch_all_assoc();
    }
	
	function read_one_rid($rid) {
        $this->db->from($this->table);
        $this->db->where('rid', $rid);
        $this->db->select('rid,uid,examid,sid,mark,is_sms');
        return $this->db->once_fetch_assoc();
    }
	
	function get_mark($uid,$examid,$sid) {
        $mark = $this->read_one($uid,$examid,$sid);
		
        return $mark['mark'];
    }
	
	function read_one($uid,$examid,$sid) {
        $this->db->from($this->table);
        $this->db->where('uid', $uid);
		$this->db->where('examid', $examid);
		$this->db->where('sid', $sid);
        $this->db->select('rid,uid,examid,sid,mark,is_sms');
        return $this->db->once_fetch_assoc();
    }
	
    function save(& $post, $rid=NULL, $cache=TRUE) {
        $this->check_post($post);
		
        if(!$rid) {

        }
        return parent::save($post, $rid, $cache, FALSE);
    }
	
	 //更新发送短信参数
    function update_is_sms($rid,$is_sms=0) {
        $this->db->from($this->table);
        $this->db->where('rid',$rid);
        $this->db->set('is_sms',$is_sms);
        $this->db->update();
    }

    function check_post($post,$is_edit=false) {
        if(!$post['uid']) Note('学生id不存在！');
		if(!$post['examid']) Note('所属考试不能为空！');
		if(!$post['sid']) Note('科目不能为空！');
		if(!is_numeric($post['mark'])) Note('分数必须为数字！');
    }
}
?>