anjhar

member_model

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