Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- require APPPATH . '/libraries/REST_Controller.php';
- use Restserver\Libraries\REST_Controller;
- class ApiUser extends REST_Controller {
- function __construct($config = 'rest') {
- parent::__construct($config);
- $this->load->database();
- }
- function index_get() {
- $query = $this->db->query('SELECT admin.id_user,admin.nama,admin.alamat,service.nama_service,service.harga
- FROM admin LEFT JOIN service ON (service.id_admin = admin.id_user)GROUP BY admin.id_user order by
- admin.id_user ASC;');
- $output = $query->result_array();
- $this->response(array('data'=>$output));
- }
- /*foreach ($query->result_array() as $row)
- {
- echo $row['nama'];
- echo $row['alamat'];
- echo $row['nama_service'];
- echo $row['harga'];
- }
- echo json_encode($query);*/
- /*function index_get() {
- $id = $this->get('id_user');
- if ($id == '') {
- $user = $this->db->get('admin')->result();
- } else {
- $this->db->where('id_user', $id);
- $user = $this->db->get('admin')->result();
- }
- //$this->response($user, 200);
- $this->response(array('data'=>$user));
- }*/
- function layanan_get() {
- $id = $this->get('id_service');
- if ($id == '') {
- $user = $this->db->get('service')->result();
- } else {
- $this->db->where('id_service', $id);
- $user = $this->db->get('service')->result();
- }
- //$this->response($user, 200);
- $this->response(array('data'=>$user));
- }
- function pelayan_get() {
- $id = $this->get('id_pelayan');
- if ($id == '') {
- $user = $this->db->get('pelayan')->result();
- } else {
- $this->db->where('id_pelayan', $id);
- $user = $this->db->get('pelayan')->result();
- }
- //$this->response($user, 200);
- $this->response(array('data'=>$user));
- }
- function reservasi_get() {
- $id = $this->get('id_pesan');
- if ($id == '') {
- $user = $this->db->get('reservasi')->result();
- } else {
- $this->db->where('id_pesan', $id);
- $user = $this->db->get('reservasi')->result();
- }
- $this->response($user, 200);
- }
- function blog_get() {
- $id = $this->get('id_blog');
- if ($id == '') {
- $user = $this->db->get('blog')->result();
- } else {
- $this->db->where('id_blog', $id);
- $user = $this->db->get('blog')->result();
- }
- $this->response($user, 200);
- }
- function reservasi_post() {
- $data = array(
- 'id_pesan' => $this->post('id_pesan'),
- 'id_user' => $this->post('id_user'),
- 'id_pemesan' => $this->post('id_pemesan'),
- 'id_service' => $this->post('id_service'),
- 'id_pelayan' => $this->post('id_pelayan'),
- 'tgl_pesan' => $this->post('tgl_pesan'),
- 'harga' => $this->post('harga'),
- 'total_biaya' => $this->post('total_biaya'),
- 'status_pesan' => $this->post('status_pesan'),
- 'pembayaran' => $this->post('pembayaran'),
- 'tanggal_pembayaran' => $this->post('tanggal_pembayaran'),
- );
- $insert = $this->db->insert('reservasi', $data);
- if ($insert) {
- $this->response($data, 200);
- } else {
- $this->response(array('status' => 'fail', 502));
- }
- }
- function reservasi_put() {
- $id = $this->put('id_pesan');
- $data = array(
- 'id_pesan' => $this->put('id_pesan'),
- 'id_user' => $this->put('id_user'),
- 'id_pemesan' => $this->put('id_pemesan'),
- 'id_service' => $this->put('id_service'),
- 'id_pelayan' => $this->put('id_pelayan'),
- 'tgl_pesan' => $this->put('tgl_pesan'),
- 'harga' => $this->put('harga'),
- 'total_biaya' => $this->put('total_biaya'),
- 'status_pesan' => $this->put('status_pesan'),
- 'pembayaran' => $this->put('pembayaran'),
- 'tanggal_pembayaran' => $this->put('tanggal_pembayaran'),
- );
- $this->db->where('id_pesan', $id);
- $update = $this->db->update('reservasi', $data);
- if ($update) {
- $this->response($data, 200);
- } else {
- $this->response(array('status' => 'fail', 502));
- }
- }
- /*function index_delete() {
- $id = $this->delete('id_user');
- $this->db->where('id_user', $id);
- $delete = $this->db->delete('admin');
- if ($delete) {
- $this->response(array('status' => 'success'), 201);
- } else {
- $this->response(array('status' => 'fail', 502));
- }
- }*/
- function reservasi_delete() {
- $id = $this->delete('id_pesan');
- $this->db->where('id_pesan', $id);
- $delete = $this->db->delete('reservasi');
- if ($delete) {
- $this->response(array('status' => 'success'), 201);
- } else {
- $this->response(array('status' => 'fail', 502));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement