/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, Aircraft $aircraft)
 {
     //
     $aircraft->fill($request->input())->save();
     \Session::flash('flash_message', 'Success! aircraft updated');
     return redirect('aircraft/' . $aircraft->slug);
 }
 public function __construct($attributes = array())
 {
     parent::__construct($attributes);
     // Call default constructor
     // $this->statusable_type = "App\\Shorthaulhelicopter";
     // $this->Distance = 100;  // This is the radius of the 'response ring' around a helicopter in nautical miles.  Default: 100;
     // $this->LabelText= ".";  // This is a workaround to help ArcGIS server render the helicopter symbol in the center of its response circle. This should ALWAYS BE "."
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if (\Request::ajax()) {
         return view('ajax.aircraftShow', ['aircraft' => Aircraft::find($id)]);
     } else {
         Log::error('AircraftController@show no ajax request');
         abort(403, 'Unauthorized action.');
     }
 }
 public function run()
 {
     DB::table('statuses')->delete();
     $rightNow = Carbon::now();
     $heli = Aircraft::where("tailnumber", "N1111")->first();
     $user = User::where("crew_id", $heli->crew_id)->first();
     $crew = $heli->crew;
     $oldtime = Carbon::now()->subday();
     // A timestamp from yesterday
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 42.454223, 'longitude' => -123.310388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Bob Nielson", 'manager_phone' => "789-566-4430", 'comments1' => "This is update 1 of 2 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "Gasquet Complex", 'assigned_fire_number' => "WA-FRE-150038", 'assigned_supervisor' => "John Thompson", 'assigned_supervisor_phone' => "333-444-5555", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $oldtime, 'updated_at' => $oldtime, 'crew_name' => $crew->name, 'popupinfo' => "");
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 42.464223, 'longitude' => -121.210388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Bob Nielson", 'manager_phone' => "789-566-4430", 'comments1' => "This is update 2 of 2 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "Gasquet Complex", 'assigned_fire_number' => "WA-FRE-150038", 'assigned_supervisor' => "John Thompson", 'assigned_supervisor_phone' => "333-444-5555", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $rightNow, 'updated_at' => $rightNow, 'crew_name' => $crew->name, 'popupinfo' => "");
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $heli = Aircraft::where("tailnumber", "N2222")->first();
     $user = User::where("crew_id", $heli->crew_id)->first();
     $crew = $heli->crew;
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 44.084223, 'longitude' => -119.310388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Jim Lewis", 'manager_phone' => "250-778-5443", 'comments1' => "This is update 1 of 1 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "Big Windy", 'assigned_fire_number' => "OR-RSF-150208", 'assigned_supervisor' => "Bill Newman", 'assigned_supervisor_phone' => "333-444-5555", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $rightNow, 'updated_at' => $rightNow, 'crew_name' => $crew->name, 'popupinfo' => "");
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $heli = Aircraft::where("tailnumber", "N3333")->first();
     $user = User::where("crew_id", $heli->crew_id)->first();
     $crew = $heli->crew;
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 46.384223, 'longitude' => -115.310388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Steve Borland", 'manager_phone' => "334-998-6756", 'comments1' => "This is update 1 of 1 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "", 'assigned_fire_number' => "", 'assigned_supervisor' => "", 'assigned_supervisor_phone' => "", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $rightNow, 'updated_at' => $rightNow, 'crew_name' => $crew->name, 'popupinfo' => "");
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $heli = Aircraft::where("tailnumber", "J-83")->first();
     $user = User::where("crew_id", $heli->crew_id)->first();
     $crew = $heli->crew;
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 38.51106, 'longitude' => -118.441425, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Mark Kennedy", 'manager_phone' => "789-432-2120", 'comments1' => "This is update 1 of 1 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "", 'assigned_fire_number' => "", 'assigned_supervisor' => "", 'assigned_supervisor_phone' => "", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $rightNow, 'updated_at' => $rightNow, 'crew_name' => $crew->name, 'popupinfo' => '');
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $heli = Aircraft::where("tailnumber", "J-89")->first();
     $user = User::where("crew_id", $heli->crew_id)->first();
     $crew = $heli->crew;
     $oldtime = Carbon::now()->subDays(3);
     // A stale timestamp
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $heli->id, 'statusable_name' => $heli->tailnumber, 'latitude' => 45.281331, 'longitude' => -116.225388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Pat Stone", 'manager_phone' => "530-448-8581", 'comments1' => "This is update 1 of 1 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "Morning Fire", 'assigned_fire_number' => "MT-FFT-150038", 'assigned_supervisor' => "Gary Pickett", 'assigned_supervisor_phone' => "333-444-5555", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $oldtime, 'updated_at' => $oldtime, 'crew_name' => $crew->name, 'popupinfo' => '');
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
     $crew = Crew::where("name", "Prineville Hotshots")->first();
     $user = User::where("crew_id", $crew->id)->first();
     $oldtime = Carbon::now()->subDays(3);
     // A stale timestamp
     $statusArray = array('statusable_type' => $crew->statusable_type, 'statusable_id' => $crew->id, 'statusable_name' => $crew->name, 'latitude' => 45.281331, 'longitude' => -111.225388, 'staffing_value1' => "3", 'staffing_value2' => "4", 'manager_name' => "Pat Stone", 'manager_phone' => "530-448-8581", 'comments1' => "This is update 1 of 1 from the db seeder", 'comments2' => "This is upcoming", 'assigned_fire_name' => "Morning Fire", 'assigned_fire_number' => "MT-FFT-150038", 'assigned_supervisor' => "Gary Pickett", 'assigned_supervisor_phone' => "333-444-5555", 'Distance' => 100, 'LabelText' => ".", 'created_by_name' => $user->firstname . " " . $user->lastname, 'created_by_id' => $user->id, 'created_at' => $oldtime, 'updated_at' => $oldtime, 'crew_name' => $crew->name, 'popupinfo' => '');
     $statusArray['popupinfo'] = $this->createPopupinfo($statusArray);
     $status = Status::create($statusArray);
 }
 /**
  * Display the Aircraft Status update form
  * Note: this form POSTS its response to the StatusController
  */
 public function newStatus(Request $request, $tailnumber)
 {
     // Determine the subclass for this Aircraft (Shorthaulhelicopter, Rappelhelicopter, Smokejumperairplane, etc)
     $aircraft = Aircraft::where('tailnumber', '=', $tailnumber)->first();
     if (is_null($aircraft)) {
         return "Aircraft not found";
     }
     $aircraft = $aircraft->subclass();
     // Instantiate a child class (Rappelhelicopter, for example) NOT the parent "Aircraft" class
     // Make sure this user is authorized...
     if (Auth::user()->cannot('actAsAdminForCrew', $aircraft->crew_id)) {
         // The current user does not have permission to perform admin functions for this crew
         return redirect()->back()->withErrors("You're not authorized to access that aircraft!");
     }
     // Authorization complete - continue...
     // Retrieve the other Aircrafts that are owned by the same Crew (to build a navigation menu)
     $crew = $aircraft->crew;
     $aircraft_class = $aircraft->classname();
     $crew_aircrafts = $aircraft_class::where('crew_id', $aircraft->crew_id)->orderBy('tailnumber')->get();
     // Retrieve the most recent status update to prepopulate the form (returns a 'new Status' if none exist)
     $last_status = $aircraft->status();
     // Convert the lat and lon from decimal-degrees into decimal-minutes
     // MOVE THIS FUNCTIONALITY INTO A COORDINATES CLASS
     if (!empty($last_status->latitude)) {
         $sign = $last_status->latitude >= 0 ? 1 : -1;
         // Keep track of whether the latitude is positive or negative
         $last_status->latitude_deg = floor(abs($last_status->latitude)) * $sign;
         $last_status->latitude_min = round((abs($last_status->latitude) - $last_status->latitude_deg) * 60.0, 4);
     } else {
         $last_status->latitude_deg = "";
         $last_status->latitude_min = "";
     }
     if (!empty($last_status->longitude)) {
         $sign = $last_status->longitude >= 0 ? 1 : -1;
         // Keep track of whether the longitude is positive or negative
         $last_status->longitude_deg = floor(abs($last_status->longitude)) * $sign * -1;
         // Convert to 'West-positive' reference
         $last_status->longitude_min = round((abs($last_status->longitude) - $last_status->longitude_deg) * 60.0, 4);
     } else {
         $last_status->longitude_deg = "";
         $last_status->longitude_min = "";
     }
     // Display the status update form
     if (Auth::user()->isGlobalAdmin()) {
         $request->session()->flash('active_menubutton', 'aircraft');
         // Tell the menubar which button to highlight
     } else {
         $request->session()->flash('active_menubutton', 'status');
         // Tell the menubar which button to highlight
     }
     // return view('aircrafts.new_status')->with("aircraft",$aircraft)->with("aircrafts",$crew_aircrafts)->with("status",$last_status)->with("crew",$crew);
     $resource_type = $crew->statusable_type_plain();
     return view('status_forms.' . $resource_type)->with("aircraft", $aircraft)->with("aircrafts", $crew_aircrafts)->with("status", $last_status)->with("crew", $crew);
     // return view('status_forms.shorthaulhelicopter')->with("aircraft",$aircraft)->with("aircrafts",$crew_aircrafts)->with("status",$last_status)->with("crew",$crew);
     // return var_dump($aircraft);
     // return var_dump($last_status);
 }
 public function __construct($attributes = array())
 {
     parent::__construct($attributes);
     // Call default constructor
     // $this->statusable_type = "App\\Smokejumperairplane";
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // Make sure this user is authorized...
     if (Auth::user()->cannot('actAsAdminForCrew', $id)) {
         // The current user does not have permission to perform admin functions for this crew
         return redirect()->back()->withErrors("You're not authorized to access that crew!");
     }
     // Authorization complete - continue...
     // Grab the form input
     $crew_fields = array_except($request->input('crew'), ['aircrafts']);
     $crew = Crew::find($id);
     // Deal with a logo file upload
     if ($request->hasFile('logo')) {
         if ($request->file('logo')->isValid()) {
             $filename = "crew_" . $id . "_logo.jpg";
             $request->file('logo')->move('logos', $filename);
             $crew_fields['logo_filename'] = '/logos/' . $filename;
         }
         // *** Add error handling for the file upload ***
     }
     // Save any changes to the Crew model
     $crew->update($crew_fields);
     // *** Add error handling/validation for the Crew model
     // Deal with the Aircraft fields:
     // For each Aircraft on the form, create new or update the existing Aircraft in the dB if necessary
     // (don't update the model if nothing has changed)
     $aircraft_fields = array();
     if (isset($request->input('crew')['aircrafts'])) {
         $aircraft_fields = $request->input('crew')['aircrafts'];
     }
     foreach ($aircraft_fields as $aircraft) {
         if (!empty($aircraft['tailnumber'])) {
             // Instantiate a new Aircraft - CONVERT TAILNUMBER TO ALL CAPS IN THE DATABASE
             $temp_heli = Aircraft::firstOrCreate(array('tailnumber' => strtoupper($aircraft['tailnumber'])));
             $aircraft['crew_id'] = $id;
             $temp_heli->updateIfChanged($aircraft);
             // An error occurred during updateIfChanged()
             // Go back to the form and display errors
             // return redirect()->route('edit_crew', $crew->id)
             //->withErrors($temp_heli->errors())
             //            ->withInput();
         }
     }
     // Everything completed successfully
     return redirect()->route('edit_crew', $crew->id)->with('alert', array('message' => 'Crew info saved!', 'type' => 'success'));
 }
 public function __construct($attributes = array())
 {
     parent::__construct($attributes);
     // Call default constructor
     // $this->statusable_type = "App\\Rappelhelicopter";
 }