Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. defined('BASEPATH') or exit('No direct script access allowed');
  4.  
  5. class Home extends MY_Controller
  6. {
  7.  
  8.   protected $data = array();
  9.   protected $countries = array();
  10.  
  11.   public function __construct()
  12.   {
  13.     parent::__construct();
  14.     $this->load->model('Home_qry');
  15.     $jsonHis = $this->getHistory();
  16.     $dataHis = json_decode($jsonHis, true);
  17.     $sum_baru = 0;
  18.     $kasus_baru = 0;
  19.     if(is_array($dataHis) && count($dataHis) > 0){
  20.       foreach($dataHis['features'] as $val){
  21.         if(is_null($val['attributes']['Jumlah_Kasus_Kumulatif'])){
  22.           break;
  23.         }
  24.         $kasus_baru = $val['attributes']['Jumlah_Kasus_Baru_per_Hari'];
  25.         $sum_baru += $val['attributes']['Jumlah_Kasus_Baru_per_Hari'];
  26.         $this->data['last_info'] = $val['attributes'];
  27.       }
  28.       $this->data['avg'] = ($kasus_baru/$sum_baru) * 100;
  29.     }
  30.   }
  31.  
  32.   //redirect if needed, otherwise display the user list
  33.  
  34.   public function index()
  35.   {
  36.     $this->initIndex();
  37.     $this->template
  38.       ->title("Dashboard")
  39.       ->set_layout('main')
  40.       ->build('index', $this->data);
  41.   }
  42.  
  43.   public function getGlobal()
  44.   {
  45.     $curl = curl_init();
  46.  
  47.     curl_setopt_array($curl, array(
  48.       CURLOPT_URL => "https://services5.arcgis.com/VS6HdKS0VfIhv8Ct/arcgis/rest/services/COVID19_Indonesia_per_Provinsi/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json",
  49.       CURLOPT_RETURNTRANSFER => true,
  50.       CURLOPT_ENCODING => "",
  51.       CURLOPT_MAXREDIRS => 10,
  52.       CURLOPT_TIMEOUT => 0,
  53.       CURLOPT_FOLLOWLOCATION => true,
  54.       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  55.       CURLOPT_CUSTOMREQUEST => "GET",
  56.     ));
  57.    
  58.     $response = curl_exec($curl);
  59.    
  60.     curl_close($curl);
  61.     echo $response;
  62.   }
  63.  
  64.   public function getRoadMap(){
  65.     echo $this->getHistory();
  66.   }
  67.  
  68.   private function getHistory(){
  69.     $curl = curl_init();
  70.  
  71.     curl_setopt_array($curl, array(
  72.       CURLOPT_URL => "https://services5.arcgis.com/VS6HdKS0VfIhv8Ct/arcgis/rest/services/Statistik_Perkembangan_COVID19_Indonesia/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json",
  73.       CURLOPT_RETURNTRANSFER => true,
  74.       CURLOPT_ENCODING => "",
  75.       CURLOPT_MAXREDIRS => 10,
  76.       CURLOPT_TIMEOUT => 0,
  77.       CURLOPT_FOLLOWLOCATION => true,
  78.       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  79.       CURLOPT_CUSTOMREQUEST => "GET",
  80.     ));
  81.    
  82.     $response = curl_exec($curl);
  83.    
  84.     curl_close($curl);
  85.     return $response;
  86.    
  87.   }
  88.  
  89.   private function initIndex()
  90.   {
  91.     $this->data['form'] = array(
  92.       'periode' => array(
  93.         'placeholder' => 'Periode',
  94.         'id' => 'periode',
  95.         'name' => 'periode',
  96.         'value' => date('d-m-Y'),
  97.         'class' => 'form-control add-input-text calendar',
  98.         'maxlength' => '10',
  99.       ),
  100.       'countries' => array(
  101.         'attr' => array(
  102.           'placeholder' => 'Negara',
  103.           'id' => 'countries',
  104.           'class' => 'form-control ',
  105.         ),
  106.         'data' => $this->countries,
  107.         'value' => 'Indonesia',
  108.         'name' => 'countries',
  109.       ),
  110.     );
  111.   }
  112. }