<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hari_libur extends CI_Model {
	function parseOrderby($col){
		if($col==1){
			return "tanggal"; 
		}else{
			return "tanggal";
		}
	}

	function get_hari_libur_list($col=1,$asc_desc='DESC',$begin=0,$key=''){
		$orderby = $this->parseOrderby($col);
		$where = '';
		if(!empty($key)){
			$where .= ' WHERE (tanggal LIKE "%'.$key.'%" OR keterangan LIKE "%'.$key.'%") ';
		}
		try {
			return $this->db->query("SELECT SQL_CALC_FOUND_ROWS tanggal,keterangan
				FROM hari_libur ".$where." ORDER BY tanggal ".$asc_desc." LIMIT ".$begin.",50;");
		} catch (Exception $e) {
			
		}
	}

	function fecth_data_num(){
		$query = $this->db->query("SELECT FOUND_ROWS() as cnt;");
		if($query->num_rows>0){
			foreach ($query->result() as $row) {
				return $row->cnt;
			}
    		return $query->num_rows;
    	}else{
    		return 0;
    	}
	}


	function get_hari_libur_info($tgl){
		if(empty($tgl)){
			return "";
		}
		try {
			$this->db->where('tanggal',$tgl);
			return $this->db->get('hari_libur');
		} catch (Exception $e) {
			return '';
		}
	}
}
?>