/** * Processes the edit meal form to update a meal * @return Redirect */ public function update($id, Request $request) { // Only update existing meals $meal = Meal::find($id); if (!$meal) { App::abort(404, "Maaltijd niet gevonden"); } // Construct candidate object $meal_data = $request->all(); // Validate the resulting input $validator = Validator::make($meal_data, ['meal_timestamp' => ['date_format:d-m-Y G:i', 'required', 'unique:meals,meal_timestamp,' . $meal->id], 'locked_timestamp' => ['date_format:d-m-Y G:i', 'required']], ['meal_timestamp.date_format' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.required' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.unique' => 'Er is al een maaltijd op deze datum en tijd', 'locked_timestamp.date_format' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'locked_timestamp.required' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)']); if ($validator->passes()) { // Format dates to database compatible values $meal_data['meal_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['meal_timestamp']); $meal_data['locked_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['locked_timestamp']); // Update meal in database $meal->update($meal_data); if ($meal->save()) { Log::info("Maaltijd geupdate: {$meal->id}|{$meal->meal_timestamp}|{$meal->event}"); Flash::set(Flash::SUCCESS, 'Maaltijd geupdate'); return redirect('/administratie/' . $meal->id); } else { Flash::set(Flash::ERROR, 'Maaltijd kon niet worden geupdate'); } } else { Session::flash('validation_errors', $validator->messages()); return redirect('/administratie/' . $meal->id . '/edit')->withInput(); } }
public function aanmelden_anonmiem() { $meal = Meal::find((int) Request::input('meal_id')); if (!$meal) { return response()->json(['error' => 'meal_not_found', 'error_details' => 'Maaltijd bestaat niet'], 404); } // Create a new registration $registration = new Registration(['name' => e(Request::input('name')), 'handicap' => Request::input('handicap') != '' ? e(Request::input('handicap')) : null]); $registration->confirmed = true; $registration->meal_id = $meal->id; if ($registration->save()) { Log::info("Aangemeld: administratie|{$registration->id}|{$registration->name}"); return view('meal/_registration', ['registration' => $registration]); } else { return response()->json(['error' => 'create_registration_admin_unknown_error', 'error_details' => 'Deze registratie kon niet opgeslagen worden, reden onbekend.'], 500); } }
/** * Removes a meal * @param int $id the id of the meal to remove * @return Redirect */ public function verwijder($id) { // Find the meal $meal = Meal::find($id); if (!$meal) { \App::abort(404, "Maaltijd niet gevonden"); } // Store the name of the meal for usage in the flash message $date = (string) $meal; // Send an e-mail to the registrations for confirmation \App\Http\Helpers\Mailer::mealIsDestroyedEmail($meal); // Remove all guests foreach ($meal->registrations()->get() as $registration) { if ($registration->email !== null) { $registration->delete(); } } // Remove the meal $meal->delete(); // Update user Flash::set(Flash::SUCCESS, "Maaltijd op {$date} verwijderd. Alle aanmeldingen zijn gemaild met een bevestiging."); \Log::info("Maaltijd verwijderd: {$date}"); return \Redirect::to('/administratie'); }
/** * Unsubscribe a user from a meal * @return JSON */ public function afmelden() { // Find the meal $meal = Meal::find((int) Request::input('meal_id')); if (!$meal) { return response()->json(['error' => 'meal_not_found', 'error_details' => 'De maaltijd bestaat niet'], 404); } // Check if the meal is still open if (!$meal->open_for_registrations()) { return response()->json(['error' => 'meal_deadline_expired', 'error_details' => 'De aanmeldingsdeadline is verstreken'], 400); } // Find the registration data $user = OAuth::user(); $registration = $user->registrationFor($meal); if (!$registration) { return response()->json(['error' => 'no_registration', 'error_details' => 'Je bent niet aangemeld voor deze maaltijd'], 404); } // Destroy the registration $id = $registration->id; $name = $registration->name; $registration->delete(); \Log::info("Afgemeld {$registration->name} (ID: {$registration->id}) voor {$meal} (ID: {$meal->id}) door {$user->name} (ID: {$user->id})"); return response(null, 200); }