Initial baseline WACloud CI3 production
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Dashboard extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Cek sesi login dan role
|
||||
if (
|
||||
!$this->session->userdata('is_logged_in') ||
|
||||
$this->session->userdata('role') !== 'admin'
|
||||
) {
|
||||
redirect('auth');
|
||||
}
|
||||
|
||||
// ⚠️ Ganti nama alias agar tidak bentrok dengan nama class
|
||||
$this->load->model('Dashboard_model', 'Dashboard');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['phone_numbers'] = $this->Dashboard->get_phone_number($this->session->userdata('user_id'));
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('dashboard/layout', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
|
||||
public function get_grafik()
|
||||
{
|
||||
$phone_number = $this->input->post('phone_number');
|
||||
$date_start = $this->input->post('date_start');
|
||||
$date_end = $this->input->post('date_end');
|
||||
|
||||
if (empty($phone_number) || empty($date_start) || empty($date_end)) {
|
||||
echo json_encode(['error' => 'Parameter tidak lengkap']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Ambil data WABA dan access token dari model
|
||||
$data = $this->Dashboard->get_whatsapp_data_by_phone($phone_number);
|
||||
|
||||
if (!$data) {
|
||||
echo json_encode(['error' => 'Nomor WhatsApp tidak ditemukan']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Konversi tanggal ke epoch
|
||||
$start_time = strtotime($date_start);
|
||||
$end_time = strtotime($date_end);
|
||||
|
||||
// Ambil data analytics dari model
|
||||
$analytics = $this->Dashboard->getAnalyticsByNumber(
|
||||
$data->phone_waba_id,
|
||||
$data->access_token,
|
||||
$phone_number,
|
||||
$start_time,
|
||||
$end_time
|
||||
);
|
||||
|
||||
// Kirim hasil ke frontend
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($analytics));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user