MGameDetails_BK.php 6.58 KB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mgamedetails extends CI_Model {
    protected $_table='game_details';

    public function __construct(){
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
    }

    public function add($dataInsert){
        $this->db->insert($this->_table, $dataInsert);
        $insert_id = $this->db->insert_id();
        return $insert_id;
    }

    public function update($id, $dataUpdate){
        try{
            $this->db->where('id', $id);
            $this->db->update($this->_table, $dataUpdate);
            return true;
        }catch (Exception $e){
            return false;
        }
    }

    public function getById($id){
        $this->db->select($this->_table.'.*');
        $this->db->from($this->_table);
        $this->db->where($this->_table.'.id', $id);
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getListForSelectBox(){
        $this->db->select('id, fullname, username, sid');
        $this->db->from($this->_table);
        $this->db->where('sid !=', '');
        $this->db->order_by($this->_table.'.username', 'asc');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function cmsCountAll($name=null){
        $this->db->select('COUNT(*) AS totalResults');
        $this->db->from($this->_table);
        if($name != null){
            $this->db->like('fullname', $name, 'both');
            $this->db->or_like('username', $name, 'both');
            $this->db->or_like('address', $name, 'both');
            $this->db->or_like('email', $name, 'both');
            $this->db->or_like('mobile', $name, 'both');
            $this->db->or_like('reward_code', $name, 'both');
        }
        $query = $this->db->get();
        $result = $query->result_array();
        if($result){
            return $result[0]['totalResults'];
        }else{
            return 0;
        }
    }

    public function cmsGetPagination($record, $start, $name=null){
        $this->db->select($this->_table.'.*');
        $this->db->from($this->_table);
        if($name != null){
            $this->db->like($this->_table.'.fullname', $name, 'both');
            $this->db->or_like('username', $name, 'both');
            $this->db->or_like('address', $name, 'both');
            $this->db->or_like('email', $name, 'both');
            $this->db->or_like('mobile', $name, 'both');
            $this->db->or_like('reward_code', $name, 'both');
        }
        $this->db->order_by($this->_table.'.created_at', 'desc');
        $this->db->limit($record, $start);
        $query = $this->db->get();
        return $query->result_array();
    }

    /**
     * -----------------------------------------------------------------------------------------------------------------
     * Thống kê danh sách các lần chơi: Tài khoản, Số điểm, thời gian hoàn thành, thời gian chơi
     * @param null $name
     * @return int
     */
    public function cmsCountAll2($name=null){
        $this->db->select('COUNT(*) AS totalResults');
        $this->db->from($this->_table.' gd');
        $this->db->join('user u', 'u.id = gd.user_id');
        if($name != null){
            $this->db->like('u.fullname', $name, 'both');
            $this->db->or_like('u.username', $name, 'both');
            $this->db->or_like('u.address', $name, 'both');
            $this->db->or_like('u.email', $name, 'both');
            $this->db->or_like('u.mobile', $name, 'both');
            $this->db->or_like('u.reward_code', $name, 'both');
        }
        $query = $this->db->get();
        $result = $query->result_array();
        if($result){
            return $result[0]['totalResults'];
        }else{
            return 0;
        }
    }

    public function cmsGetPagination2($record, $start, $name=null){
        $this->db->select('gd.*, u.fullname, u.username');
        $this->db->from($this->_table.' gd');
        $this->db->join('user u', 'u.id = gd.user_id', 'left');
        if($name != null){
            $this->db->like('u.fullname', $name, 'both');
            $this->db->or_like('u.username', $name, 'both');
            $this->db->or_like('u.address', $name, 'both');
            $this->db->or_like('u.email', $name, 'both');
            $this->db->or_like('u.mobile', $name, 'both');
            $this->db->or_like('u.reward_code', $name, 'both');
        }
        $this->db->order_by('gd.created_at', 'desc');
        $this->db->limit($record, $start);
        $query = $this->db->get();
        return $query->result_array();
    }

    /**
     * -----------------------------------------------------------------------------------------------------------------
     * Thống kê danh sách top: sắp xếp theo thứ tự ưu tiên thời gian hoàn thành, điểm
     * @param null $name
     * @return int
     */
    public function cmsCountAll3($name=null){
        $this->db->select('COUNT(*) AS totalResults');
        $this->db->from($this->_table.' gd');
        $this->db->join('user u', 'u.id = gd.user_id');
        if($name != null){
            $this->db->like('u.fullname', $name, 'both');
            $this->db->or_like('u.username', $name, 'both');
            $this->db->or_like('u.address', $name, 'both');
            $this->db->or_like('u.email', $name, 'both');
            $this->db->or_like('u.mobile', $name, 'both');
            $this->db->or_like('u.reward_code', $name, 'both');
        }
        $this->db->where('time >', 0);
        $query = $this->db->get();
        $result = $query->result_array();
        if($result){
            return $result[0]['totalResults'];
        }else{
            return 0;
        }
    }

    public function cmsGetPagination3($record, $start, $name=null){
        $this->db->select('gd.*, u.fullname, u.username');
        $this->db->from($this->_table.' gd');
        $this->db->join('user u', 'u.id = gd.user_id', 'left');
        if($name != null){
            $this->db->like('u.fullname', $name, 'both');
            $this->db->or_like('u.username', $name, 'both');
            $this->db->or_like('u.address', $name, 'both');
            $this->db->or_like('u.email', $name, 'both');
            $this->db->or_like('u.mobile', $name, 'both');
            $this->db->or_like('u.reward_code', $name, 'both');
        }
        $this->db->where('time >', 0);
        $this->db->order_by('gd.time asc, gd.point desc');
        $this->db->limit($record, $start);
        $query = $this->db->get();
        return $query->result_array();
    }





}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */