Last active
June 24, 2020 14:40
-
-
Save sinyo1015/468c4d0ce0e6307cea372ae6f9d93693 to your computer and use it in GitHub Desktop.
P
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
require APPPATH . '/libraries/REST_Controller.php'; | |
use Restserver\Libraries\REST_Controller; | |
class Lapangan extends REST_Controller{ | |
public function __construct(){ | |
parent::__construct(); | |
$this->load->model('M_Futsal'); | |
} | |
public function index_get(){ | |
$lapangan = $this->M_Futsal->lapangan()->result(); | |
foreach($lapangan as $lapang){ | |
$tersedia = $this->M_Futsal->tersedia(1, $lapang->id_lapangan, '2020-06-24', '10:00:00', '14:00:00'); | |
if($tersedia->num_rows() <= 0){ | |
echo "Lapangan ".$lapang->id_lapangan." Tersedia"; | |
}else{ | |
echo "Lapangan ".$lapang->id_lapangan." Tidak Tersedia"; | |
} | |
echo "<br><br>"; | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class M_Futsal extends CI_Model{ | |
// Menampilkan List Futsal yang terdaftar | |
public function tampilFut(){ | |
return $tampilFut = $this->db->query("SELECT id_futsal, nama_futsal, alamat_futsal, telp_futsal FROM tb_futsal WHERE id_futsal"); | |
} | |
// Menampilkan lapangan yang tersedia setelah memilih futsal | |
public function specFut($id){ | |
return $specFut = $this->db->query("SELECT id_lapangan, tb_lapangan.id_futsal, nama_futsal, harga_lapangan, foto_lapangan FROM tb_lapangan JOIN tb_futsal ON tb_lapangan.id_futsal=tb_futsal.id_futsal WHERE tb_lapangan.id_futsal='$id'"); | |
} | |
public function lapangan(){ | |
return $this->db->query("SELECT * FROM tb_lapangan WHERE id_futsal='1'"); | |
} | |
public function tersedia($id_futsal, $id_lapangan, $tanggal, $jam_awal, $jam_akhir){ | |
$jamAwal = (new DateTime($jam_awal))->modify('+1 seconds')->format("H:i:s"); | |
$jamAkhir = (new DateTime($jam_akhir))->modify('+1 seconds')->format("H:i:s"); | |
$jamAwalOri = (new DateTime($jam_awal))->format("H:i:s"); | |
$jamAkhirOri = (new DateTime($jam_akhir))->format("H:i:s"); | |
return $this->db->query("SELECT * FROM tb_booking WHERE id_futsal = '$id_futsal' AND id_lapangan = '$id_lapangan' AND (( TIME(waktu_mulai) BETWEEN CAST('$jamAwal' as TIME) AND CAST('$jamAkhir' as TIME)) OR ((TIME(waktu_berakhir) BETWEEN CAST('$jamAwal' as TIME) AND CAST('$jamAkhir' as TIME)))) AND DATE(waktu_mulai) = '$tanggal' AND DATE(waktu_berakhir) = '$tanggal'"); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment