Advertisement
kura2yamato

contoh model

Sep 30th, 2021
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2. //hari_model
  3. class Hadir_model extends CI_Model {
  4. private $table,$table_log;
  5.     public function __construct()
  6.     {
  7.         $this->table='hadir_pamong_hari';
  8.         $this->table_log='hadir_pamong_logs';
  9.         parent::__construct();
  10.     }
  11.  
  12.     public function _get($params = array(), $limit = 30, $start = 0, $debug = false )
  13.     {
  14.         $this->db->from($this->table);
  15.         if (isset($params['blank']))
  16.         {
  17.             $this->db
  18.                 ->where('waktu_masuk is null')
  19.                 ->where('waktu_keluar is null');
  20.         }
  21.        
  22.         if (isset($params['pamong_id']))
  23.         {
  24.             $this->db->where('pamong_id', $params['pamong_id'] );
  25.         }
  26.        
  27.         if (isset($params['keluarKosong']))
  28.         {
  29.             $this->db
  30.                 ->where('waktu_keluar is null')
  31.                 ->where('tanggal <', date("Y-m-d"));;
  32.         }
  33.        
  34.         if (isset($params['tanggal']))
  35.         {
  36.             $this->db->where('tanggal', $params['tanggal']);
  37.         }
  38.        
  39.         if (isset($params['now']))
  40.         {
  41.             $this->db->where('tanggal', date("Y-m-d"));
  42.         }
  43.        
  44.         if (isset($params['pamong']))
  45.         {
  46.             $this->db->where('pamong_id', $params['pamong']);
  47.         }
  48.        
  49.         if ( isset($params['count']))
  50.         {
  51.             $this->db->select('count(*) c');
  52.             $selectTable=1;
  53.             $row= $this->db
  54.                 ->get()
  55.                 ->row_array();
  56.             return $row['c'];
  57.         }
  58.        
  59.         $this->db->limit($limit, $start);
  60.        
  61.         if ( !isset($isSorted))
  62.         {
  63.             $this->db->order_by('id', 'asc');
  64.         }
  65.        
  66.         if ( isset($params['select']))
  67.         {
  68.             $this->db->select($params['select']);
  69.             $selectTable=1;
  70.         }
  71.         if ( !isset($selectTable))
  72.         {
  73.             $this->db->select('id, pamong_id, tanggal, waktu_masuk, waktu_keluar');
  74.         }
  75.        
  76.         if ( isset($params['first']))
  77.         {
  78.             return $this->db
  79.                 ->get()
  80.                 ->row_array();
  81.         }
  82.        
  83.         return $this->db
  84.             ->get()
  85.             ->result_array();
  86.     }
  87.    
  88.     public function _count($params = array())
  89.     {
  90.         $params['count'] = 1;
  91.         return $this->_get($params);
  92.     }
  93.    
  94.     public function _update($params,$where,$cond)
  95.     {
  96.         $this->db
  97.             ->where($where, $cond)
  98.             ->update($this->table, $params);
  99.         return $this->db->last_query();
  100.     }
  101.  
  102.     public function _add($params,$ignore=0)
  103.     {
  104.         $insert_query = $this->db->insert_string($this->table, $params);
  105.         if ( $ignore)
  106.         {
  107.             $insert_query = str_replace('INSERT INTO', 'INSERT IGNORE INTO', $insert_query);
  108.         }
  109.  
  110.         $this->db->query($insert_query);
  111.         return ;
  112.     }
  113.  
  114.     public function _blank()
  115.     {
  116.         $params = ['blank' => 1];
  117.         return $this->_count($params);
  118.     }
  119.    
  120.     public function tidakKeluar()
  121.     {
  122.         $params = [
  123.             'keluarKosong'=>1,
  124.             'select'=>'id, waktu_masuk, tanggal, pamong_id'
  125.         ];
  126.         $total  = $this->_count($params);
  127.         $data   = $this->_get($params,$total);
  128.         $return = ['total'=>$total,'data'=>$data];
  129.         return $return;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement