コード例 #1
0
 /**
  * get all route that passing certain bus stop
  *
  * @param $halte_id
  * @return \Illuminate\Http\JsonResponse
  */
 public function getRoutePassingBusStop($halte_id)
 {
     $busRouteModel = new BusRoute();
     $busRoute = $busRouteModel->select('rute_id')->where('halte_id', '=', $halte_id)->groupBy('rute_id')->get()->toArray();
     $response = array();
     if ($busRoute != null) {
         $response['code'] = 200;
         $response['data'] = $busRoute;
     } else {
         $response['code'] = 400;
         $response['data']['msg'] = 'bus stop is not registered in system, make sure you make correct request.';
     }
     header("Access-Control-Allow-Origin: *");
     return response()->json($response);
 }
 /**
  * check bus stop history,
  * if last visited bus is the last bus stop on its route, then delete record that related to that bus
  */
 public function checkBusStopHistory()
 {
     $busStopHistoryModel = new BusStopHistory();
     $busStopHistory = $busStopHistoryModel->where('plat_nomor', '=', $this->plat_nomor)->orderBy('arrival_history', 'desc')->with('routeOrder')->take(1)->get()->toArray();
     if (sizeof($busStopHistory > 0) && $busStopHistory != null) {
         $busRouteModel = new BusRoute();
         $lastRouteOrder = $busRouteModel->where('rute_id', '=', $busStopHistory[0]['rute_id'])->orderBy('urutan', 'desc')->take(1)->get()->toArray();
         //if bus has reach the last bus stop on its route, then delete related record
         if ($busStopHistory[0]['route_order']['urutan'] == $lastRouteOrder[0]['urutan']) {
             $busStopHistoryModel = new BusStopHistory();
             $busStopHistoryModel->where('plat_nomor', '=', $this->plat_nomor)->delete();
         }
     }
 }
コード例 #3
0
 /**
  * Display bus stop operating in certain route
  *
  * @param $rute_id
  * @return \Illuminate\Http\JsonResponse
  */
 public function busStopOperationInRoute($rute_id)
 {
     $response = array();
     try {
         $busRouteModel = new BusRoute();
         $busStop = $busRouteModel->select('rute_id', 'halte_id', DB::raw('halte_id as slug'))->where('rute_id', '=', $rute_id)->with(array('detailHalte' => function ($query) {
             $query->addSelect('nama_halte', 'lokasi_halte', 'halte_id');
         }))->get()->toArray();
         if (isset($busStop[0])) {
             for ($i = 0; $i < sizeof($busStop); $i++) {
                 $busStop[$i]['rute_pass'] = $busRouteModel->select('rute_id')->where('halte_id', '=', $busStop[$i]['halte_id'])->groupBy('rute_id')->get()->toArray();
                 unset($busStop[$i]['halte_id']);
             }
             $response['code'] = 200;
             $response['data'] = $busStop;
         } else {
             $response['code'] = 400;
             $response['data']['msg'] = 'cannot find operating bus stop in this route, please try again later';
         }
     } catch (\Exception $e) {
         $response['code'] = 500;
         $response['data']['msg'] = "internal server error, please contact administrator";
     }
     header("Access-Control-Allow-Origin: *");
     return response()->json($response);
 }
コード例 #4
0
 /**
  * get remaining bus stop information based on route_id of the bus and visited bus stop
  *
  * @param $plat_nomor
  * @return \Illuminate\Http\JsonResponse
  */
 public function remainingBusStop($plat_nomor)
 {
     $busOperationModel = new BusOperation();
     $busRouteModel = new BusRoute();
     $busStopHistoryModel = new BusStopHistory();
     $response = array();
     try {
         if ($plat_nomor == 'all') {
             $listBusOperation = $busOperationModel->get()->toArray();
             $counter = 0;
             $dataContainer = array();
             foreach ($listBusOperation as $busOperation) {
                 $busStopHistory = $busStopHistoryModel->where('plat_nomor', '=', $plat_nomor)->get()->toArray();
                 $visitedBusStopArray = array();
                 for ($i = 0; $i < sizeof($busStopHistory); $i++) {
                     $visitedBusStopArray[$i] = $busStopHistory[$i]['halte_id'];
                 }
                 $busRoute = $busRouteModel->where('rute_id', '=', $busOperation['rute_id'])->whereNotIn('halte_id', $visitedBusStopArray)->with('detailHalte')->get()->toArray();
                 if ($busRoute != null) {
                     $dataContainer[$counter] = $busRoute;
                 } else {
                     $dataContainer[$counter]['msg'] = 'route is not registered in system';
                 }
                 $counter++;
             }
             $response['code'] = 200;
             $response['data'] = $dataContainer;
         } else {
             $busOperation = $busOperationModel->where('plat_nomor', '=', $plat_nomor)->firstOrFail();
             $busStopHistory = $busStopHistoryModel->where('plat_nomor', '=', $plat_nomor)->get()->toArray();
             $visitedBusStopArray = array();
             for ($i = 0; $i < sizeof($busStopHistory); $i++) {
                 $visitedBusStopArray[$i] = $busStopHistory[$i]['halte_id'];
             }
             $busRoute = $busRouteModel->where('rute_id', '=', $busOperation['rute_id'])->whereNotIn('halte_id', $visitedBusStopArray)->with('detailHalte')->get()->toArray();
             $response['code'] = 200;
             if ($busRoute != null) {
                 $response['data'] = $busRoute;
             } else {
                 $response['data']['msg'] = 'route is not registered in system';
             }
         }
     } catch (\Exception $e) {
         $response['code'] = 200;
         $response['data']['msg'] = 'bus is not registered in system';
     }
     header("Access-Control-Allow-Origin: *");
     return response()->json($response);
 }
コード例 #5
0
 /**
  * base recursion function, this will be self called if recursion condition happen
  *
  * @param $halte_id_origin
  * @param $halte_id_dest
  * @param $treeLevel
  * @return null
  */
 public function baseSearchRouteRecursion($halte_id_origin, $halte_id_dest, $treeLevel)
 {
     $busRouteModel = new BusRoute();
     $listBusRoute = $busRouteModel->where('halte_id', '=', $halte_id_dest)->with('detailHalte')->get()->toArray();
     //echo '<br><br>'.json_encode($listBusRoute).'<br>';
     foreach ($listBusRoute as $busRoute) {
         $this->response[$treeLevel] = $busRoute;
         //echo 'halte id origin'. $halte_id_origin. '<br>';
         //echo 'rute_id '. $busRoute['rute_id']. '<br>';
         try {
             $directOrigin = $busRouteModel->where('rute_id', '=', $busRoute['rute_id'])->where('halte_id', '=', $halte_id_origin)->with('detailHalte')->firstOrFail();
             //echo 'success <br>';
             $this->response[$treeLevel + 1] = $directOrigin;
             $this->counterRecursion = 0;
             return -1;
         } catch (\Exception $e) {
             //echo 'error message: '.$e;
             $this->counterRecursion++;
             //echo 'recursing ke '.$this->counterRecursion. '<br>';
             //echo 'urutan: '.($busRoute['urutan']-1). '<br>';
             //echo 'halte id '. $busRoute['halte_id']. '<br>';
             //echo 'rute_id '. $busRoute['rute_id']. '<br>';
             if ($busRoute['urutan'] - 1 == 0) {
             } else {
                 $prevBusStop = $busRouteModel->where('urutan', '=', $busRoute['urutan'] - 1)->where('rute_id', '=', $busRoute['rute_id'])->first();
                 if ($this->counterRecursion < 100) {
                     $status = $this->baseSearchRouteRecursion($halte_id_origin, $prevBusStop['halte_id'], $treeLevel + 1);
                     if ($status == -1) {
                         return -1;
                     }
                 } else {
                     $this->counterRecursion--;
                     return -1;
                 }
             }
         }
     }
 }