Advertisement
kura2yamato

model valas_get_data

Feb 23rd, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1.     function valas_get_data($filter = array(), $limit = 10, $start = 0, $count = FALSE, $debug = FALSE) {
  2.         $head_table = 'main';
  3.         $this->db_main->reset_query();
  4.         $this->db_main->from($this->tables_realname[$head_table]." i");
  5.         //category
  6.         $this->db_main->join($this->tables_realname['category']." c","i.item_cat=c.cat_code","left");
  7.         $this->db_main->like("i.item_cat","cur");
  8.        
  9.  
  10.         if (isset($filter['get_all'])) {
  11.             $this->db_main->where($filter['get_all'][0], $filter['get_all'][1]);
  12.         }
  13.  
  14.         if (isset($filter['where_field'])) {
  15.             $this->db_main->where($filter['where_field']);
  16.         }
  17.         if (isset($filter['where_like_field'])) {
  18.             $this->db_main->like($filter['where_like_field']);
  19.         }
  20.  
  21.         if (!isset($filter['show_all'])) {
  22.             $this->db_main->where('i.deleted', 0);
  23.         }
  24. //if (!isset($filter['show_all'])) {
  25.  
  26. //============DATATABLE
  27.         if (isset($filter['datatable_search'])){
  28.             $this->db_main
  29.                 ->group_start()
  30.                 ->or_like('item_code',$filter['datatable_search'])
  31.                 ->or_like('item_title',$filter['datatable_search'])
  32.                 ->group_end();
  33.         }
  34.         //==============COUNT=============
  35.         if ($count) {
  36.             $this->db_main->select("count({$this->tables_id[$head_table]}) c");
  37.             $data = $this->db_fetch(TRUE);
  38.             return $data['c'];
  39.         }
  40.  
  41.         //==================SHOW==========    
  42.         if (isset($filter['show_fields'])) {
  43.             $this->db_main->select($filter['show_fields']);
  44.         }
  45.         //================order by=== kondisikan
  46.         if (!isset($filter['order_by'])) {
  47.             $this->db_main->order_by('kode', 'asc');
  48.         } else {
  49.             $this->db_main->order_by($filter['order_by'][0], $filter['order_by'][1]);
  50.         }
  51.  
  52.         $this->db_main->limit($limit, $start);
  53.  
  54.         $data = $this->db_fetch();
  55.         if ($debug) {
  56.             $sql = $this->db_main->last_query();
  57.             return array('data' => $data, 'sql' => $sql, 'filter' => $filter);
  58.         } else {
  59.             return $data;
  60.         }
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement