<commit_before><?php

namespace App\Http\Controllers;

use App\User;                           // to use the User class
use App\Admin;                          // to use the Admin class
use App\Submission;                     // to use the Submission class
use App\Question;                       // to use the Question class
use App\Score;                          // to use the Score class


use Validator;                          // to use the Validator functions to validate the user input

use Illuminate\Http\Request;
                                        // to use the request function
use App\Http\Requests;

use Illuminate\Support\Facades\Auth;    // to use predefined auth process

use App\Http\Controllers\Controller;    // to use the Controller class

use DB;                                 // to acess to the database

use App\Http\Controllers\View;          // to acess the views functions

class QuizController extends Controller
{
    private $NumberOfQuestions = 20;            //keep it same as the $NumberOfQuestions mentioned in migrations

    // function to display quiz response form
    public function DisplayForm (Request $request)
    {
      $user = Auth::user();           // get the user details;

      return View('question_form',[
                      'DangerMessage' => 'Be careful with your clicks Once selected it can\'t be changed',
                      'WarningMessage' => 'You can\'t Change the response once submitted',
                      'user' => $user,
                      'NumberOfQuestions' => $this->NumberOfQuestions,
                    ]);
    }

    // function to record the user response
    public function AddQuizResponse (Request $request)
    {

      $validator = Validator::make($request->all(), [
                'key' => 'required|max:255',
          ]);
          // if validation fails send back to register page
      if ($validator->fails())
        {        return redirect('/questions')
                          ->withErrors($validator)
                          ->withInput();
        }
        $sub = new Submission;
        $sub->uid = Auth::user()->id;
        $sub->key = $request->key;

        for ($i=1; $i <= $this->NumberOfQuestions ; $i++)
        {
          $a='question'.$i;
          //echo "$a";
          //echo $request->$a;
          $sub->$a = $request->$a;
        }

        $sub->save();

        if( !($sub->save()) )         // redirect to the success page with error message
          return view('success',[
                      'message' => 'I am not able to accept your Response now <br> Contact admin right now',
                      'level' => 'danger',
                      ]);

        // now calaculate the user score
        $CorrectResponse=0;
        $IncorrectResponse=0;
        $NotAttempt=0;
        $submittedanswer = Submission::where('uid',Auth::user()->id)->get();
        $answer = Question::where('key', $submittedanswer[0]->key)->get();

        for ($i=1; $i <= $this->NumberOfQuestions ; $i++)
        {
          $a='question'.$i;
          if($submittedanswer[0]->$a == NULL)
            $NotAttempt++;
          elseif($answer[0]->$a==$submittedanswer[0]->$a)
            $CorrectResponse++;
          else
            $IncorrectResponse++;
        }<commit_msg>  automatic redirect to home page after admin registration  	modified:   app/Http/Controllers/QuizController.php<commit_after><?php

namespace App\Http\Controllers;

use App\User;                           // to use the User class
use App\Admin;                          // to use the Admin class
use App\Submission;                     // to use the Submission class
use App\Question;                       // to use the Question class
use App\Score;                          // to use the Score class


use Validator;                          // to use the Validator functions to validate the user input

use Illuminate\Http\Request;
                                        // to use the request function
use App\Http\Requests;

use Illuminate\Support\Facades\Auth;    // to use predefined auth process

use App\Http\Controllers\Controller;    // to use the Controller class

use DB;                                 // to acess to the database

use App\Http\Controllers\View;          // to acess the views functions

class QuizController extends Controller
{
    private $NumberOfQuestions = 20;            //keep it same as the $NumberOfQuestions mentioned in migrations

    // function to display quiz response form
    public function DisplayForm (Request $request)
    {
      $user = Auth::user();           // get the user details;

      return View('question_form',[
                      'DangerMessage' => 'Be careful with your clicks Once selected it can\'t be changed',
                      'WarningMessage' => 'You can\'t Change the response once submitted',
                      'user' => $user,
                      'NumberOfQuestions' => $this->NumberOfQuestions,
                    ]);
    }

    // function to record the user response
    public function AddQuizResponse (Request $request)
    {

      $validator = Validator::make($request->all(), [
                'key' => 'required|max:255',
          ]);
          // if validation fails send back to register page
      if ($validator->fails())
        {        return redirect('/questions')
                          ->withErrors($validator)
                          ->withInput();
        }
        $sub = new Submission;
        $sub->uid = Auth::user()->id;
        $sub->key = $request->key;

        for ($i=1; $i <= $this->NumberOfQuestions ; $i++)
        {
          $a='question'.$i;
          //echo "$a";
          //echo $request->$a;
          $sub->$a = $request->$a;
        }

        $sub->save();

        if( !($sub->save()) )         // redirect to the success page with error message
          return view('success',[
                      'message' => 'I am not able to accept your Response now <br> Contact admin right now',
                      'level' => 'danger',
                      ]);

        // now calaculate the user score
        $CorrectResponse=0;
        $IncorrectResponse=0;
        $NotAttempt=0;
        $submittedanswer = Submission::where('uid', Auth::user()->id)->get();
        $answer = Question::where('key', $submittedanswer[0]->key)->get();

        for ($i=1; $i <= $this->NumberOfQuestions ; $i++)
        {
          $a='question'.$i;
          if($submittedanswer[0]->$a == NULL)
            $NotAttempt++;
          elseif($answer[0]->$a==$submittedanswer[0]->$a)
            $CorrectResponse++;
          else
            $IncorrectResponse++;
        }
{'fraction_non_alphanumeric': 0.12118947997609085, 'fraction_numerical': 0.0041841004184100415, 'mean_word_length': 1.611392898946547, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4540194', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1677, 'n_words': 511}