/** * 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); }