예제 #1
0
 /**
  * Show calendar for Aircraft
  *
  * @return \Illuminate\Http\Response
  */
 public function calendar($slug)
 {
     $flights = FlightThread::whereAircraftUsageId($slug)->with('FlightDays', 'AirportDeparture', 'AirportArrival')->get();
     $i = 1;
     $return = [];
     $userData = Auth::User()->UserData();
     foreach ($flights as $flight) {
         foreach ($flight->FlightDays as $flightday) {
             //86400 Sec/Tag
             $arrival_time = strtotime($flightday->arrival_time);
             $departure_time = strtotime($flightday->departure_time);
             if ($arrival_time < $departure_time) {
                 //flying over midnight
                 $left_sec = $departure_time - strtotime('00:00:00');
                 $width_sec = strtotime('24:00:00') - $departure_time;
                 $left = $left_sec / 86400 * 100;
                 $width = $width_sec / 86400 * 100;
                 $return[$flightday->day][$i]['left'] = $left;
                 $return[$flightday->day][$i]['width'] = $width;
                 $return[$flightday->day][$i]['flightnumber'] = $userData->airline_short . $flight->flight_number;
                 $return[$flightday->day][$i]['departure_airport'] = $flight->AirportDeparture->iata;
                 $return[$flightday->day][$i]['arrival_airport'] = $flight->AirportArrival->iata;
                 $return[$flightday->day][$i]['departure_time'] = date('H:i', $departure_time);
                 $return[$flightday->day][$i]['arrival_time'] = date('H:i', $arrival_time);
                 $width_sec = $arrival_time - strtotime('00:00:00');
                 $width = $width_sec / 86400 * 100;
                 $return[$flightday->day * 2][999]['left'] = 0;
                 $return[$flightday->day * 2][999]['width'] = $width;
                 $return[$flightday->day * 2][999]['flightnumber'] = $userData->airline_short . $flight->flight_number;
                 $return[$flightday->day * 2][999]['departure_airport'] = $flight->AirportDeparture->iata;
                 $return[$flightday->day * 2][999]['arrival_airport'] = $flight->AirportArrival->iata;
                 $return[$flightday->day * 2][999]['departure_time'] = date('H:i', $departure_time);
                 $return[$flightday->day * 2][999]['arrival_time'] = date('H:i', $arrival_time);
             } else {
                 $time = $arrival_time - $departure_time;
                 $start_time = $departure_time - strtotime('00:00:00');
                 $width = $time / 86400 * 100;
                 $left = $start_time / 86400 * 100;
                 $return[$flightday->day][$i]['left'] = $left;
                 $return[$flightday->day][$i]['width'] = $width;
                 $return[$flightday->day][$i]['flightnumber'] = $userData->airline_short . $flight->flight_number;
                 $return[$flightday->day][$i]['departure_airport'] = $flight->AirportDeparture->iata;
                 $return[$flightday->day][$i]['arrival_airport'] = $flight->AirportArrival->iata;
                 $return[$flightday->day][$i]['departure_time'] = date('H:i', $departure_time);
                 $return[$flightday->day][$i]['arrival_time'] = date('H:i', $arrival_time);
             }
             $i++;
         }
     }
     return view('template.fleet.calendar', ['days' => $return]);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(FlightThreadCreateRequest $request)
 {
     $departure_time = strtotime($request->departure_time);
     $arrival_time = Carbon::createFromTimestamp($departure_time)->addHours(2)->addMinutes(0);
     $departure_time = Carbon::createFromTimestamp($departure_time);
     $flightThread = new FlightThread();
     $flightThread->fill($request->all());
     $flightThread->slug = str_slug($request->flight_number);
     $flightThread->departure_airport_id = Station::find($request->departure_station_id)->airport_id;
     $flightThread->arrival_airport_id = Station::find($request->arrival_station_id)->airport_id;
     $flightThread->arrival_time = $arrival_time;
     $flightThread->user_id = Auth::user()->id;
     $flightThread->save();
     if (is_array($request->days)) {
         foreach ($request->days as $day) {
             $flightday = new FlightDay();
             $flightday->flight_thread_id = $flightThread->id;
             $flightday->offset = $request->departure_offset[$day];
             $flightday->day = $day;
             $flightday->departure_time = $departure_time->addMinutes($request->departure_offset[$day]);
             $flightday->arrival_time = $arrival_time->addMinutes($request->departure_offset[$day]);
             $flightday->departure_airport_id = Station::find($request->departure_station_id)->airport_id;
             $flightday->arrival_airport_id = Station::find($request->arrival_station_id)->airport_id;
             $flightday->departure_station_id = $request->departure_station_id;
             $flightday->arrival_station_id = $request->arrival_station_id;
             $flightday->save();
         }
     }
     return redirect()->route('flightOverview')->with('success', 'Flug wurde eingeplant');
     //Hinflug
     /*$flightThread = new FlightThread;
             $flightThread->fill($request->all());
             $flightThread->user_id = Auth::user()->id;
             $flightThread->slug = str_slug($request->flight_number);
             $flightThread->save();
     
     
     
             //Zurückflug
             $flightThread = new FlightThread;
             $flightThread->aircraft_id = $request->aircraft_id;
             $flightThread->flight_number = $request->flight_number_back;
             $flightThread->departure_airport_id = $request->arrival_airport_id;
             $flightThread->arrival_airport_id = $request->departure_airport_id;
             $flightThread->user_id = Auth::user()->id;
             $flightThread->slug = str_slug($request->flight_number_back);
             $flightThread->save();*/
     /*return redirect()->route('flightOverview')->with('success', 'Flug wurde erstellt');*/
     /*$flight = new Flight;
             $flight->flight_thread_id = $flightThread->id;
             $flight->departure_time = Carbon::createFromFormat('Y-m-d G:i',$request->departure_day.' '.$request->departure_time);
             $flight->arrival_time = Carbon::createFromFormat('Y-m-d G:i',$request->departure_day.' '.$request->departure_time)->addHours(24)->second(0);
             $flight->user_id = Auth::user()->id;
             if($flight->save()){
     
                 return redirect()->route('flightOverview')->with('success', 'Flug wurde erstellt');
             }*/
 }
예제 #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $flights = FlightThread::whereSlug($slug)->with('Flight')->first();
     return view('template.flight.show', ['flights' => $flights]);
 }