Advertisement
roynaldoindra

ApiUser

Jun 7th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.56 KB | None | 0 0
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. require APPPATH . '/libraries/REST_Controller.php';
  6. use Restserver\Libraries\REST_Controller;
  7.  
  8. class ApiUser extends REST_Controller {
  9.  
  10.     function __construct($config = 'rest') {
  11.         parent::__construct($config);
  12.         $this->load->database();
  13.     }
  14.  
  15.     function index_get() {
  16.         $id = $this->get('id_user');
  17.         if ($id == '') {
  18.             $user = $this->db->get('admin')->result();
  19.         } else {
  20.             $this->db->where('id_user', $id);
  21.             $user = $this->db->get('admin')->result();
  22.         }
  23.         $this->response($user, 200);
  24.     }
  25.  
  26.     function layanan_get() {
  27.         $id = $this->get('id_service');
  28.         if ($id == '') {
  29.             $user = $this->db->get('service')->result();
  30.         } else {
  31.             $this->db->where('id_service', $id);
  32.             $user = $this->db->get('service')->result();
  33.         }
  34.         $this->response($user, 200);
  35.     }
  36.  
  37.     function reservasi_get() {
  38.         $id = $this->get('id_pesan');
  39.         if ($id == '') {
  40.             $user = $this->db->get('reservasi')->result();
  41.         } else {
  42.             $this->db->where('id_pesan', $id);
  43.             $user = $this->db->get('reservasi')->result();
  44.         }
  45.         $this->response($user, 200);
  46.     }
  47.  
  48.     function blog_get() {
  49.         $id = $this->get('id_blog');
  50.         if ($id == '') {
  51.             $user = $this->db->get('blog')->result();
  52.         } else {
  53.             $this->db->where('id_blog', $id);
  54.             $user = $this->db->get('blog')->result();
  55.         }
  56.         $this->response($user, 200);
  57.     }
  58.  
  59.     function reservasi_post() {
  60.         $data = array(
  61.                     'id_pesan'           => $this->post('id_pesan'),
  62.                     'id_user'           => $this->post('id_user'),
  63.                     'id_pemesan'           => $this->post('id_pemesan'),
  64.                     'id_service'           => $this->post('id_service'),
  65.                     'id_pelayan'           => $this->post('id_pelayan'),
  66.                     'tgl_pesan'          => $this->post('tgl_pesan'),
  67.                     'harga'    => $this->post('harga'),
  68.                     'total_biaya'    => $this->post('total_biaya'),
  69.                     'status_pesan'           => $this->post('status_pesan'),
  70.                     'pembayaran'           => $this->post('pembayaran'),
  71.                     'tanggal_pembayaran'           => $this->post('tanggal_pembayaran'),
  72.                     );
  73.         $insert = $this->db->insert('reservasi', $data);
  74.         if ($insert) {
  75.             $this->response($data, 200);
  76.         } else {
  77.             $this->response(array('status' => 'fail', 502));
  78.         }
  79.     }
  80.  
  81.     function reservasi_put() {
  82.         $id = $this->put('id_pesan');
  83.         $data = array(
  84.                     'id_pesan'           => $this->put('id_pesan'),
  85.                     'id_user'           => $this->put('id_user'),
  86.                     'id_pemesan'           => $this->put('id_pemesan'),
  87.                     'id_service'           => $this->put('id_service'),
  88.                     'id_pelayan'           => $this->put('id_pelayan'),
  89.                     'tgl_pesan'          => $this->put('tgl_pesan'),
  90.                     'harga'    => $this->put('harga'),
  91.                     'total_biaya'    => $this->put('total_biaya'),
  92.                     'status_pesan'           => $this->put('status_pesan'),
  93.                     'pembayaran'           => $this->put('pembayaran'),
  94.                     'tanggal_pembayaran'           => $this->put('tanggal_pembayaran'),
  95.                     );
  96.         $this->db->where('id_pesan', $id);
  97.         $update = $this->db->update('reservasi', $data);
  98.         if ($update) {
  99.             $this->response($data, 200);
  100.         } else {
  101.             $this->response(array('status' => 'fail', 502));
  102.         }
  103.     }
  104.  
  105.     function index_delete() {
  106.         $id = $this->delete('id_user');
  107.         $this->db->where('id_user', $id);
  108.         $delete = $this->db->delete('admin');
  109.         if ($delete) {
  110.             $this->response(array('status' => 'success'), 201);
  111.         } else {
  112.             $this->response(array('status' => 'fail', 502));
  113.         }
  114.     }
  115.  
  116.     function reservasi_delete() {
  117.         $id = $this->delete('id_pesan');
  118.         $this->db->where('id_pesan', $id);
  119.         $delete = $this->db->delete('reservasi');
  120.         if ($delete) {
  121.             $this->response(array('status' => 'success'), 201);
  122.         } else {
  123.             $this->response(array('status' => 'fail', 502));
  124.         }
  125.     }
  126.  
  127. }
  128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement