anjhar

member_model

Dec 9th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. <?php
  2.  
  3. class Member_Model extends BF_Model {
  4.  
  5. private $db_import = null;
  6.  
  7. function __construct() {
  8. parent::__construct();
  9. $this->db_import = $this->load->database('import',TRUE);
  10. }
  11. /*
  12. function import_connection($id) {
  13. //ambil data username + password
  14. $this->db->where("member.".$this->key, $id);
  15. $this->db->join("profil_sekolah", $this->table.".iid_profil_sekolah = profil_sekolah.iid_profil_sekolah");
  16. $query = $this->db->get($this->table);
  17. //$query = $this->db->query("select * from member where ".$this->key."=".$id);
  18. if ($query->num_rows == 1) {
  19. return $query->row_array();
  20. }
  21. return NULL;
  22. //isi sesuai result
  23. $dsn = 'dbdriver://username:password@hostname/database?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache';
  24. $this->db_import = $this->load->database($dsn, TRUE);
  25. }
  26. */
  27.  
  28. protected $table = "member";
  29. protected $key = "iid_member";
  30.  
  31. function load_member($id) {
  32. $this->db->where("member.".$this->key, $id);
  33. $this->db->join("profil_sekolah", $this->table.".iid_profil_sekolah = profil_sekolah.iid_profil_sekolah");
  34. $query = $this->db->get($this->table);
  35. //$query = $this->db->query("select * from member where ".$this->key."=".$id);
  36. if ($query->num_rows == 1) {
  37. return $query->row_array();
  38. }
  39. return NULL;
  40. }
  41.  
  42. function get_sekolah_non_member()
  43. {
  44. $this->db->select('iid_profil_sekolah as id');
  45. $this->db->select('cnama_sekolah as name');
  46. $this->db->where('imember',"0");
  47.  
  48. return $this->db->get('profil_sekolah');
  49. }
  50.  
  51. /*
  52. function select_all()
  53. {
  54. $this->db->select('*');
  55. $select = $this->db->get('profile_sekolah')->result();
  56. return $select;
  57. }
  58. */
  59. function get_sum_kuota_siswa(){
  60. $this->db->select_sum('imaks_siswa');
  61. $query = $this->db->get($this->table);
  62. $result = $query->result();
  63. return $result[0]->imaks_siswa;
  64. }
  65.  
  66. function get_sum_aktiv_siswa($data){
  67. if($data == "l")
  68. $query = $this->db->query('select sum(siswa_l) as siswa from '.$this->table);
  69. else
  70. $query = $this->db->query('select sum(siswa_p) as siswa from '.$this->table);
  71.  
  72. $result = $query->result();
  73. return $result[0]->siswa;
  74. }
  75.  
  76. function get_sum_aktiv_pegawai($data){
  77. if($data == "l")
  78. $query = $this->db->query('select sum(pegawai_l) as pegawai from '.$this->table);
  79. else
  80. $query = $this->db->query('select sum(pegawai_p) as pegawai from '.$this->table);
  81.  
  82. $result = $query->result();
  83. return $result[0]->pegawai;
  84. }
  85.  
  86.  
  87. function get_combo_paket(){
  88. $this->db->select('iid_paket as id');
  89. $this->db->select('vnama_paket as name');
  90. return $this->db->get('paket');
  91. }
  92.  
  93. function get_json_member($data) {
  94. $records = array();
  95. $records["aaData"] = array();
  96.  
  97. $this->db->where(array('profil_sekolah.idelete' => '0', "profil_sekolah.imember" => "1"));
  98. $this->db->join("profil_sekolah", $this->table.".iid_profil_sekolah = profil_sekolah.iid_profil_sekolah");
  99. $query = $this->db->get($this->table);
  100.  
  101. $itotalrecords = $query->num_rows();
  102.  
  103. $idisplaylength = intval($data['iDisplayLength']);
  104. $idisplaylength = $idisplaylength < 0 ? $itotalrecords : $idisplaylength;
  105. $idisplaystart = intval($data['iDisplayStart']);
  106. $secho = intval($data['sEcho']);
  107.  
  108. $end = $idisplaystart + $idisplaylength;
  109. $end = $end > $itotalrecords ? $itotalrecords : $end;
  110.  
  111. $records["sStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  112. $records["sMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  113.  
  114. $records["sEcho"] = $secho;
  115. $records["iTotalRecords"] = $itotalrecords;
  116. $records["iTotalDisplayRecords"] = $itotalrecords;
  117.  
  118. $this->db->join("profil_sekolah", $this->table.".iid_profil_sekolah = profil_sekolah.iid_profil_sekolah");
  119. $this->db->join("paket", $this->table.".ipaket = paket.iid_paket");
  120. $this->db->where("profil_sekolah.imember","1");
  121.  
  122. if ($this->soft_deletes === TRUE)
  123. $this->db->where("profil_sekolah.idelete","0");
  124.  
  125. $query = $this->db->get($this->table, $idisplaylength,$idisplaystart);
  126.  
  127. foreach ($query->result_array() as $row) {
  128. $straksi = '';
  129. if ($data['ubah'] == 1)
  130. $straksi .= '<a href="#" onclick=editdata("' . $row[$this->key] . '") class="btn green btn-xs default" title="Edit"><i class="fa fa-edit"></i></a> ';
  131. if ($data['hapus'] == 1)
  132. $straksi .= '<a href="#" onclick=deletedata("' . $row[$this->key] . '") class="btn red btn-xs default" title="Delete"><i class="fa fa-times"></i></a> ';
  133.  
  134. $straksi .= '<a href="#" onclick=viewdata("' . $row[$this->key] . '") class="btn blue btn-xs default" title="'.$this->lang->line('preview').'"><i class="fa fa-search"></i></a> ';
  135. $straksi .= '<a href="#" onclick=importdata("' . $row[$this->key] . '") class="btn btn-xs default" id="import" title="Import"><i class="fa fa-download"></i></a> ';
  136. //$straksi .= '<a href="#" onclick=viewdata class="btn btn-xs default" id="import" title="import"><i class="fa fa-download"></i></a> ';
  137. $row['aksi'] = $straksi;
  138. $row['jumlah_siswa'] = $row['siswa_l'] + $row['siswa_p'];
  139. $row['jumlah_pegawai'] = $row['pegawai_l'] + $row['pegawai_p'];
  140.  
  141. $records["aaData"][] = array(
  142. $row['cnama_sekolah'],
  143. $row['ckode'],
  144. $row['ckabupaten'],
  145. $row['cpropinsi'],
  146. $row['dtgl_awal'],
  147. $row['dtgl_akhir'],
  148. $row['vnama_paket'],
  149. $row['jumlah_siswa'],
  150. $row['jumlah_pegawai'],
  151. $row['imaks_siswa'],
  152. $row['imaks_sms'],
  153. $row['webkey'],
  154. $row['aksi']
  155. );
  156. }
  157.  
  158. echo json_encode($records);
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment