Ejemplo n.º 1
0
 public function deleteFeature($id)
 {
     // INPUT $id    The OBJECTID of a feature on the ArcGIS server
     $response = ArcServer::deleteFeature($id);
     echo "Attempting to delete feature with OBJECTID = " . $id . "<br />\n";
     if ($response === false) {
         echo "An error prevented this query from completing";
         // Log the error, if desired
     } else {
         // Success!
         //The ArcGIS Server responded with an array of OBJECT_IDs, as expected (the array could be empty though)
         echo var_dump($response);
     }
     return;
 }
Ejemplo n.º 2
0
 /**
  * Show the most recent Status for this Crew
  */
 public function showCurrentStatus($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...
     $status = Status::first();
     $response = ArcServer::findFeature($status);
     echo "Looking for tailnumber: " . $status->statusable_name . "<br />\n";
     if ($response === false) {
         echo "An error prevented this query from completing";
     } else {
         //This
         echo "OBJECT_IDs => [" . implode(",", $response) . "]";
     }
     // Determine whether to redirect to a Crews Status Update form or an Aircraft Status Update form
     // return "Showing most recent Status for Crew #".$id;
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // Accept a form post from either the Aircraft Status Form (route: 'new_status_for_aircraft')
     // or the Crew Status Form (route: 'new_status_for_crew')
     // Determine whether this is a status update for an Aircraft or a Crew
     // then store the ID of the Crew that owns this object.
     $classname = $request->get('statusable_type');
     $obj = $classname::find($request->get('statusable_id'));
     if (!$obj) {
         // The 'statusable_type' from the form is not one of the polymorphic 'statusable' classes.
         // Add the 'morphMany()' function to the desired class to make it statusable.
         return redirect()->back()->with('alert', array('message' => 'Status update failed! This status update is not linked to a statusable entity', 'type' => 'danger'));
     }
     $crew_id = $obj->get_crew_id();
     $crew = Crew::find($crew_id);
     // Make sure current user is authorized
     if (Auth::user()->cannot('actAsAdminForCrew', $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 update that crew!");
     }
     // This User is authorized - continue...
     $this->validate($request, ['latitude_deg' => 'required', 'latitude_min' => 'required', 'longitude_deg' => 'required', 'longitude_min' => 'required']);
     $latitude_dd = $this->decMinToDecDeg($request->get('latitude_deg'), $request->get('latitude_min'));
     $longitude_dd = $this->decMinToDecDeg($request->get('longitude_deg'), $request->get('longitude_min')) * -1.0;
     // Convert to 'Easting' (Western hemisphere is negative)
     // Form is valid, continue...
     $status = new Status(Input::all());
     // Add a period to the LabelText field - this is a a workaround for the ArcGIS server to be able to render a buffer around the shorthaulhelicopter features
     $status->LabelText = ".";
     // Insert the identity of the User who created this Status update (the CURRENT user):
     $status->created_by_name = Auth::user()->fullname();
     $status->created_by_id = Auth::user()->id;
     // Insert the name of the Crew that owns this Status update (if this Status refers to a Crew, then 'crew_name' will be the same as 'statusable_name')
     $status->crew_name = Crew::find($crew_id)->name;
     // Insert the lat and lon in decimal-degree format
     $status->latitude = $latitude_dd;
     $status->longitude = $longitude_dd;
     // Change the 'statusable_type' variable to a fully-namespaced class name (the html form only submits the class name, but not the namespace)
     // i.e. Change 'Shorthaulhelicopter' to 'App\Shorthaulhelicopter'. This is required for the Status class to be able to retrieve the correct Aircraft (or Crew).
     //$status->statusable_type = "App\\".ucwords($status->statusable_type);
     $status->created_at = date('Y-m-d H:m:s');
     // Temporarily set the timestamp so that it can be included in the popup (timestamp will be reset when $status is saved)
     // Build the HTML popup that will be displayed when this feature is clicked
     $status->popupinfo = $this->generatePopup($status, $crew);
     // Attempt to save
     if ($status->save()) {
         // Changes have been saved to the local database, now initiate an update on the ArcGIS Server...
         // Render a different popup view to be sent to the EGP, but don't save it locally
         $status->popupinfo = $this->generatePopup($status, $crew, "egp");
         $objectids = ArcServer::findFeature($status);
         if ($objectids === false) {
             // An error occurred in findFeature() - check 'laravel.log' for details
             return redirect()->back()->with('alert', array('message' => 'Status update was saved locally, but could not be sent to the EGP (findFeature error).', 'type' => 'danger'));
         } elseif (!isset($objectids[0]) || $objectids[0] == '') {
             // The server responded, but the request feature was not found - add it.
             $result = ArcServer::addFeature($status);
         } else {
             // The Feature being updated was found on the ArcGIS server - now update it.
             $objectid = $objectids[0];
             $result = ArcServer::updateFeature($objectid, $status);
         }
         // Check the ArcGIS server response to determine if the operation was successful or not.
         if (empty($result->error)) {
             return redirect()->back()->with('alert', array('message' => 'Status update saved!', 'type' => 'success'));
         } else {
             return redirect()->back()->with('alert', array('message' => 'Status update was saved locally, but could not be sent to the EGP: ' . $result->error, 'type' => 'danger'));
         }
     }
     return redirect()->back()->with('alert', array('message' => 'Status update failed!', 'type' => 'danger'));
 }