Beispiel #1
0
 public function schedule(User $user, FormDefinition $form)
 {
     try {
         if ($form->group()->first()->isCreator($user->id) || $form->group()->first()->isAdmin($user->id)) {
             return true;
         } else {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
 }
 public function updateJudges(FormDefinition $form, Request $request)
 {
     $this->validate($request, ['judges' => 'required|array', 'judges.*' => 'exists:users,id']);
     $error_list = new Collection();
     $updated_judges = new Collection();
     foreach ($request->input('judges') as $new_judge_id) {
         try {
             $judge = $form->group()->first()->adjudicatorUsers()->findOrFail($new_judge_id);
             $updated_judges->put($judge->id, $judge);
         } catch (\Exception $e) {
             $error_list->push("Judge with User ID of " . $new_judge_id . " not found and thus not added!");
         }
     }
     $current_judges = $form->judges()->get();
     foreach ($current_judges as $cur_judge) {
         if (!$updated_judges->has($cur_judge->id)) {
             $form->judges()->detach($cur_judge->id);
         }
         $updated_judges->forget($cur_judge->id);
     }
     foreach ($updated_judges as $new_judge) {
         $form->judges()->save($new_judge);
     }
     if ($error_list->count() > 0) {
         $error_string = "";
         foreach ($error_list as $error) {
             $error_string = $error_string . "<br>{$error}";
         }
         flash()->overlay("Something went wrong, and not all the judges may have been added correctly.  Double check the results." . $error_string, "Error");
         return redirect()->back();
     } else {
         flash()->overlay("The judges have been added to the form", "Form Updated");
         return redirect()->back();
     }
 }