Exemplo n.º 1
0
 public function round($id)
 {
     $utoken = session('user_id');
     $maxround = leaderboard::where('user_id', $utoken)->select('round_id')->first();
     $maxround = $maxround['round_id'];
     $cc = leaderboard::where('round_id', '>', $id)->count();
     $quesquery = solved::where(['user_token' => $utoken, 'round_id' => $id])->select('question_no')->get();
     $totalques = quiz::where('round', $id)->select('question_id', 'position')->get();
     $rquery = roundans::where('round_id', $id)->select('question', 'round_name')->first();
     $rq = $rquery['question'];
     $rname = $rquery['round_name'];
     $qdone = array();
     $i = 0;
     foreach ($quesquery as $ques) {
         $qdone[$i] = $ques['question_no'];
         $i++;
     }
     $i = 0;
     $i2 = 0;
     $parray = array();
     $tques = array();
     $totpos = array();
     $location = array();
     foreach ($totalques as $t) {
         $tques[$i2] = $t['question_id'];
         $totpos[$i2] = $t['position'];
         if (in_array($tques[$i2], $qdone)) {
             $parray[$i] = explode(",", $t['position']);
             $location[$i] = $t['position'];
             $i++;
         }
         $i2++;
     }
     if ($id > $maxround || $id < 1) {
         return redirect(url('/round/' . $maxround));
     } else {
         if ($id > $this->mxround) {
             return view('quiz/winner')->with('id', $id);
         } else {
             return view('quiz/round')->with(['id' => $id, 'qdone' => $qdone, 'pos' => $location, 'totalques' => $tques, 'totalpos' => $totpos, 'rq' => $rq, 'rname' => $rname, 'c' => $cc, 'locations' => $parray]);
         }
     }
 }