belajarmasak

mservice-individual

May 17th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 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. //fungsi pencarian data dropdown.
  24. function dd_pencarian()
  25. {
  26. // ambil data dari db
  27. $this->db->order_by('service', 'asc');
  28. $result = $this->db->get('service');
  29.  
  30. // bikin array
  31. // please select berikut ini merupakan tambahan saja agar saat pertama
  32. // diload akan ditampilkan text please select.
  33. $dd[''] = 'Please Select';
  34. if ($result->num_rows() > 0) {
  35. foreach ($result->result() as $row) {
  36. // tentukan value (sebelah kiri) dan labelnya (sebelah kanan)
  37. $dd[$row->model] = $row->model;
  38. }
  39. }
  40. return $dd;
  41. }
  42.  
  43.  
  44. private function _get_datatables_query()
  45. {
  46.  
  47. $this->db->from($this->table);
  48.  
  49. $i = 0;
  50.  
  51. foreach ($this->column_search as $item) // loop column
  52. {
  53. if($_POST['search']['value']) // if datatable send POST for search
  54. {
  55.  
  56. if($i===0) // first loop
  57. {
  58. $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
  59. $this->db->like($item, $_POST['search']['value']);
  60. }
  61. else
  62. {
  63. $this->db->or_like($item, $_POST['search']['value']);
  64. }
  65.  
  66. if(count($this->column_search) - 1 == $i) //last loop
  67. $this->db->group_end(); //close bracket
  68. }
  69. $i++;
  70. }
  71.  
  72. if(isset($_POST['order'])) // here order processing
  73. {
  74. $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  75. }
  76. else if(isset($this->order))
  77. {
  78. $order = $this->order;
  79. $this->db->order_by(key($order), $order[key($order)]);
  80. }
  81. }
  82.  
  83. function get_datatables()
  84. {
  85. $this->_get_datatables_query();
  86. if($_POST['length'] != -1)
  87. $this->db->limit($_POST['length'], $_POST['start']);
  88. $query = $this->db->get();
  89. return $query->result();
  90. }
  91.  
  92. function count_filtered()
  93. {
  94. $this->_get_datatables_query();
  95. $query = $this->db->get();
  96. return $query->num_rows();
  97. }
  98.  
  99. public function count_all()
  100. {
  101. $this->db->from($this->table);
  102. return $this->db->count_all_results();
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. /// data sebelumnya..yg menggunakan datatables standar
  110.  
  111.  
  112.  
  113.  
  114.  
  115. function service(){
  116. return $this->db->get('service');
  117. }
  118.  
  119. function addService($add){
  120. return $this->db->insert('service',$add);
  121. }
  122.  
  123. //fungsi untuk mendapatkan service, atau mencari primary key milik table service
  124. function getService($flag){
  125. $this->db->where($flag);
  126. return $this->db->get('service');
  127. }
  128.  
  129. //fungsi untuk mengedit service yang ada didatabase
  130. function editService($flag,$edit){
  131. $this->db->where($flag);
  132. return $this->db->update('service',$edit);
  133. }
  134.  
  135. //fungsi untuk delete data service
  136. function deleteService($flag){
  137. $this->db->where($flag);
  138. return $this->db->delete('service');
  139. }
  140. }
Add Comment
Please, Sign In to add comment