<?php namespace App\Controllers;
/**
 * File			: Dashboard.php
 * Description  : Controller untuk halaman utama
 * Created By	: Hendi
 * Created Date : 13 Mar 2021
 * Last Update  : 24 Mar 2021
**/
use \App\Models\AntrianModel;
class Dashboard extends MyBaseController
{
	public function index()
	{
	    $this->hideAntrian();
		# fn isLoggedIn di MyBaseController
		//if (!$this->isLoggedIn()) return redirect()->to(base_url('/login'));
		# jika sudah menu dinamis diisi dari array hasil query
		$data_sidebar = []; 
		# jika dibutuhkan data untuk konten
		$data_content = [
			'mod' => 'dashboard',
		];
		$data = [
			'title' => 'Dashboard',
			'sidebar' => view('contents/sidebar', $data_sidebar),
			'content' => view('contents/dashboard', $data_content),
		];
		return view('templates/index', $data);
	}
	# hilangkan dari monitor otomatis jika out/finish lebih dari 30 detik
	function hideAntrian()
	{
	    $sekarang = date('Y-m-d H:i:s');
	    $AntrianModel = new AntrianModel();
	    $sql = "
	            UPDATE antrian SET status = 3, updated_at = '".$sekarang."'
	            WHERE status = 2 AND TIME_TO_SEC(TIMEDIFF(STR_TO_DATE('".$sekarang."', '%Y-%m-%d %H:%i:%s'), finish)) > 30
	           ";
	    $AntrianModel->db->query($sql);
	}
}
