Esempio n. 1
0
 private function handleSearchFlight($request)
 {
     $pilot = Pilot::find($request->input('dbid'));
     if ($request->has('departureicao')) {
         $availableRoutes = Route::whereHas('departureAirport', function ($q) use($request) {
             $q->where('icao', '=', $request->input('departureicao'));
         })->where('airline_id', '=', $pilot->airline->id)->get();
     } else {
         $currentLocation = $pilot->location;
         $lastBooking = Booking::where('pilot_id', '=', $pilot->id)->orderBy('created_at', 'desc')->first();
         if (count($lastBooking) == 1) {
             $currentLocation = $lastBooking->route->arrivalAirport;
         }
         $availableRoutes = Route::where('departure_id', '=', $currentLocation->id)->where('airline_id', '=', $pilot->airline->id)->get();
     }
     $routesList = [];
     foreach ($availableRoutes as $route) {
         if ($request->has('arrivalicao') && $route->arrivalAirport->icao != $request->input('arrivalicao')) {
             continue;
         }
         $routesList[] = ["routeid" => $route->id, "code" => '', "flightnumber" => 'FR1234', "departureicao" => $route->departureAirport->icao, "arrivalicao" => $route->arrivalAirport->icao, "route" => $route->route, "cruisingaltitude" => 38000, "aircraft" => 'TBA', "flighttime" => "Unknown", "departuretime" => 0, "arrivaltime" => 0, "daysofweek" => ''];
     }
     $return = '';
     $runcount = 0;
     foreach ($routesList as $singleRoute) {
         if ($runcount != 0) {
             $return .= ";";
         }
         $singleRoute = str_replace(";", "", $singleRoute);
         $singleRoute = str_replace(",", "", $singleRoute);
         $return .= $singleRoute['routeid'] . "|" . $singleRoute['code'] . "|" . $singleRoute['flightnumber'] . "|" . $singleRoute['departureicao'] . "|" . $singleRoute['arrivalicao'] . "|" . $singleRoute['route'] . "|" . $singleRoute['cruisingaltitude'] . "|" . $singleRoute['aircraft'] . "|" . $singleRoute['flighttime'] . "|" . $singleRoute['departuretime'] . "|" . $singleRoute['arrivaltime'] . "|" . $singleRoute['daysofweek'];
         $runcount++;
     }
     return $return;
 }
Esempio n. 2
0
 public static function getRoutesFrom(Airport $airport)
 {
     // Get all outbound routes from this airport
     return Route::where('departure_id', '=', $airport->id)->where('airline_id', '=', PilotRepository::getCurrentPilot()->airline->id)->get();
 }