/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { if (!Auth::user()->isGlobalAdmin()) { // Only Global Admins can access this return redirect()->back()->withErrors("Unauthorized"); } $crew = Crew::find($id); $crew_name = $crew->name; // Release all Aircrafts from this crew (null the crew_id field in the aircrafts table) if ($crew->is_an_aircraft_crew()) { $aircrafts = $crew->aircrafts; foreach ($aircrafts as $aircraft) { $aircraft->release(); } } // Delete all Users belonging to this crew foreach ($crew->users as $user) { $user->delete(); } $crew->delete(); return redirect()->route('crews_index')->with('alert', array('message' => "'" . $crew_name . "' was deleted.", 'type' => 'success')); }
/** * 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')); }
/** * * Remove crew member from movie * @return Response * */ public function removeCrewMember() { if ($this->isAdmin) { if (Request::ajax()) { $data = Request::all(); $movie_id = $data['movie']; $crew_id = $data['row']; $movie = Movies::findorfail($movie_id); Crew::find($crew_id)->delete(); return (string) view('movies.crew', compact('movie')); } } return "error"; }