Beispiel #1
0
 public function scopefromPilot($query, $pilotId = null)
 {
     if ($pilotId === null) {
         $pilotId = PilotRepository::getCurrentPilot()->id;
     }
     $query->select('pireps.*')->join('bookings', 'bookings.id', '=', 'pireps.booking_id')->join('pilots', 'pilots.id', '=', 'bookings.pilot_id')->where('pilots.id', '=', $pilotId);
 }
Beispiel #2
0
    public function getSinglePirep(Pirep $pirep)
    {
        // Do we have access to this PIREP?
        if ($pirep->booking->pilot->id !== PilotRepository::getCurrentPilot()->id) {
            return redirect('/pireps');
        }
        // Calculate some data bits (keep it out of the view)
        $extras = [];
        // Airborne Time
        $takeoff = new Carbon($pirep->departure_time);
        $landing = new Carbon($pirep->landing_time);
        $extras['airborneTime'] = $takeoff->diff($landing);
        // Blocks Time
        $offBlocks = new Carbon($pirep->off_blocks_time);
        $onBlocks = new Carbon($pirep->on_blocks_time);
        $extras['blocksTime'] = $offBlocks->diff($onBlocks);
        // Total Time
        $start = new Carbon($pirep->pirep_start_time);
        $finish = new Carbon($pirep->pirep_end_time);
        $extras['totalTime'] = $start->diff($finish);
        // Planned Route
        $routeService = new Route();
        $extras['routePoints'] = $routeService->getAllPointsForRoute($pirep->booking->route);
        // Format Text Log (ugly, I know!)
        $extras['log'] = str_replace('[', '
[', $pirep->log);
        // Display the PIREP!
        return view('pireps/single', ['pirep' => $pirep, 'extras' => $extras]);
    }
Beispiel #3
0
 public function getDoJumpseat(Route $route)
 {
     // todo: VALIDATE!
     $pilot = PilotRepository::getCurrentPilot();
     // Save this jumpseat so we can track them!
     $booking = new Booking();
     $booking->pilot()->associate($pilot);
     $booking->route()->associate($route);
     $booking->aircraft_id = null;
     // This indicates a jumpseat booking
     $booking->callsign = 'JUMPSEAT';
     // This also indicates a jumpseat booking
     $booking->save();
     $booking->delete();
     // Put in a dummy PIREP
     $pirep = new Pirep();
     $pirep->booking()->associate($booking);
     $pirep->pirep_data = ['jumpseat' => true];
     $pirep->status = 'complete';
     $pirep->points = 0;
     $pirep->landing_rate = 0;
     $pirep->fuel_used = 0;
     $pirep->load = 0;
     $pirep->save();
     $pilot->location()->associate($route->arrivalAirport);
     $pilot->save();
     return redirect('/flights');
 }
Beispiel #4
0
 /**
  * Bind data to the view.
  *
  * @param Route $route
  * @param  View $view
  */
 public function compose(View $view)
 {
     $routeService = new Route();
     $pilot = PilotRepository::getCurrentPilot();
     $currentBooking = Booking::has('pirep', '<', 1)->where('pilot_id', '=', $pilot->id)->first();
     $view->with('currentBooking', $currentBooking);
     $view->with('upcomingBookings', Booking::has('pirep', '<', 1)->limit(10)->skip(1)->where('pilot_id', '=', $pilot->id)->get());
     $view->with('routePoints', $routeService->getAllPointsForRoute($currentBooking->route));
     $view->with('depMetar', Cache::remember('Metar:' . $currentBooking->route->departureAirport->icao, 10, function () use($currentBooking) {
         return file_get_contents('http://weather.noaa.gov/pub/data/observations/metar/decoded/' . strtoupper($currentBooking->route->departureAirport->icao) . '.TXT');
     }));
     $view->with('arrMetar', Cache::remember('Metar:' . $currentBooking->route->arrivalAirport->icao, 10, function () use($currentBooking) {
         return file_get_contents('http://weather.noaa.gov/pub/data/observations/metar/decoded/' . strtoupper($currentBooking->route->arrivalAirport->icao) . '.TXT');
     }));
 }
Beispiel #5
0
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     // Are we connecting from a known URL?
     if ($airline = Airline::where('url', '=', Request::getHttpHost())->first()) {
         Session::put('airlineId', $airline->id);
     }
     if (Session::has('airlineId')) {
         $view->with('airline', Airline::find(Session::get('airlineId')));
     }
     if (Request::user()) {
         $view->with('user', Request::user());
         $view->with('pilot', PilotRepository::getCurrentPilot());
         $airline = Airline::find(Session::get('airlineId'));
         $view->with('airlineStaff', UserRepository::hasRole($airline->prefix . '-staff', Request::user()));
     }
 }
Beispiel #6
0
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $pilot = PilotRepository::getCurrentPilot();
     $currentLocation = $pilot->location;
     $lastBooking = Booking::has('pirep', '<', 1)->where('pilot_id', '=', $pilot->id)->orderBy('created_at', 'desc')->first();
     if (count($lastBooking) == 1) {
         $currentLocation = $lastBooking->route->arrivalAirport;
     }
     $view->with('currentLocation', $currentLocation);
     // Ordered flights list
     $sortedRoutes = [];
     $availableRoutes = RoutesRepository::getRoutesFrom($currentLocation);
     $view->with('availableRoutes', $availableRoutes);
     foreach ($availableRoutes as $route) {
         $sortedRoutes[$route->arrivalAirport->region->country->continent][$route->arrivalAirport->region->country->name][$route->arrivalAirport->region->name][] = (object) $route->arrivalAirport->toArray();
     }
     $view->with('sortedRoutes', $sortedRoutes);
 }
Beispiel #7
0
 public function getOwnProfile()
 {
     return $this->getProfile(PilotRepository::getCurrentPilot());
 }
 /**
  * Show the global leaderboards to the user.
  *
  * @return Response
  */
 public function getIndex()
 {
     // Collect statistics if required
     $data = Cache::get(PilotRepository::getCurrentPilot()->airline->prefix . ':Leaderboards:Global');
     return view('leaderboards.global', ['data' => (object) $data]);
 }
Beispiel #9
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();
 }