Advertisement
roynaldoindra

restaapi

Jul 12th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 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. $query = $this->db->query('SELECT admin.id_user,admin.nama,admin.alamat,service.nama_service,service.harga
  17. FROM admin LEFT JOIN service ON (service.id_admin = admin.id_user)GROUP BY admin.id_user order by
  18. admin.id_user ASC;');
  19. $output = $query->result_array();
  20. $this->response(array('data'=>$output));
  21. }
  22.  
  23.  
  24. /*foreach ($query->result_array() as $row)
  25. {
  26. echo $row['nama'];
  27. echo $row['alamat'];
  28. echo $row['nama_service'];
  29. echo $row['harga'];
  30. }
  31. echo json_encode($query);*/
  32.  
  33.  
  34. /*function index_get() {
  35. $id = $this->get('id_user');
  36. if ($id == '') {
  37. $user = $this->db->get('admin')->result();
  38. } else {
  39. $this->db->where('id_user', $id);
  40. $user = $this->db->get('admin')->result();
  41. }
  42. //$this->response($user, 200);
  43. $this->response(array('data'=>$user));
  44. }*/
  45.  
  46. function layanan_get() {
  47. $id = $this->get('id_service');
  48. if ($id == '') {
  49. $user = $this->db->get('service')->result();
  50. } else {
  51. $this->db->where('id_service', $id);
  52. $user = $this->db->get('service')->result();
  53. }
  54. //$this->response($user, 200);
  55. $this->response(array('data'=>$user));
  56. }
  57.  
  58. function pelayan_get() {
  59. $id = $this->get('id_pelayan');
  60. if ($id == '') {
  61. $user = $this->db->get('pelayan')->result();
  62. } else {
  63. $this->db->where('id_pelayan', $id);
  64. $user = $this->db->get('pelayan')->result();
  65. }
  66. //$this->response($user, 200);
  67. $this->response(array('data'=>$user));
  68. }
  69.  
  70. function reservasi_get() {
  71. $id = $this->get('id_pesan');
  72. if ($id == '') {
  73. $user = $this->db->get('reservasi')->result();
  74. } else {
  75. $this->db->where('id_pesan', $id);
  76. $user = $this->db->get('reservasi')->result();
  77. }
  78. $this->response($user, 200);
  79. }
  80.  
  81. function blog_get() {
  82. $id = $this->get('id_blog');
  83. if ($id == '') {
  84. $user = $this->db->get('blog')->result();
  85. } else {
  86. $this->db->where('id_blog', $id);
  87. $user = $this->db->get('blog')->result();
  88. }
  89. $this->response($user, 200);
  90. }
  91.  
  92. function reservasi_post() {
  93. $data = array(
  94. 'id_pesan' => $this->post('id_pesan'),
  95. 'id_user' => $this->post('id_user'),
  96. 'id_pemesan' => $this->post('id_pemesan'),
  97. 'id_service' => $this->post('id_service'),
  98. 'id_pelayan' => $this->post('id_pelayan'),
  99. 'tgl_pesan' => $this->post('tgl_pesan'),
  100. 'harga' => $this->post('harga'),
  101. 'total_biaya' => $this->post('total_biaya'),
  102. 'status_pesan' => $this->post('status_pesan'),
  103. 'pembayaran' => $this->post('pembayaran'),
  104. 'tanggal_pembayaran' => $this->post('tanggal_pembayaran'),
  105. );
  106. $insert = $this->db->insert('reservasi', $data);
  107. if ($insert) {
  108. $this->response($data, 200);
  109. } else {
  110. $this->response(array('status' => 'fail', 502));
  111. }
  112. }
  113.  
  114. function reservasi_put() {
  115. $id = $this->put('id_pesan');
  116. $data = array(
  117. 'id_pesan' => $this->put('id_pesan'),
  118. 'id_user' => $this->put('id_user'),
  119. 'id_pemesan' => $this->put('id_pemesan'),
  120. 'id_service' => $this->put('id_service'),
  121. 'id_pelayan' => $this->put('id_pelayan'),
  122. 'tgl_pesan' => $this->put('tgl_pesan'),
  123. 'harga' => $this->put('harga'),
  124. 'total_biaya' => $this->put('total_biaya'),
  125. 'status_pesan' => $this->put('status_pesan'),
  126. 'pembayaran' => $this->put('pembayaran'),
  127. 'tanggal_pembayaran' => $this->put('tanggal_pembayaran'),
  128. );
  129. $this->db->where('id_pesan', $id);
  130. $update = $this->db->update('reservasi', $data);
  131. if ($update) {
  132. $this->response($data, 200);
  133. } else {
  134. $this->response(array('status' => 'fail', 502));
  135. }
  136. }
  137.  
  138. /*function index_delete() {
  139. $id = $this->delete('id_user');
  140. $this->db->where('id_user', $id);
  141. $delete = $this->db->delete('admin');
  142. if ($delete) {
  143. $this->response(array('status' => 'success'), 201);
  144. } else {
  145. $this->response(array('status' => 'fail', 502));
  146. }
  147. }*/
  148.  
  149. function reservasi_delete() {
  150. $id = $this->delete('id_pesan');
  151. $this->db->where('id_pesan', $id);
  152. $delete = $this->db->delete('reservasi');
  153. if ($delete) {
  154. $this->response(array('status' => 'success'), 201);
  155. } else {
  156. $this->response(array('status' => 'fail', 502));
  157. }
  158. }
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement