anjhar

member_model

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