Notifikasi CI
function getData(){
var content = "";
var contentBody ="";
var getBodyNotifikasiDiv ="";
$.ajax({
type : "POST",
url : "<?php echo base_url('index.php/Notifikasi/Get_Data')?>",
dataType : "JSON",
cache:false,
success: function(response){
console.log(response.get_Datas);
console.log(response.get_Datas[0].totalNotifikasi);
content += `${response.get_Datas[0].totalNotifikasi}`;
$("#txtTotalNotif").html(content);
var getDataNotify = response.get_Datas[0].datas;
for (i=0;i< getDataNotify.length;i++){
var rowData = getDataNotify[i];
/*<a class="dropdown-item ${rowData.status_dibaca == "Belum Dibaca"?"active":""}" href="<?php echo base_url("index.php/Notifikasi/update_status_dibaca/")?>${rowData.id}" style="font-size: 13px;">${rowData.remark} Rp. ${rowData.nominal} Berhasil</a>`;*/
contentBody += `
<a class="dropdown-item ${rowData.status_dibaca == "Belum Dibaca"?"active":""}" style="font-size: 13px;">${rowData.remark} Rp. ${rowData.nominal} Berhasil</a>`;
if(response.get_Datas[0].countTableNotifikasi > 0){
getBodyNotifikasiDiv = `<div class="dropdown-menu" style="margin-left:-290px;margin-top:5px;" id="txtNotifikasi" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#" style="font-size: 13px;">Pemberitahuan</a>
<div class="dropdown-divider"></div>
<div id="txtBodyNotifikasi"></div>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" style="font-size: 13px;">Lihat Semua</a>
</div>`
}
}
$("#getBodyNotifikasi").html(getBodyNotifikasiDiv);
$("#txtBodyNotifikasi").html(contentBody);
}
});
}
function SaveNotifikasiInvestasi(){
var nominal = $('.total-pembayaran').val();
$.ajax({
type : "POST",
url : "<?php echo base_url('index.php/Notifikasi/SaveNotifikasiInvestasi')?>",
dataType : "JSON",
data : {nominal:nominal},
success: function(data){
}
});
}
===============
Controller
==============
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Notifikasi extends MY_Controller {
public function get_Data()
{
if($this->session->userdata("user")){
$username = $this->session->userdata("user");
$email = $this->session->userdata("user")->email;
if($email == null)$email = "";
$datas = $this->db->select('*')->where("email",$email)->order_by("create_date","Desc")->limit(90)->get('tb_notifikasi')->result();
$totalNotifikasi = count($this->db->select('*')->where("status_dibaca","Belum Dibaca")->where("email",$email)->get('tb_notifikasi')->result());
$countTableNotifikasi = count($datas);
if($totalNotifikasi == 0)$totalNotifikasi = "";
$data[] = [
"countTableNotifikasi" => $countTableNotifikasi,
"totalNotifikasi" => $totalNotifikasi,
"datas" => $datas,
"nama" => $username->email,
"AllData" => ""//$this->session->userdata("user")
];
echo json_encode(["get_Datas" => $data]);
}
}
public function Save_Data_Saldo()
{
date_default_timezone_set('asia/jakarta');
$create_date = date('Y-m-d H:i:s');
$email = $this->session->userdata("user")->email;
$data = array(
'nominal' => $this->input->post('nominal'),
'pembayaran' => $this->input->post('pembayaran'),
'status_dibaca' => "Belum Dibaca",
'create_date' => $create_date,
'email' => $email,
'remark' => "Isi Saldo"
);
$this->db->insert('tb_notifikasi', $data);
}
public function SaveNotifikasiInvestasi()
{
date_default_timezone_set('asia/jakarta');
$create_date = date('Y-m-d H:i:s');
$email = $this->session->userdata("user")->email;
$data = array(
'nominal' => $this->input->post('nominal'),
'pembayaran' => "",
'status_dibaca' => "Belum Dibaca",
'create_date' => $create_date,
'email' => $email,
'remark' => "Total Pembayaran"
);
$this->db->insert('tb_notifikasi', $data);
}
public function update_status_dibaca($id)
{
$email = $this->session->userdata("user")->email;
$this->db->query("update tb_notifikasi set status_dibaca = 'Sudah Dibaca' where id='$id' and email='$email'");
redirect(base_url());
}
public function iconNotifUpdate()
{
$email = $this->session->userdata("user")->email;
$this->db->query("update tb_notifikasi set status_dibaca = 'Sudah Dibaca' and email='$email'");
echo json_encode(["get_Datas" => "Update Proses Success Notifikasi.php line 73"]);
}
}
Tidak ada komentar