/**
  * This function is called when a student starts the test.
  * If the test is already started, load_questions() should be called
  * else a new set of questions will be loaded into memory.
  * @return question
  */
 public function get_questions()
 {
     $quiz = Quiz::find($this->quiz_id);
     $this->my_questions = $quiz->generate_questions();
     $this->store_my_questions();
     return $this->my_questions[0];
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $quiz = Quiz::findOrFail($request->get('quiz_id'));
     //calculamos la nota
     $value_evaluation = $quiz->evaluation->value;
     $max_question = $quiz->evaluation->max_question;
     $min_value = $quiz->evaluation->min_value;
     $answers = $quiz->answers;
     /*
      * Respuestas Correctas
      */
     $correct_answers = 0;
     foreach ($answers as $answer) {
         if ($answer->correct == 1) {
             $correct_answers++;
         }
     }
     $quiz_result = $value_evaluation / $max_question * $correct_answers;
     $quiz_approval = $quiz_result * 100 / $value_evaluation;
     if ($quiz_approval < $min_value) {
         $quiz->status = 'rejected';
     } else {
         $quiz->status = 'approved';
     }
     $quiz->save();
     $result = new Result();
     $result->fill($request->all());
     $result->correct_answers = $correct_answers;
     $result->quiz_result = $quiz_result;
     $result->quiz_approval = $quiz_approval;
     $result->user_id = Auth::id();
     $result->save();
     return redirect()->route('results.show', $result);
 }
 /**
  * Get the response for a forbidden operation.
  *
  * @return \Illuminate\Http\Response
  */
 public function forbiddenResponse()
 {
     $quiz = Quiz::findOrFail($this->quiz_id);
     $message = trans('messages.the_test_time_has_expired');
     Flash::warning($message);
     return redirect()->route('units.show', $quiz->unit->id);
 }
Example #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(QuestionRequest $request)
 {
     $quiz = Quiz::findOrfail($request->input('quiz_list'));
     $question = $quiz->questions()->create($request->all());
     flash()->success('New Question has been created!');
     return redirect('questions');
 }
Example #5
0
 /**
  * Responds to request to GET /question/add/{quiz_id}
  */
 public function getQuestionAdd($quiz_id)
 {
     $quiz = Quiz::find($quiz_id);
     $question = new Question();
     $question->quiz_id = $quiz_id;
     $question->save();
     return redirect('/question/edit/' . $question->id);
 }
Example #6
0
 /**
  * Responds to request to GET /answer/add/{question_id}
  */
 public function getAnswerAdd($question_id)
 {
     $question = Quiz::find($question_id);
     $answer = new Answer();
     $answer->question_id = $question_id;
     $answer->save();
     return redirect('/answer/edit/' . $answer->id);
 }
Example #7
0
 /**
  *
  * Create a quiz
  **/
 public function createNewQuiz(Request $req)
 {
     $data = ['quiz_name' => $req->input('quiz_name')];
     $this->validate($req, ['quiz_name' => 'required']);
     if (Quiz::create($data)) {
         return redirect('admin/quiz/all');
     }
 }
Example #8
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, QuizRequest $request)
 {
     $quiz = Quiz::findOrFail($id);
     $quiz->category_id = $request->input('cat_list');
     $quiz->update($request->all());
     flash()->success('New Quiz has been updated!');
     return redirect('quizzes');
 }
 public static function questionDelete($id)
 {
     $idDecoded = intval(base64_decode($id));
     $quizs = Quiz::all();
     $record = $quizs->find($idDecoded);
     $record->delete();
     echo '<script>window.location=\'http://localhost:69/QuizFinal/public/AdminEditQuiz\'</script>';
 }
Example #10
0
 public function getQuiz($id)
 {
     $quizzes = Quiz::where('quiz_id', (int) $id)->with('user')->with('questions')->with('results')->with('media')->get();
     $api = new ApiHandler();
     $api->enableSideloading();
     if ($quizzes->count() > 0) {
         $api->setCollection($quizzes);
     } else {
         $api->setState(404, 'not_found');
     }
     return $api->send();
 }
Example #11
0
 public function getSingleQuiz(Request $req, $id)
 {
     $quiz = Quiz::find($id);
     $question_ids = \DB::table('question_categories')->select('question_id')->where('quiz_id', '=', $id)->get();
     foreach ($question_ids as $question) {
         $options[$this->getQuestion($question->question_id)][] = \DB::table('options')->where('question_id', '=', $question->question_id)->select('id', 'option', 'question_id')->get();
     }
     // echo '<pre>';
     // print_r($options);
     // echo '</pre>';
     //return $options;
     return view('quiz')->with(['questions' => $options, 'quiz' => $quiz]);
 }
Example #12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('quizzes')->truncate();
     $quiz = new Quiz();
     $quiz->user_id = 1;
     $quiz->media_id = 1;
     $quiz->type = 'classic';
     $quiz->title = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam posuere ut lorem vitae fermentum';
     $quiz->content = 'Praesent pellentesque leo enim, ut lobortis mauris egestas et. Quisque sit amet vehicula lectus. Proin venenatis velit ac lacinia porttitor. Mauris at quam dolor. Proin vitae turpis in ligula finibus auctor. Vivamus cursus dolor a erat eleifend, et scelerisque neque suscipit. Nulla';
     $quiz->state_visibility = 1;
     $quiz->save();
     $quiz = new Quiz();
     $quiz->user_id = 1;
     $quiz->media_id = 2;
     $quiz->type = 'classic';
     $quiz->title = 'Cras cursus tempus lectus ac finibus ?';
     $quiz->content = 'Maecenas sollicitudin, nunc in dignissim ultrices, nibh eros pharetra leo, et facilisis urna sem et erat. Vivamus eget ultricies nisi';
     $quiz->state_visibility = 1;
     $quiz->save();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Example #13
