Example #1
0
 public function aanmeldenAnoniem()
 {
     // Find the meal
     $meal = Meal::find((int) Request::input('meal_id'));
     if (!$meal) {
         return response()->json(['error' => 'meal_not_found', 'error_details' => 'De maaltijd waarvoor je je probeert aan te melden 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);
     }
     // Validate input data
     $validator = \Validator::make(Request::all(), ['email' => ['email', 'required'], 'name' => ['required']], ['name.required' => 'Je moet je naam invullen', 'email.required' => 'Je moet je e-mailadres invullen', 'email.email' => 'Het ingevulde e-mailadres is ongeldig']);
     if (!$validator->passes()) {
         return response()->json(['error' => 'input_invalid', 'error_details' => 'Naam of e-mailadres niet ingevuld of ongeldig'], 400);
     }
     // Create registration
     $registration = new Registration(['name' => Request::get('name'), 'email' => Request::get('email'), 'handicap' => Request::get('handicap', null), 'confirmed' => false]);
     $registration->meal_id = $meal->id;
     if ($registration->save()) {
         \Log::info("Aangemeld: {$registration->id}|{$registration->name}");
         // Send email for confirmation
         \App\Http\Helpers\Mailer::confirmationEmail($registration);
         return response(null, 200);
     } else {
         \Log::error("Aanmelding mislukt, onbekend");
         return response()->json(['error' => 'unknown', 'error_details' => 'unknown_internal_server_error'], 500);
     }
 }
Example #2
0
 /**
  * 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');
 }