Beispiel #1
0
 public function check($time, $airport, $day)
 {
     $this->setTime($time);
     $this->setAirport($airport);
     $this->getTimeRange();
     $count = FlightDay::whereRaw("(`arrival_time` <= ?\n            and `arrival_time` >= ?\n            and `arrival_airport_id` = ? and `day` = ?)\n            or (`departure_time` <= ?\n            and `departure_time` >= ?\n            and `departure_airport_id` = ? and `day` = ?) ", [$this->maxtime, $this->mintime, $airport, $day, $this->maxtime, $this->mintime, $airport, $day])->count();
     return $count;
 }
 /**
  * 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');
             }*/
 }