Last active
April 20, 2016 06:12
-
-
Save virbo/51e416dea294b1304dd979902f566035 to your computer and use it in GitHub Desktop.
Modifikasi file Welcome.php, Alumni_model.php dan maps_view.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Alumni_model extends CI_Model | |
{ | |
/** | |
* @author Yusuf Ayuba | |
* @since 2016 | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function create($data) | |
{ | |
return $this->db->insert('modul_alumni',$data); | |
} | |
public function get_wil_ajax($cari,$limit) | |
{ | |
$this->db->select('rp.id AS id_prop,rk.id AS id_kab,rc.id AS id_kec,rd.id AS id_desa, | |
rp.name AS prop,rk.name AS kab,rc.name AS kec, | |
rd.name AS desa') | |
->from('provinces AS rp') | |
->join('regencies AS rk','rk.province_id=rp.id') | |
->join('districts AS rc','rc.regency_id=rk.id') | |
->join('villages AS rd','rd.district_id=rc.id') | |
->like('rd.name',$cari) | |
->order_by('rp.name','ASC') | |
->limit($limit,0); | |
return $this->db->get(); | |
} | |
public function get_location() | |
{ | |
$this->db->select('al.nm_alumni,al.id_wil,rd.name AS desa, | |
rk.name AS kec, rb.name AS kab, | |
rp.name AS prop') | |
->from('modul_alumni AS al') | |
->join('villages AS rd','al.id_wil=rd.id') | |
->join('districts AS rk','rd.district_id=rk.id') | |
->join('regencies AS rb','rk.regency_id=rb.id') | |
->join('provinces AS rp','rb.province_id=rp.id'); | |
return $this->db->get(); | |
} | |
public function get_location_by_id($id) | |
{ | |
$this->db->select('al.nm_alumni,CONCAT(rd.name, \', \', rp.name) AS lokasi') | |
->from('modul_alumni AS al') | |
->join('villages AS rd','al.id_wil=rd.id') | |
->join('districts AS rk','rd.district_id=rk.id') | |
->join('regencies AS rb','rk.regency_id=rb.id') | |
->join('provinces AS rp','rb.province_id=rp.id') | |
->where('al.id_wil',$id); | |
return $this->db->get(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Peta Sebaran Alumni</title> | |
<link href="<?php echo base_url('assets/css/bootstrap.min.css');?>" rel="stylesheet"> | |
<link href="<?php echo base_url('assets/css/font-awesome.min.css');?>" media="all" rel="stylesheet" /> | |
<?php echo $map['js']; ?> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="page-header" style="margin-top: 50px;"> | |
<blockquote> | |
<a href="<?php echo base_url('welcome');?>" class="btn btn-primary">Input Data</a> | |
</blockquote> | |
</div> | |
<div class="panel panel-default"> | |
<div class="panel-body"> | |
<legend>Peta Sebaran Alumni</legend> | |
<?php echo $map['html']; ?> | |
</div> | |
</div> | |
</div> | |
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.min.js');?>"></script> | |
<script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.min.js');?>"></script> | |
<script type="text/javascript"> | |
var top_url = '<?php echo base_url();?>'; | |
function showModal(id) { | |
var temp_url = top_url+'welcome/modal/'+id | |
$('#mod_title').html('Daftar Alumni'); | |
$('#isi').html('<center><i class="fa fa-circle-o-notch fa-spin fa-fw"></i> Loading data, please wait...</center>'); | |
$('#isi').load(temp_url); | |
$('#myModal').modal(); | |
} | |
</script> | |
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
<div class="modal-dialog modal-sm" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
<h4 class="modal-title" id="mod_title"></h4> | |
</div> | |
<div class="modal-body"> | |
<div id="isi"></div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Welcome extends CI_Controller { | |
/** | |
* @author Yusuf Ayuba | |
* @since 2016 | |
*/ | |
public function index() | |
{ | |
$this->add(); | |
} | |
public function add() | |
{ | |
$this->load->helper('form'); | |
$this->load->library('form_validation'); | |
$this->load->model('alumni_model','alumni'); | |
$data['nama'] = ''; | |
$this->form_validation->set_rules('nama','Nama','trim|required'); | |
$this->form_validation->set_rules('wilayah','Wilayah Tinggal','trim|required'); | |
if ($this->form_validation->run()===FALSE) { | |
$this->load->view('form_add',$data); | |
} else { | |
$nama = $this->input->post('nama'); | |
$wilayah = $this->input->post('wilayah'); | |
$data = array( | |
'nm_alumni'=>$this->input->post('nama'), | |
'id_wil' => $this->input->post('wilayah') | |
); | |
$this->alumni->create($data); | |
$this->session->set_flashdata('message','Sukses, Data alumni berhasil ditambahkan'); | |
redirect('welcome','refresh'); | |
} | |
} | |
public function ajax() | |
{ | |
$this->load->model('alumni_model','alumni'); | |
$cari = $this->input->post('cari'); | |
$limit =$this->input->post('page'); | |
$temp = $this->alumni->get_wil_ajax($cari,$limit)->result_array(); | |
echo json_encode($temp); | |
} | |
public function maps() | |
{ | |
$this->load->model('alumni_model','alumni'); | |
$config = array(); | |
$config['center'] = 'jakarta'; | |
$config['zoom'] = 'auto'; | |
$this->googlemaps->initialize($config); | |
$temp_result = $this->alumni->get_location()->result(); | |
$marker = array(); | |
foreach ($temp_result as $value) { | |
$marker['position'] = $value->desa.', '.$value->prop; | |
// parameter onclick digunakan untuk mennampilkan popuo windows dalam bentuk modals | |
$marker['onclick'] = 'javascript:showModal(\''.$value->id_wil.'\')'; | |
//$marker['infowindow_content'] = ''.$value->nm_alumni.'<br>Lokasi: '.$value->desa.', '.$value->prop.''; | |
//$marker['title'] = ''.$value->nm_alumni.'\n'.$value->desa.', '.$value->prop.''; | |
$this->googlemaps->add_marker($marker); | |
} | |
$data['map'] = $this->googlemaps->create_map(); | |
$this->load->view('maps_view', $data); | |
} | |
public function modal($id) | |
{ | |
$this->load->model('alumni_model','alumni'); | |
$temp_result = $this->alumni->get_location_by_id($id)->result(); | |
$temp_place = $this->alumni->get_location_by_id($id)->row(); | |
$temp_jml = count($temp_result); | |
echo "<div class=\"panel panel-primary\"> | |
<div class=\"panel-heading\"> | |
<div class=\"row\"> | |
<div class=\"col-xs-3\"> | |
<i class=\"fa fa-map-o fa-5x\"></i> | |
</div> | |
<div class=\"col-xs-9 text-right\"> | |
<div class=\"huge\">".$temp_jml."</div> | |
<div>Data Alumni</div> | |
</div> | |
<div class=\"col-xs-12\"> | |
<hr style=\"margin-bottom: 5px;\" /> | |
<small>".$temp_place->lokasi."</small> | |
</div> | |
</div> | |
</div> | |
<div class=\"panel-footer\">"; | |
foreach ($temp_result as $value) { | |
echo "<div><i class=\"fa fa-user\"></i> ".$value->nm_alumni."</div><hr />"; | |
} | |
echo "</div> | |
</div>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment