Ejemplo n.º 1
0
 public function save($id2, Request $request)
 {
     $id = urldecode($id2);
     //$question=DB::select('select * from questions where question = :id',['id'=>$id]);
     $question = question::where('question', $id)->get()->first();
     // $question->question_answer()->create(["user_id" => Auth::user()->id],$request->all());
     $answer = new answer();
     $answer->question = $question->question;
     $answer->user_id = Auth::user()->id;
     $answer->answer = $request['answer'];
     $answer->save();
     return redirect()->route('answer', ['question' => urlencode($id2)]);
 }
Ejemplo n.º 2
0
 public function display($id)
 {
     //echo ($id);
     $id = urldecode($id);
     $question = question::where('question', $id)->get()->first();
     $topic = topic::where('id', $question->topic_id)->get()->first();
     $answer = answer::where('question', $id)->get();
     if ($answer !== null) {
         $name = DB::select('select name, users.id,answer, question, preffered, upvoted , downvoted from users inner join answers on users.id=answers.user_id');
         return view('show.answer', compact('question', 'topic', 'name'));
         //   return $answer;
     } else {
         return view('show.answer', compact('question', 'topic'));
     }
     //return $id;
 }
Ejemplo n.º 3
0
 public function saveanswer(Request $request)
 {
     $input = $request->except('_token');
     if (empty($input['useranswer'])) {
         // If user not given particular question answer than set boolean value 0
         $ans_yes_not = "0";
         $useranswer = "null";
     } else {
         if (!empty($input['useranswer'])) {
             // If user not given particular question naswer than set boolean value 1
             $ans_yes_not = "1";
             $useranswer = $input['useranswer'];
         }
     }
     // This condition is run when user click on Finish Exam button
     if (isset($_POST['finishexam'])) {
         $data = new user_ans_log();
         $data->user_id = \Auth::id();
         $data->exam_id = $request->examid;
         $data->que_id = $request->questionid;
         $data->answer = $ans_yes_not;
         $data->user_answer = $useranswer;
         $data->exam_date = date("Y/m/d");
         $exam_id = $request->examid;
         $user_id = \Auth::id();
         //
         // This query will find out how many questions answer given by users.
         $data = user_ans_log::where('user_id', $user_id)->where('exam_id', $exam_id)->get();
         foreach ($data as $val) {
             $user_answer[] = $val->user_answer;
         }
         // This query will find out the correct answer set by the examiner
         $data1 = question::where('exam_id', $exam_id)->get();
         $check_question_answer = count($data1);
         foreach ($data1 as $val) {
             $correct_answer[] = $val->correct_ans;
         }
         // This query will findout how many mark specify per question
         $perquestion_mark = exam::where('id', $exam_id)->get();
         // Here check the total number of correct answer given by the user
         for ($i = 0; $i < $check_question_answer; $i++) {
             if ($user_answer[$i] == $correct_answer[$i]) {
                 $count[] = $i;
             }
         }
         $marks = count($count) * $perquestion_mark[0]['mark_per_que'];
         $passing_mark = $perquestion_mark[0]['passing_marks'];
         $total_marks = $perquestion_mark[0]['total_question'] * $perquestion_mark[0]['mark_per_que'];
         $result = exam::where('id', $exam_id)->get();
         return view('user.showresult', compact('result'))->with('examdate', date("d/m/Y"))->with('marks', $marks)->with('passing_mark', $passing_mark)->with('total_marks', $total_marks);
     }
     $data = new user_ans_log();
     $data->user_id = \Auth::id();
     $data->exam_id = $request->examid;
     $data->que_id = $request->questionid;
     $data->answer = $ans_yes_not;
     $data->user_answer = $useranswer;
     $data->exam_date = date("Y/m/d");
     $data->save();
     $total_size = count(session()->get('id'));
     $arr[] = session()->get('id');
     if ($total_size > 1) {
         if ($request->session()->has('abc')) {
             if (session()->get('abc') < $total_size) {
                 $nextquestionid = session()->get('abc');
                 $result = question::where('id', $nextquestionid)->get();
                 session(['abc' => $nextquestionid + 1]);
                 return view('user.displayexam', compact('result'));
             } else {
                 $lastquestionid = session()->get('abc');
                 $result = question::where('id', $lastquestionid)->get();
                 session()->forget('abc');
                 session()->forget('current_questionid');
                 return view('user.displayexam', compact('result'))->with('lastquestionid', $lastquestionid);
             }
         } else {
             if (!$request->session()->has('abc')) {
                 session(['current_questionid' => $arr[0][0]]);
                 $nextquestionid = session()->get('current_questionid') + 1;
                 session(['current_questionid' => $nextquestionid]);
                 $result = question::where('id', $nextquestionid)->get();
                 session(['abc' => session()->get('current_questionid') + 1]);
                 return view('user.displayexam', compact('result'));
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function destroy($id)
 {
     $result = question::destroy($id);
     if ($result > 0) {
         Flash::success('Question successfully deleted');
         return redirect()->back();
     }
 }
Ejemplo n.º 5
0
		background-image: url("real.jpg");
	}
	.row
	{ font-size: 20px;
    }
	</style>
</head>	
<?php 
$answers = \App\answer::where('author_id', '=', $_SESSION["user"])->get();
$values = [];
$k = 0;
foreach ($answers as $answer) {
    $values[$k] = $answer->ques_id;
    $k++;
}
$question = \App\question::where('author', '!=', $_SESSION["user"])->whereNotIn('id', $values)->get(['id', 'question', 'opt1', 'opt2', 'opt3', 'opt4', 'points']);
echo '
        <div class="jumbotron">
  <div class="container">
    <h1>THE OFFICIAL QUIZ PAGE</h1> 
    <p>The questions present below are the questions submitted by other users. </p>     
    <p>The users have two options.
       Either they can play the quiz or
       they can submit a question of their own. </p>
    <p>The user score will be updated and stored dynamically. </p>
    <p>So what are you waiting for? Go Ahead. GOOD LUCK  </p>
    <p>Interested in submitting a tough question to squeeze your opponents? Click Submit questions.</p>
     </div>
   </div>

';
Ejemplo n.º 6
0
   <script>
  window.location="' . url("/") . '";
  </script>
  
  ';
} else {
    include 'navbar.php';
    $answer = \App\answer::where('ques_id', '=', $quesid)->where('author_id', '=', $_SESSION["user"])->get();
    if (count($answer)) {
        echo '
		 <div class="row">
		 <div class="col-sm-2 col-xs-2 " ></div>
		 <div class="alert alert-info col-sm-8 col-xs-8 text-center" > <strong>Question you are trying to answer is already answered</strong></div>
		 </div>';
    } else {
        $question = \App\question::where('id', '=', $quesid)->first();
        if ($ans == $question->correct) {
            echo '
		 <div class="row">
		 <div class="col-sm-2 col-xs-2 " ></div>
		 <div class="alert alert-success col-sm-12 col-xs-8 text-center" > <strong>Right Answer! ' . $question->points . ' points added to your score.</strong></div>
		 <div class="alert alert-success col-sm-12 col-xs-8 text-center" > <strong>Keep going. Continue the same form.</strong></div>
		 </div>';
            $account = \App\account::find($_SESSION["user"]);
            $account->score = $account->score + $question->points;
            $account->save();
        } else {
            echo '
		 <div class="row">
		 <div class="col-sm-2 col-xs-2 " ></div>
		 <div class="alert alert-danger col-sm-12 col-xs-8 text-center" > <strong>Wrong Answer! Sorry, ' . $question->points . ' points has been deducted</strong></div>