<?php

class Chinese_history_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->INFO = $this->load->database('INFO', TRUE);
    }

    /**
     * [LOG_Action]
     * 1; // 进了封面的图片进入测试
     * 2; // 完成了前3题
     * 3; // 完成了10题拿到成绩单
     * 4; // 点击了try again
     */

    function get_log($log_action = '0',$start_date = null,$end_date = null,$order_field = null)
    {
        $sql = "SELECT COUNT(1) ret,LOG_Action FROM ChineseHistoryLog WHERE 1=1 ";
        if ($log_action != '0') {
            $sql .= " AND LOG_Action=" . $this->INFO->escape($log_action);
        }
        if ($start_date !== null) {
            $sql .= " AND Created_On BETWEEN " . $this->INFO->escape($start_date) ." AND ". $this->INFO->escape($end_date);
        }
        if ($order_field !== null) {
            $sql .= $order_field;
        }
        $sql .= " GROUP BY LOG_Action ";
        $query = $this->INFO->query($sql);
        return $query->result();
    }

}
