Membuat Antrian Dengan CodeIgniter dan Bootstrap (Part 6)

Controller Home.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('M_home');
        $this->auth->cek_auth(); //ngambil auth dari library
    }

    function index(){
      $username = $this->session->userdata('user_data');
      $tgl = date('Y-m-d');
      $antrian = $this->M_home->antrian($tgl)->result();
      $data = array(
        'username' => $username,
        'antrian' => $antrian,
      );
      $this->load->view('home/v_home',$data);
    }

    function data_antrian(){
      $tgl = date('Y-m-d');
      $antrian = $this->M_home->antrian($tgl)->result();
      $data = array(
        'antrian' => $antrian,
      );
      $this->load->view('home/v_data',$data);
    }

    function data_antrians(){
      $tgl = date('Y-m-d');
      $antrian = $this->M_home->antrian($tgl)->result();
      echo "1";
    }

}

models M_home.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class M_home extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function antrian($tgl){
      $this->db->from('ambil_antrian');
      $this->db->where('a_tgl',$tgl);
      $this->db->where('a_status <>','2');
      return $this->db->get();
    }

}

views (buat sebuah folder dengan nama home didalam folder views) buat nama file dengan nama v_home.php

<html>
<head>
  <title>Sistem Antrian | Login</title>
  <link rel="stylesheet" href="<?php echo base_url();?>bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <h1>Selamat Datang <?php echo $username;?><span style="float:right;"><a href="<?php echo base_url('login/logout');?>" class="btn btn-danger">Logout</a></span></h1>
      <div id="data_antrian"></div>
    </div>
  </div>
</div>
</body>
<script src="<?php echo base_url();?>bootstrap/js/jquery.min.js"></script>
</html>

<script>
  setInterval(function(){
    $("#data_antrian").load('<?php echo base_url("home/data_antrian")?>')
  }, 1000);
</script>

dan v_data.php didalam folder home (views/home)

<table class="table table-bordered table-hover">
  <tr>
    <th>No.</th>
    <th>Nomor Panggil</th>
    <th>Panggil</th>
    <th>Selesai</th>
  </tr>
  <?php if(!empty($antrian)){
    $no = 1;
    foreach($antrian as $antri){
    if($antri->a_status == '0'){
      $panggil = 'Panggil';
      $warna	 = 'btn btn-success';
    }else{
      $panggil = 'Panggil Ulang';
      $warna	 = 'btn btn-warning';
    }
  ?>
  <tr>
    <td><?php echo $no++;?></td>
    <td><?php echo $antri->a_nomor;?></td>
    <td><a href="<?php echo base_url('home/proses/'.$antri->a_nomor.'/'.$antri->a_tgl);?>" class="<?php echo $warna;?>"><?php echo $panggil;?></a>
    </td>
    <td><a href="<?php echo base_url('home/delete/'.$antri->a_nomor.'/'.$antri->a_tgl);?>" class="btn btn-danger">Hapus</a></td>
  </tr>
  <?php } ?>
  <?php } ?>
</table>

 

Recommended For You

About the Author: adyrhs

Leave a Reply

Your email address will not be published. Required fields are marked *