belajarmasak

Modelnya...

May 16th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4.  
  5. class Mservice extends CI_Model {
  6.  
  7. var $table = 'service'; //nama tabel dari database
  8. var $column_order = array(null, 'no_rangka','no_polisi','model','type','transmission','warna','tahun','km','customer','telephone'
  9. ,'handphone','contact_person','telephone_cp','cabang_penjual','cabang_service','salesman','last_service','job','pekerjaan_utama','program_promo'
  10. ,'status_aktif','hasil_fu1','hasil_fu2','hasil_fu3'); //field yang ada di table user
  11. var $column_search = array('no_rangka','no_polisi','model','type','transmission','warna','tahun','km','customer','telephone'
  12. ,'handphone','contact_person','telephone_cp','cabang_penjual','cabang_service','salesman','last_service','job','pekerjaan_utama','program_promo'
  13. ,'status_aktif','hasil_fu1','hasil_fu2','hasil_fu3'); //field yang diizin untuk pencarian
  14. var $order = array('nomor' => 'asc'); // default order
  15.  
  16.  
  17. public function __construct ()
  18. {
  19. parent::__construct();
  20. $this->load->database();
  21. }
  22.  
  23.  
  24. private function _get_datatables_query()
  25. {
  26.  
  27. $this->db->from($this->table);
  28.  
  29. $i = 0;
  30.  
  31. foreach ($this->column_search as $item) // loop column
  32. {
  33. if($_POST['search']['value']) // if datatable send POST for search
  34. {
  35.  
  36. if($i===0) // first loop
  37. {
  38. $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
  39. $this->db->like($item, $_POST['search']['value']);
  40. }
  41. else
  42. {
  43. $this->db->or_like($item, $_POST['search']['value']);
  44. }
  45.  
  46. if(count($this->column_search) - 1 == $i) //last loop
  47. $this->db->group_end(); //close bracket
  48. }
  49. $i++;
  50. }
  51.  
  52. if(isset($_POST['order'])) // here order processing
  53. {
  54. $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  55. }
  56. else if(isset($this->order))
  57. {
  58. $order = $this->order;
  59. $this->db->order_by(key($order), $order[key($order)]);
  60. }
  61. }
  62.  
  63. function get_datatables()
  64. {
  65. $this->_get_datatables_query();
  66. if($_POST['length'] != -1)
  67. $this->db->limit($_POST['length'], $_POST['start']);
  68. $query = $this->db->get();
  69. return $query->result();
  70. }
  71.  
  72. function count_filtered()
  73. {
  74. $this->_get_datatables_query();
  75. $query = $this->db->get();
  76. return $query->num_rows();
  77. }
  78.  
  79. public function count_all()
  80. {
  81. $this->db->from($this->table);
  82. return $this->db->count_all_results();
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /// data sebelumnya..yg menggunakan datatables standar
  90.  
  91.  
  92.  
  93.  
  94.  
  95. function service(){
  96. return $this->db->get('service');
  97. }
  98.  
  99. function addService($add){
  100. return $this->db->insert('service',$add);
  101. }
  102.  
  103. //fungsi untuk mendapatkan service, atau mencari primary key milik table service
  104. function getService($flag){
  105. $this->db->where($flag);
  106. return $this->db->get('service');
  107. }
  108.  
  109. //fungsi untuk mengedit service yang ada didatabase
  110. function editService($flag,$edit){
  111. $this->db->where($flag);
  112. return $this->db->update('service',$edit);
  113. }
  114.  
  115. //fungsi untuk delete data service
  116. function deleteService($flag){
  117. $this->db->where($flag);
  118. return $this->db->delete('service');
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment