demo transaksi
This commit is contained in:
@@ -11,14 +11,15 @@ class appnotification extends CI_Controller
|
||||
is_logged_in();
|
||||
|
||||
$this->load->model('notification_model', 'notif');
|
||||
$this->load->model('Pelanggan_model', 'pelanggan_model');
|
||||
$this->load->library('form_validation');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data['pelanggan_list'] = $this->pelanggan_model->get_all_for_notification_picker();
|
||||
$this->load->view('includes/header');
|
||||
$this->load->view('appnotification/index');
|
||||
$this->load->view('appnotification/index', $data);
|
||||
$this->load->view('includes/footer');
|
||||
}
|
||||
|
||||
@@ -33,10 +34,57 @@ class appnotification extends CI_Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = $this->input->post('topic');
|
||||
$title = $this->input->post('title');
|
||||
$message = $this->input->post('message');
|
||||
$send_target = $this->input->post('send_target');
|
||||
|
||||
if ($send_target === 'users') {
|
||||
$user_ids = $this->input->post('user_ids');
|
||||
if (!is_array($user_ids)) {
|
||||
$user_ids = array();
|
||||
}
|
||||
$user_ids = array_unique(array_filter(array_map('intval', $user_ids)));
|
||||
if (empty($user_ids)) {
|
||||
$this->session->set_flashdata('error', 'Pilih minimal satu pengguna (user).');
|
||||
redirect('appnotification/index');
|
||||
return;
|
||||
}
|
||||
$sent = 0;
|
||||
$skipped = 0;
|
||||
foreach ($user_ids as $uid) {
|
||||
if ($uid <= 0) {
|
||||
continue;
|
||||
}
|
||||
$row = $this->pelanggan_model->get_notification_row_by_id($uid);
|
||||
if (!$row) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
$tok = isset($row->token) ? trim((string) $row->token) : '';
|
||||
if ($tok === '' || !fcm_v1_is_valid_device_token($tok)) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
if ($this->notif->send_notif($title, $message, $tok)) {
|
||||
$sent++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
}
|
||||
if ($sent > 0) {
|
||||
$msg = 'Notifikasi terkirim ke ' . $sent . ' pengguna.';
|
||||
if ($skipped > 0) {
|
||||
$msg .= ' ' . $skipped . ' dilewati (tanpa token FCM valid atau gagal kirim).';
|
||||
}
|
||||
$this->session->set_flashdata('send', $msg);
|
||||
} else {
|
||||
$this->session->set_flashdata('error', 'Tidak ada notifikasi terkirim. Pastikan pengguna memiliki token FCM valid (login dari aplikasi).');
|
||||
}
|
||||
redirect('appnotification/index');
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = $this->input->post('topic');
|
||||
$ok = $this->notif->send_notif($title, $message, $topic);
|
||||
if ($ok) {
|
||||
$this->session->set_flashdata('send', 'Notifikasi berhasil dikirim');
|
||||
|
||||
Reference in New Issue
Block a user