gundambison

Model (1)

May 18th, 2018
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * _POST tidak boleh digunakan di model. karena fungsinya agar dapat digunakan
  5.  * dengan parameter non POST kedepannya
  6.  * dari conctroller yang ngirim POST jgn dari model baca POST
  7.  */
  8. class User_model extends CI_Model {
  9.  
  10.     var $table = 'service'; //nama tabel dari database
  11.     var $column_order = array(
  12.         null, 'no_rangka', 'no_polisi', 'model', 'type',
  13.         'transmission', 'warna', 'tahun', 'km', 'customer',
  14.         'telephone', 'handphone', 'contact_person', 'telephone_cp', 'cabang_penjual',
  15.         'cabang_service', 'salesman', 'last_service', 'job', 'pekerjaan_utama',
  16.         'program_promo', 'status_aktif', 'hasil_fu1', 'hasil_fu2', 'hasil_fu3'
  17.     ); //field yang ada di table user
  18.     var $column_search = array(
  19.         'no_rangka', 'no_polisi', 'model', 'type', 'transmission',
  20.         'warna', 'tahun', 'km', 'customer', 'telephone',
  21.         'handphone', 'contact_person', 'telephone_cp', 'cabang_penjual', 'cabang_service',
  22.         'salesman', 'last_service', 'job', 'pekerjaan_utama', 'program_promo'
  23.         , 'status_aktif', 'hasil_fu1', 'hasil_fu2', 'hasil_fu3'
  24.     ); //field yang diizin untuk pencarian
  25.     var $order = array(
  26.         'nomor' => 'asc'
  27.     ); // default order
  28.  
  29.     public function __construct() {
  30.         parent::__construct();
  31.         $this->load->database();
  32.     }
  33.  
  34.     private function _get_datatables_query($input) {
  35.  
  36.         $this->db->from($this->table);
  37.  
  38.         $i = 0;
  39.         if (isset($input['search']['value']) && strlen($input['search']['value']) > 3) {
  40.             // if datatable send POST for search
  41.             $search = explode(" ", $input['search']['value']);
  42.             foreach ($search as $txt) {
  43.                 $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
  44.  
  45.                 foreach ($this->column_search as $item) { // loop column
  46.                     //if ($i === 0) { // first loop
  47.                     //    $this->db->like($item, $input['search']['value']);
  48.                     //} else
  49.                     {
  50.                         $this->db->or_like($item, $txt);
  51.                     }
  52.  
  53.                     //if(count($this->column_search) - 1 == $i) //last loop
  54.  
  55.                     $i++;
  56.                 }
  57.                 $this->db->group_end(); //close bracket
  58.             }
  59.         }
  60.  
  61.         if (isset($input['order'])) { // here order processing
  62.             $this->db->order_by($this->column_order[$input['order']['0']['column']], $input['order']['0']['dir']);
  63.         } else if (isset($this->order)) {
  64.             $order = $this->order;
  65.             $this->db->order_by(key($order), $order[key($order)]);
  66.         }
  67.     }
  68.  
  69.     function get_datatables($input) {
  70.         $this->_get_datatables_query($input);
  71.         if ($input['length'] != -1)
  72.             $this->db->limit($input['length'], $input['start']);
  73.         $query = $this->db->get();
  74.         $respon = array('data' => $query->result(), 'sql' => $this->db->last_query());
  75.         return $respon;
  76.     }
  77.  
  78.     function count_filtered($input) {
  79.         $this->_get_datatables_query($input);
  80.         $query = $this->db->get();
  81.         return $query->num_rows();
  82.     }
  83.  
  84.     public function count_all() {
  85.         $this->db->from($this->table);
  86.         return $this->db->count_all_results();
  87.     }
  88.  
  89. }
  90.  
  91. /***
  92. sql
  93. SELECT * FROM `service` WHERE  
  94. ( `no_rangka` LIKE '%honda%' ESCAPE '!' OR  `no_polisi` LIKE '%honda%' ESCAPE '!' OR  `model` LIKE '%honda%' ESCAPE '!' OR  `type` LIKE '%honda%' ESCAPE '!' OR  `transmission` LIKE '%honda%' ESCAPE '!' OR  `warna` LIKE '%honda%' ESCAPE '!' OR  `tahun` LIKE '%honda%' ESCAPE '!' OR  `km` LIKE '%honda%' ESCAPE '!' OR  `customer` LIKE '%honda%' ESCAPE '!' OR  `telephone` LIKE '%honda%' ESCAPE '!' OR  `handphone` LIKE '%honda%' ESCAPE '!' OR  `contact_person` LIKE '%honda%' ESCAPE '!' OR  `telephone_cp` LIKE '%honda%' ESCAPE '!' OR  `cabang_penjual` LIKE '%honda%' ESCAPE '!' OR  `cabang_service` LIKE '%honda%' ESCAPE '!' OR  `salesman` LIKE '%honda%' ESCAPE '!' OR  `last_service` LIKE '%honda%' ESCAPE '!' OR  `job` LIKE '%honda%' ESCAPE '!' OR  `pekerjaan_utama` LIKE '%honda%' ESCAPE '!' OR  `program_promo` LIKE '%honda%' ESCAPE '!' OR  `status_aktif` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu1` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu2` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu3` LIKE '%honda%' ESCAPE '!'  ) AND  
  95. ( `no_rangka` LIKE '%manual%' ESCAPE '!' OR  `no_polisi` LIKE '%manual%' ESCAPE '!' OR  `model` LIKE '%manual%' ESCAPE '!' OR  `type` LIKE '%manual%' ESCAPE '!' OR  `transmission` LIKE '%manual%' ESCAPE '!' OR  `warna` LIKE '%manual%' ESCAPE '!' OR  `tahun` LIKE '%manual%' ESCAPE '!' OR  `km` LIKE '%manual%' ESCAPE '!' OR  `customer` LIKE '%manual%' ESCAPE '!' OR  `telephone` LIKE '%manual%' ESCAPE '!' OR  `handphone` LIKE '%manual%' ESCAPE '!' OR  `contact_person` LIKE '%manual%' ESCAPE '!' OR  `telephone_cp` LIKE '%manual%' ESCAPE '!' OR  `cabang_penjual` LIKE '%manual%' ESCAPE '!' OR  `cabang_service` LIKE '%manual%' ESCAPE '!' OR  `salesman` LIKE '%manual%' ESCAPE '!' OR  `last_service` LIKE '%manual%' ESCAPE '!' OR  `job` LIKE '%manual%' ESCAPE '!' OR  `pekerjaan_utama` LIKE '%manual%' ESCAPE '!' OR  `program_promo` LIKE '%manual%' ESCAPE '!' OR  `status_aktif` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu1` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu2` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu3` LIKE '%manual%' ESCAPE '!'  )
  96. ORDER BY `nomor` ASC  LIMIT 25
  97.  
  98. {"draw":"29","recordsTotal":4,"recordsFiltered":3,"data":[[1,"ABCEGHI","BM-12","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""],[2,"ABCEGHIzzd","BM-12","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""],[3,"ABCEGHIJKL","BM-13","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""]],"sql":"SELECT * FROM `service` WHERE   ( `no_rangka` LIKE '%honda%' ESCAPE '!' OR  `no_polisi` LIKE '%honda%' ESCAPE '!' OR  `model` LIKE '%honda%' ESCAPE '!' OR  `type` LIKE '%honda%' ESCAPE '!' OR  `transmission` LIKE '%honda%' ESCAPE '!' OR  `warna` LIKE '%honda%' ESCAPE '!' OR  `tahun` LIKE '%honda%' ESCAPE '!' OR  `km` LIKE '%honda%' ESCAPE '!' OR  `customer` LIKE '%honda%' ESCAPE '!' OR  `telephone` LIKE '%honda%' ESCAPE '!' OR  `handphone` LIKE '%honda%' ESCAPE '!' OR  `contact_person` LIKE '%honda%' ESCAPE '!' OR  `telephone_cp` LIKE '%honda%' ESCAPE '!' OR  `cabang_penjual` LIKE '%honda%' ESCAPE '!' OR  `cabang_service` LIKE '%honda%' ESCAPE '!' OR  `salesman` LIKE '%honda%' ESCAPE '!' OR  `last_service` LIKE '%honda%' ESCAPE '!' OR  `job` LIKE '%honda%' ESCAPE '!' OR  `pekerjaan_utama` LIKE '%honda%' ESCAPE '!' OR  `program_promo` LIKE '%honda%' ESCAPE '!' OR  `status_aktif` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu1` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu2` LIKE '%honda%' ESCAPE '!' OR  `hasil_fu3` LIKE '%honda%' ESCAPE '!'  ) AND   ( `no_rangka` LIKE '%manual%' ESCAPE '!' OR  `no_polisi` LIKE '%manual%' ESCAPE '!' OR  `model` LIKE '%manual%' ESCAPE '!' OR  `type` LIKE '%manual%' ESCAPE '!' OR  `transmission` LIKE '%manual%' ESCAPE '!' OR  `warna` LIKE '%manual%' ESCAPE '!' OR  `tahun` LIKE '%manual%' ESCAPE '!' OR  `km` LIKE '%manual%' ESCAPE '!' OR  `customer` LIKE '%manual%' ESCAPE '!' OR  `telephone` LIKE '%manual%' ESCAPE '!' OR  `handphone` LIKE '%manual%' ESCAPE '!' OR  `contact_person` LIKE '%manual%' ESCAPE '!' OR  `telephone_cp` LIKE '%manual%' ESCAPE '!' OR  `cabang_penjual` LIKE '%manual%' ESCAPE '!' OR  `cabang_service` LIKE '%manual%' ESCAPE '!' OR  `salesman` LIKE '%manual%' ESCAPE '!' OR  `last_service` LIKE '%manual%' ESCAPE '!' OR  `job` LIKE '%manual%' ESCAPE '!' OR  `pekerjaan_utama` LIKE '%manual%' ESCAPE '!' OR  `program_promo` LIKE '%manual%' ESCAPE '!' OR  `status_aktif` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu1` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu2` LIKE '%manual%' ESCAPE '!' OR  `hasil_fu3` LIKE '%manual%' ESCAPE '!'  ) ORDER BY `nomor` ASC  LIMIT 25"}
  99. ***/
Advertisement
Add Comment
Please, Sign In to add comment