<?php 
class nobat_model extends CI_Model {
	 public function set_nobat($data){
	$this->db->insert('modirat_nobat', $data);
 }
 public function get_nobat($uid,$date,$staus = "null",$limit = "null"){
	$this->db->where("uid",$uid);
	$this->db->where("po_date",$date);
	if($staus != "null"){
	$this->db->where("po_status",$staus);
	}
	if($limit !="null"){
		$this->db->limit($limit);
	}
	$result = $this->db->get('modirat_nobat');
    return $result->result();
}
function get_nobat_all($uid){
	 $this->db->where("uid",$uid);
	 $result = $this->db->get('modirat_nobat');
    return $result->result();
}
function is_nobat_exist($uid,$po_date){
	 $this->db->where("uid",$uid);
	 $this->db->where("po_date_ISO8601",$po_date);
	  $result = $this->db->get('modirat_nobat');
	  if(count($result->result()) == 0){
		  return false;
	  }else{
		  return true;
	  }
}
function update_nobat($id,$data){
	 $this->db->where("id",$id);
	 $this->db->update('modirat_nobat', $data);
}
function telegram_infonobatdehi_add($data){
	 $this->db->insert('telegram_info_nobatdehi', $data);
}
function telegram_infonobatdehi_get($nobatid){
	  $this->db->where("nobatid",$nobatid);
	 $result = $this->db->get('telegram_info_nobatdehi');
    return $result->result();
}
function get_nobat_lastid(){
	 $query = $this->db->query("SELECT *
  FROM modirat_nobat
 ORDER
    BY Id DESC
 LIMIT 1");
$query = $query->result();
return $query[0]->id;
}
function get_nobat_byorder($uid,$day){
	  $this->db->where("uid",$uid);
	 $this->db->where("po_date",$day);
	  $this->db->where("po_status",2);
	 $this->db->order_by('po_date_ISO8601','ASC');
	 $result = $this->db->get('modirat_nobat');
    return $result->result();
}
function get_nobat_bytime($uid,$stime,$endtime){
	  $this->db->where("uid",$uid);
	 $this->db->where('po_date >=', $stime);
	 $this->db->where('po_date <=', $endtime);
	 $this->db->where("visit_status",3);
 $result = $this->db->get('modirat_nobat');
    return count($result->result());
}
function delete_nobat($id){
	  $this->db->where("id",$id);
	   $this->db->delete('modirat_nobat');
}
}
?>