/**
  * get detail feedback (praise/complaint) to certain bus stop
  *
  * @param $halte_id
  * @return \Illuminate\Http\JsonResponse
  */
 public function detailBusStopSatisfaction($halte_id)
 {
     $userFeedbackModel = new UserFeedback();
     try {
         $listUserFeedback = $userFeedbackModel->where('directed_to_bus_stop', '=', $halte_id)->get()->toArray();
         $groupUserFeedback = array();
         $groupUserFeedback['rating'] = 0;
         $groupUserFeedback['input'] = 0;
         $counter = 0;
         $detailRating = array();
         $detailRating[0]['rating'] = 1;
         $detailRating[0]['input'] = 0;
         $detailRating[1]['rating'] = 2;
         $detailRating[1]['input'] = 0;
         $detailRating[2]['rating'] = 3;
         $detailRating[2]['input'] = 0;
         $detailRating[3]['rating'] = 4;
         $detailRating[3]['input'] = 0;
         $detailRating[4]['rating'] = 5;
         $detailRating[4]['input'] = 0;
         foreach ($listUserFeedback as $userFeedback) {
             $groupUserFeedback['halte_id'] = $userFeedback['directed_to_bus_stop'];
             $groupUserFeedback['input']++;
             $groupUserFeedback['rating'] = $groupUserFeedback['rating'] + $userFeedback['satisfaction'];
             $groupUserFeedback['feedback'][$counter] = $userFeedback['complaint'];
             if ($userFeedback['satisfaction'] == 1) {
                 $detailRating[0]['input']++;
             } elseif ($userFeedback['satisfaction'] == 2) {
                 $detailRating[1]['input']++;
             } elseif ($userFeedback['satisfaction'] == 3) {
                 $detailRating[2]['input']++;
             } elseif ($userFeedback['satisfaction'] == 4) {
                 $detailRating[3]['input']++;
             } elseif ($userFeedback['satisfaction'] == 5) {
                 $detailRating[4]['input']++;
             }
             $counter++;
         }
         $groupUserFeedback['rating'] = $groupUserFeedback['rating'] / $groupUserFeedback['input'];
         $groupUserFeedback['detail_rating'] = $detailRating;
         if (isset($groupUserFeedback['detail_rating'][0])) {
             $response = array();
             $response['code'] = 200;
             $response['data'] = $groupUserFeedback;
         } else {
             $response['code'] = 400;
             $response['data']['msg'] = 'could not find rating evaluation';
         }
     } catch (\Exception $e) {
         $response['code'] = 500;
         $response['data']['msg'] = 'internal error, please try again later or contact administrator';
     }
     header("Access-Control-Allow-Origin: *");
     return response()->json($response);
 }
 /**
  * save user feedback about bus_stop/bus_operation to database
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function inputUserFeedback(Request $request)
 {
     $userFeedbackModel = new UserFeedback();
     $userId = $request->input('user_id');
     $userSatisfaction = $request->input('satisfaction');
     $userComplaint = $request->input('complaint');
     $userFeedbackModel->created_at = \Carbon\Carbon::now();
     $userFeedbackModel->updated_at = \Carbon\Carbon::now();
     $userFeedbackModel->user_id = $userId;
     $userFeedbackModel->satisfaction = $userSatisfaction;
     $userFeedbackModel->complaint = $userComplaint;
     if ($request->exists('halte_id')) {
         $directedToBusStop = $request->input('halte_id');
         $userFeedbackModel->directed_to_bus_stop = $directedToBusStop;
     }
     if ($request->exists('plat_nomor')) {
         $directedToBus = $request->input('plat_nomor');
         $userFeedbackModel->directed_to_bus = $directedToBus;
     }
     $response = array();
     if ($userFeedbackModel->save()) {
         $response['code'] = 200;
         $response['data']['msg'] = "feedback has successfully saved";
     } else {
         $response['code'] = 400;
         $response['data']['msg'] = "please provide correct parameter and try again";
     }
     header("Access-Control-Allow-Origin: *");
     return response()->json($response);
 }