Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $maxParticipantID = Participant::count();
     $maxTrialID = Trial::count();
     for ($i = 0; $i < 1000; $i++) {
         $p = new Participation();
         $p->participant_id = rand(1, $maxParticipantID);
         $p->trial_id = rand(1, $maxTrialID);
         $p->save();
     }
     //
 }
Пример #2
0
 public function postPlay(Request $request, $id)
 {
     $qcm = Qcm::findOrFail($id);
     if (Auth::user()->hasPlayed($qcm)) {
         Session::push('messages', 'danger|Vous ne pouvez pas participer deux fois à ce QCM');
         return Redirect::route('qcm::index');
     }
     $ret = DB::transaction(function () use($request, $qcm) {
         $datas = $request->all();
         $questions = $qcm->questions;
         $questionsCount = $questions->count();
         $validsAnswersCount = count($datas['valids_answers']);
         if ($questionsCount != $validsAnswersCount) {
             Session::push('messages', 'danger|Le nombre de questions est différent du nombre de vos réponses');
             return Redirect::to(URL::previous());
         }
         foreach ($questions as $k => $question) {
             $validAnswer = $datas['valids_answers'][$k];
             $answer = $question->answers->get($validAnswer);
             if ($answer == null) {
                 Session::push('messages', 'danger|???');
                 return Redirect::to(URL::previous());
             }
             Participation::create(['user_id' => Auth::id(), 'qcm_id' => $qcm->id, 'question_id' => $question->id, 'answer_id' => $answer->id]);
         }
         return true;
     });
     if ($ret) {
         Session::push('messages', 'success|Votre participation a bien été prise en compte');
         return Redirect::route('qcm::index');
     } else {
         Session::push('messages', 'danger|Il y a eu un soucis lors de votre participation');
         return Redirect::to(URL::previous());
     }
 }
Пример #3
0
 public function deleteParticipation(Request $request)
 {
     Participation::destroy($request->input('id'));
     return;
 }