0
 public function quesvalidate(Request $request, $qid)
 {
     $quiz = Quiz::where('question_id', $qid)->first();
     $ans = $request->input('ansq');
     $utoken = session('user_id');
     if (strcasecmp($ans, $quiz['answer']) == 0) {
         $rid = $quiz['round'];
         solved::firstOrCreate(['user_token' => $utoken, 'question_no' => $qid, 'round_id' => $rid]);
         return redirect(url('/round/' . $rid));
     } else {
         return view('quiz/ques')->with(['qid' => $qid, 'ques' => $quiz['question'], 'error' => 'Wrong Answer']);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function show($id)
 {
     $quiz = Quiz::findOrFail($id);
     $result = Result::where('quiz_id', $quiz->id)->first();
     if (!$result) {
         $quiz->status = 'rejected';
         $quiz->save();
         $result = new Result();
         $result->quiz_id = $quiz->id;
         $result->user_id = $quiz->user_id;
         $result->save();
     }
     return view('teacher.results.show')->with('result', $result)->with('title', trans('titles.results'));
 }
Example #15
0
 public function getAllAvailableQuizzes()
 {
     $today = Carbon\Carbon::now();
     $today = Carbon\Carbon::create($today->year, $today->month, $today->day, 0, 0, 0);
     $quizzes = Quiz::where('valid_from', '<=', $today)->where('valid_to', '>=', $today)->get();
     foreach ($quizzes as $quiz) {
         $result = QuizResults::where('quiz_id', '=', $quiz->id)->where('user_id', '=', \Auth::user()->id)->get();
         if (!empty($result)) {
             $quiz->results = [];
             $quiz->results = $result;
         }
     }
     //        $quizzes = Quiz::where('valid_from','<=',$today)
     //            ->where('valid_to','>=',$today)->leftJoin('results', function($join) {
     //                $join->on('quizzes.id','=','results.quiz_id')->where('results.user_id','=',\Auth::user()->id);
     //            })->get();
     return $quizzes;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     // $this->call(ClassTableSeeder::class);
     //Optional just to clear table
     // DB::table('answers')->delete();
     // DB::table('questions')->delete();
     // DB::table('classes')->delete();
     // DB::table('users')->delete();
     $student1 = User::create(['name' => 'Scotty Gomez', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $student2 = User::create(['name' => 'Misha Dowd', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $lecturer = User::create(['name' => 'Dr. Andre Chen', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'lecturer']);
     $this->command->info('User Created!');
     $course = Course::create(['name' => 'Math', 'term' => 'Fall2020', 'lecturer_id' => $lecturer->id]);
     $this->command->info('Course Created!');
     $quiz = Quiz::create(['course_id' => $course->id, 'description' => 'A Quiz to Test Your Might!', 'quizTime' => '20', 'startDate' => '10.29.2015', 'endDate' => '10.30.2015']);
     $this->command->info('Quiz Created!');
     //Questions
     $q = Question::create(['prompt' => 'What is the sqare root of 4?', 'difficulty' => 'easy']);
     $q1 = Question::create(['prompt' => 'What is 2 X 3?', 'difficulty' => 'easy']);
     $this->command->info('2 Questions Created!');
     //Answers
     $a = Answer::create(['text' => '6', 'image' => NULL]);
     $a1 = Answer::create(['text' => '2', 'image' => NULL]);
     $a2 = Answer::create(['text' => '6', 'image' => NULL]);
     $a11 = Answer::create(['text' => '5', 'image' => NULL]);
     $this->command->info('All 4 Answers Created!');
     // Adding User to Course
     $course->users()->sync([$student1->id, $student2->id]);
     // Syncing Quiz to Questions
     $quiz->questions()->sync([$q->id, $q1->id]);
     // Syncing (Binding Qustion to Answer)
     $q->answers()->sync([$a->id, $a1->id]);
     $q1->answers()->sync([$a2->id, $a11->id]);
     $this->command->info('Everything Created and Linked!');
     Model::reguard();
 }
Example #17
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $users = DB::table('users')->where('access_id', '3')->get();
     $quiz = Quiz::all();
     return view('createClass')->with(compact('users'))->with(compact('quiz'));
 }
Example #18
0
 public function addExaminee(Quiz $quiz, Request $request)
 {
     $quiz->examinees()->detach();
     foreach ($request->get('examinees', []) as $id) {
         $quiz->examinees()->attach($id);
     }
     return redirect()->back();
 }
 public function take_quiz()
 {
     $scoreCard = ScoreCard::find(session("scorecardID"));
     $questionNumber = 1;
     $first_question;
     if ($scoreCard->questions()->count() > 0) {
         $first_question = $scoreCard->load_questions();
     } else {
         $first_question = $scoreCard->get_questions();
     }
     $minutes = Quiz::find($scoreCard->quiz_id)->quiz_time;
     $date = new DateTime();
     $date->add(new DateInterval('PT' . $minutes . 'M'));
     session(['score_card' => $scoreCard, 'date' => $date, 'questionNumber' => $questionNumber]);
     return view('scorecard.take', ['question' => $first_question, 'selected_answers' => $scoreCard->selected_answers($first_question->id), 'date' => $date, 'questionNumber' => $questionNumber]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $quizzes = Quiz::paginate();
     return view('teacher.quizzes.index')->with('quizzes', $quizzes)->with('title', trans('titles.results'));
 }
 public function updateQuiz(Request $request)
 {
     $input = $request->all();
     $quiz = Quiz::find($request->quiz);
     $quiz->name = $request->name;
     $quiz->save();
     foreach ($input as $key => $value) {
         if (substr($key, 0, strlen('question')) === 'question') {
             $segments = explode("_", $key);
             $question_id = str_replace("genre", "", $segments[1]);
             $question = Question::find($question_id);
             $question->text = $value;
             $question->answer = $input['answer_' . $question_id];
             $question->save();
         }
     }
     return redirect()->back();
 }
Example #22
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  */
 protected function create(array $data)
 {
     return Quiz::create(['name' => $data['name'], 'description' => $data['description'], 'public' => $data['public'], 'owner_id' => $data['owner_id']]);
 }
 /**
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function next($id, Request $request)
 {
     $quiz = Quiz::findOrFail($id);
     $quiz->answers()->attach($request->get('answer_id'));
     return redirect()->route('quizzes.show', $quiz);
 }
Example #24
0
 public function index($id)
 {
     $quiz = \App\Quiz::find($id)->with('questions.answers')->firstOrFail();
     return $this->makeResponse('quiz.single', array('quiz' => $quiz));
 }
Example #25
0
 public function examineeTests(User $examinee)
 {
     $user = auth()->user();
     if ($user->isExaminer()) {
         $quizzes = Quiz::with('tests')->where('user_id', $user->id)->lists('id');
         $tests = $examinee->tests()->whereIn('quiz_id', $quizzes)->latest()->get();
     } else {
         $tests = $examinee->tests()->latest()->get();
     }
     return view('tests.byexaminee', compact('tests', 'examinee'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Quiz::destroy($id);
     return redirect('/dashboard');
 }
Example #27
0
 /**
  * Responds to requests to POST /quizzes/{id}
  */
 public function postQuizzesResult($id, Request $request)
 {
     // delete zero grade for validation
     $grade = Grade::where('quiz_id', $id)->where('user_id', Auth::user()->id)->first();
     $grade->taken = FALSE;
     $grade->save();
     $request->all();
     // get quiz for validation
     $quiz = Quiz::find($id);
     // custom message
     $messages = array('required' => 'You must answer all questions!');
     // make sure each question that is part of the quiz is in the request
     foreach ($quiz->question as $question) {
         $this->validate($request, ['answer_for_question.' . $question->id => 'required'], $messages);
     }
     // Grades quiz
     $correct_answers = 0;
     foreach ($request['answer_for_question'] as $answer) {
         $correct = Answer::find($answer);
         if ($correct->correct) {
             $correct_answers++;
         }
     }
     $score = $correct_answers / $quiz->numberOfQuestions() * 100;
     // store grade in grades_table
     $grade = Grade::where('quiz_id', $id)->where('user_id', Auth::user()->id)->first();
     $grade->grade = $score;
     $grade->taken = TRUE;
     $grade->save();
     return view('quiz.result')->with('quiz', $quiz)->with('score', $score);
 }
Example #28
0
 /**
  * Responds to request to GET /delete/confirm/{id}
  */
 public function getConfirmDelete($id)
 {
     $quiz = Quiz::find($id);
     $quiz->delete();
     \Session::flash('flash_message', 'Quiz deleted!');
     return redirect('/edit/quizzes');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  Quiz $quiz
  * @return \Illuminate\Http\Response
  */
 public function destroy(Quiz $quiz)
 {
     $quiz->delete();
     return redirect()->action('QuizzesController@index');
 }
    $scoreCard = ScoreCard::find(1);
    // $answers = ScoreCard::find(1)->answer_questions()->get();
    $answers = $scoreCard->answer_questions()->get();
    echo $scoreCard->user->first_name;
    //Get Name
    echo "<br>";
    foreach ($answers as $a) {
        echo $a->id;
        echo "<br>";
    }
    echo "<br>";
    $users = User::all();
    foreach ($users as $u) {
        $s = $u->scoreCards()->get();
        echo "User: "******"<br>";
        foreach ($s as $c) {
            echo $c->id;
            echo "<br>";
            # code...
        }
    }
});
Route::get('/test/genQ', function () {
    return Quiz::find(2)->generate_questions();
});
//[OK]
Route::get('/{user}', function ($user) {
    return redirect('/');
});