Advertisement
nurrohim11

Untitled

Jul 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.30 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class BengkelController extends CI_Controller{
  5.  
  6.     public function __construct(){
  7.         parent::__construct();
  8.         //ini di ambil dulu modelnya, model dibuat untuk mendapatkan data dari database langsung
  9.         $this->load->model('BengkelModel');
  10.     }
  11.  
  12.  
  13.     //Controller data bengkel
  14.     public function getAllBengkel(){
  15.         $response = array('Bengkel' => $this->BengkelModel->modelAllBengkel()->result());
  16.         $this->print_json($response);
  17.         exit;
  18.     }
  19.     public function getBengkelDetails($id_bengkel){
  20.         $response =  array('Details' => $this->BengkelModel->modelGetBengkelDetails($id_bengkel)->row_array());
  21.         $this->print_json($response);
  22.         exit;
  23.     }
  24.     //============================
  25.  
  26.     public function getMerkMotor(){
  27.         $response = array('MerkMotor' => $this->BengkelModel->modelgetMerkMotor()->result());
  28.         $this->print_json($response);
  29.         exit;
  30.     }
  31.     public function getDataMotor($id_merk_motor){
  32.         $response = array('motorlist' => $this->BengkelModel->modelGetDataMotor($id_merk_motor)->result());
  33.         $this->print_json($response);
  34.         exit;
  35.     }
  36.  
  37.     //=============================
  38.  
  39.     public function login(){
  40.         $data = (array)json_decode(file_get_contents('php://input'));
  41.         $response = $this->BengkelModel->modelLogin($data);
  42.         if(count($response) > 0){
  43.             $this->print_login_response($response->id_user,true,'Logged in !');
  44.         }else{
  45.             $this->print_response(false,'Wrong Username or Password!');
  46.         }
  47.         exit;
  48.     }
  49.  
  50.     public function getDataUser($id_user){
  51.         $response =  $this->BengkelModel->modelGetDataUser($id_user)->row_array();
  52.         $this->print_json($response);
  53.         exit;
  54.     }
  55.  
  56.     public function registerUser(){
  57.         $data = (array)json_decode(file_get_contents('php://input'));
  58.         $is_insert= $this->BengkelModel->modelRegisterUser($data);
  59.         if($is_insert > 0){
  60.             $this->print_response(true,'Success Register Data');
  61.         }
  62.         else{
  63.             $this->print_response(false,'Failed Register Data');
  64.         }
  65.         exit;      
  66.     }
  67.     public function editUser(){
  68.         $data = (array)json_decode(file_get_contents('php://input'));
  69.         $is_edit= $this->BengkelModel->modelEditUser($data);
  70.         if($is_edit > 0){
  71.             $this->print_response(true,'Success Edit Data');
  72.         }
  73.         else{
  74.             $this->print_response(false,'Failed To Edit Data');
  75.         }
  76.         exit;      
  77.     }
  78.  
  79.     // Controller Booking
  80.  
  81.     public function getBookingData($id_user){
  82.         $response = array('UserBooking' => $this->BengkelModel->modelGetBookingData($id_user)->result());
  83.         $this->print_json($response);
  84.         exit;
  85.     }
  86.     public function insertBookingData(){
  87.         $data = (array)json_decode(file_get_contents('php://input'));
  88.         $is_insert= $this->BengkelModel->modelInsertBookingData($data);
  89.         if($is_insert > 0){
  90.             $this->print_response(true,'Booking Success');
  91.         }
  92.         else{
  93.             $this->print_response(false,'Booking Failed');
  94.         }
  95.         exit;
  96.     }
  97.     public function deleteBookingData($id_booking){
  98.         $is_delete= $this->BengkelModel->modelDeleteBookingData($id_booking);
  99.         if($is_delete > 0){
  100.             $this->print_response(true,'Delete Success');
  101.         }
  102.         else{
  103.             $this->print_response(false,'Delete Failed');
  104.         }
  105.         exit;
  106.     }
  107.    
  108.      /**
  109.         Method print_login_response buat mencetak status login apakah berhasil atau tidak
  110.     **/
  111.     public function print_response($status ,$info){
  112.         $response = array(
  113.             'Success' => $status,
  114.             'Info' => $info);
  115.         $this->print_json($response);
  116.     }
  117.     public function print_login_response($id_user,$status ,$info){
  118.         $response = array(
  119.             'id_user' => $id_user,
  120.             'Success' => $status,
  121.             'Info' => $info);
  122.         $this->print_json($response);
  123.     }
  124.     /**
  125.         Method print_json buat mencetak data berformat JSON.
  126.     **/
  127.     public function print_json($response){
  128.         $this->output
  129.         ->set_status_header(200)
  130.         ->set_content_type('application/json', 'utf-8')
  131.         ->set_output(json_encode($response, JSON_PRETTY_PRINT))
  132.         ->_display();
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement