コード例 #1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     if (!Auth::check()) {
         return redirect('home')->with('message', "Veuillez d'abord vous connecter");
     }
     $question = Question::find($id);
     if (is_null($question)) {
         abort(404);
     }
     $total_questions = Question::count();
     $user = Auth::user();
     $total_questions_replied = $user->questionsReplied()->count();
     $total_questions_replied_percent = round($total_questions_replied / $total_questions * 100);
     // Get the current user that will be the origin of our operations
     // Get ID of a User whose autoincremented ID is less than the current user, but because some entries might have been deleted we need to get the max available ID of all entries whose ID is less than current user's
     $previousQuestionID = Question::where('id', '<', $question->id)->max('id');
     // Same for the next user's id as previous user's but in the other direction
     $nextQuestionID = Question::where('id', '>', $question->id)->min('id');
     $replies = $question->getChoices();
     // if user already replied to this particular question
     if ($question->getAnswer()) {
         $replies[$question->getAnswer()]['checked'] = true;
         $question->replied = true;
     }
     return view('questions.show', compact('question', 'previousQuestionID', 'nextQuestionID', 'replies', 'total_questions', 'total_questions_replied', 'total_questions_replied_percent'));
 }
コード例 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $question = Question::where('year', $year)->where('month', $month)->where('day', $day)->first();
     if (count($question)) {
         $leagues = League::where('year', $question->leagueYear())->where('month', $question->leagueMonth())->get();
         foreach ($leagues as $key => $league) {
             $players = json_decode($league->users);
             foreach ($players as $key => $player) {
                 $user = User::find($player);
                 if ($user->deadline_reminder && $user->active) {
                     $answers = Answer::where('question_id', $question->id)->where('user_id', $user->id)->first();
                     if (!count($answers)) {
                         Mail::send('emails.deadlinereminder', [], function ($message) use($user) {
                             $message->from('*****@*****.**', 'Liga Quiz Portugal');
                             $message->to($user->email, $user->fullName())->subject('Quiz ainda não respondido');
                         });
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $student = Auth::user();
     $course_id = $request["course_id"];
     $questions = Question::where('course_id', '=', $course_id)->get();
     if (count($questions) <= 0) {
         Flash::error('There was a problem processing your request.');
         return redirect()->route('registration.index');
     }
     $question_count = 0;
     $passed_count = 0;
     foreach ($questions as $que) {
         $question_count = $question_count + 1;
         $keyword_found = 0;
         $answer_array = explode(',', $que->answers);
         $students_reply_array = explode(' ', $request[$que->id]);
         $students_reply = $request[$que->id];
         foreach ($answer_array as $keyword) {
             if (strpos($students_reply, $keyword) !== false) {
                 $keyword_found = $keyword_found + 1;
             }
         }
         if ($keyword_found == count($answer_array)) {
             $passed_count = $passed_count + 1;
         }
     }
     $percent = $passed_count / $question_count * 100;
     Exam::create(['course_id' => $course_id, 'student_id' => $student->id, 'score_percentage' => $percent]);
     Flash::success('Answer sheet submitted successfully.');
     return redirect()->route('registration.index');
 }
コード例 #4
0
ファイル: ForumController.php プロジェクト: Panfen/mango
 public function getQuesitions(Request $request)
 {
     $type = $request->get('type');
     switch ($type) {
         case 0:
             $questions = Question::take(10)->get();
             break;
         case 1:
             $questions = Question::orderBy('total_answer', 'desc')->take(10)->get();
             break;
         case 2:
             $questions = Question::where('issolved', 0)->take(10)->get();
             break;
         default:
             $questions = Question::where('issolved', 1)->take(10)->get();
             break;
     }
     if ($questions) {
         foreach ($questions as &$question) {
             $question['time'] = $question->created_at->diffForHumans();
             $question['username'] = $question->user->name;
         }
         $this->setResult($questions);
         $this->succeed(true);
     } else {
         $this->setResult('questions表获取记录失败!');
         $this->fail(true);
     }
 }
コード例 #5
0
ファイル: Question.php プロジェクト: namilaRadith/AmalyaReach
 /**
  * @param $questionerId
  */
 public static function deleteQuestions($questionerId)
 {
     $question = Question::where('questioner_id', '=', $questionerId)->get();
     foreach ($question as $q) {
         $q->delete();
     }
 }
コード例 #6
0
 protected function fetchStepQuestions($step)
 {
     $questions = Question::where('step', $step)->get();
     if (empty($questions)) {
         abort(404);
     }
     return $questions;
 }
コード例 #7
0
 public function index()
 {
     $where["questions.question_type"] = 2;
     $data['public_questions'] = Question::GetActiveQuestions($where)->take(3);
     $where["questions.question_type"] = 1;
     $data['private_questions'] = Question::GetActiveQuestions($where)->take(3);
     $data['archived_questions'] = Question::where("active", 0)->get()->take(3);
     return view('home', $data);
 }
コード例 #8
0
 /**
  * Show the form for creating a new resource.
  *
  * @param Request $request
  * @return $this
  */
 public function create(Request $request)
 {
     if ($request->has('question')) {
         $questions = Question::findOrFail($request->get('question'))->unit->questions->lists('title', 'id');
     } else {
         $questions = Question::where('user_id', Auth::user()->id)->lists('title', 'id');
     }
     return view('teacher.answers.create')->with('questions', $questions)->with('title', trans('titles.create_new_answer'));
 }
コード例 #9
0
 /**
  * Get the next question link (under the same questionnaire)
  * , return result page link if this is the final question.
  */
 public function nextQuestionLink()
 {
     $next = Question::where(['questionnaire_id' => $this->questionnaire_id, 'order' => $this->order + 1])->first();
     if ($next) {
         return '/questionnaires/' . $next->questionnaire_id . '/questions/' . $next->id;
     } else {
         return '/questionnaires/' . $this->questionnaire_id . '/questions/result';
     }
 }
コード例 #10
0
 public function iresponse($project, Request $request)
 {
     $iresponseCol = Question::where('project_id', $project->id)->where('qnum', config('aio.iresponse'))->first();
     $dbraw = DB::select(DB::raw("SELECT pcode.state,answers.*,q.* \n            FROM pcode INNER JOIN results ON results.resultable_id = pcode.primaryid \n            INNER JOIN answers ON answers.status_id = results.id \n            INNER JOIN ( SELECT id,qnum FROM questions where id = '{$iresponseCol->id}') q ON q.id = answers.qid"));
     $dbGroupBy = DB::select(DB::raw("SELECT pcode.state,answers.*,q.* \n            FROM pcode INNER JOIN results ON results.resultable_id = pcode.primaryid \n            INNER JOIN answers ON answers.status_id = results.id \n            INNER JOIN ( SELECT id,qnum FROM questions where id = '{$iresponseCol->id}') q ON q.id = answers.qid GROUP BY results.id"));
     $incidents = Result::where('project_id', $project->id);
     $locations = PLocation::where('org_id', $project->org_id)->groupBy('state');
     return view('frontend.result.response-incident')->withProject($project)->withRequest($request)->withQuestion($iresponseCol)->withIncidents($incidents)->withLocations($locations)->withDbraw(collect($dbraw))->withDbGroup(collect($dbGroupBy));
 }
コード例 #11
0
ファイル: APIController.php プロジェクト: mish0501/exams
 public function QuestionGenerate(Request $request)
 {
     $class = $request->get('class');
     $subject = $request->get('subject');
     $partition = $request->get('partition');
     $questions = Question::where('class', '=', $class)->where('subject_id', '=', $subject)->where('partition_id', '=', $partition)->get();
     $questions[0]['token'] = $request->get("_token");
     return $questions;
 }
コード例 #12
0
 public static function questions()
 {
     if (Gate::allows('view_question')) {
         return Question::all();
     } elseif (Auth::check() && Gate::allows('view_own_question')) {
         return Question::where('user_id', Auth::id())->get();
     } else {
         return null;
     }
 }
コード例 #13
0
 public function search(Request $request)
 {
     // retrieve query from URL
     $q = $request->q;
     // SQL LIKE format for matching on search query:
     // %SEARCH_TERM%
     $q_query = '%' . $q . '%';
     $questions = Question::where('title', 'LIKE', $q_query)->orWhere('description', 'LIKE', $q_query)->orWhere('code', 'LIKE', $q_query)->get();
     return view('questions.search', ['q' => $q, 'questions' => $questions, 'languages' => Language::all()]);
 }
コード例 #14
0
 public function search(Request $request)
 {
     // Gets the search terms from our form submission
     $query = Request::input('search');
     $result = Question::where('title', 'LIKE', '%' . $query . '%')->orWhere('body', 'LIKE', '%' . $query . '%');
     // Paginate the questions
     $questions = $result->paginate(10);
     // returns a view and passes the view the list of questions and the original query.
     return view('search.results', compact('questions', 'query'));
 }
コード例 #15
0
 public function index()
 {
     $user = JWTAuth::parseToken()->authenticate();
     $user_id = $user->id;
     $answers = Answer::where('user_id', $user_id)->get();
     //add the question to each answer
     for ($i = 0; $i < count($answers); $i++) {
         array_add($answers[$i], 'question', Question::where('id', $answers[$i]->question_id)->get());
     }
     return response()->json(['answers' => $answers]);
 }
コード例 #16
0
 /**
  * Display the specified resource.
  *
  * @param  int  $questionnaireId
  * @param  int  $questionOrderId
  * @return \Illuminate\Http\Response
  */
 public function show($questionnaireId, $questionOrderId)
 {
     $questions = Question::where(['questionnaire_id' => $questionnaireId])->get();
     $question = Question::where(['questionnaire_id' => $questionnaireId, 'order' => $questionOrderId])->first();
     $answers = $question->answers();
     $userAnswer = $question->userAnswer();
     $previousQuestionLink = $question->previousQuestionLink();
     $nextQuestionLink = $question->nextQuestionLink();
     $nextQuestionText = $question->nextQuestionText($nextQuestionLink);
     return view('questions.show')->with(compact('questionnaireId', 'questions', 'question', 'answers', 'userAnswer', 'previousQuestionLink', 'nextQuestionLink', 'nextQuestionText'));
 }
コード例 #17
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $partition = Partition::findOrFail($id);
     $questions = Question::where('partition_id', '=', $partition->id);
     foreach ($questions->get() as $value) {
         $answers = Answer::where('question_id', '=', $value->id);
         $answers->update(['trash' => true]);
     }
     $questions->update(['trash' => true]);
     $partition->update(['trash' => true]);
     \Session::flash('flash_message', 'Разделът беше успешно преместен в кошчето!');
     return redirect()->route('admin.partition.index');
 }
コード例 #18
0
ファイル: Quiz.php プロジェクト: philipjamesk/p4
 /**
  * Return any question id's and warnings if a question does not have exactly 1 correct answer
  *
  * @return collection
  */
 public function warnings()
 {
     $warnings = new \Illuminate\Database\Eloquent\Collection();
     $questions = Question::where('quiz_id', '=', $this->id)->get();
     foreach ($questions as $question) {
         $number_of_correct_answers = $question->numberOfCorrectAnswers();
         if ($number_of_correct_answers != 1) {
             $warning = 'Question has ' . $number_of_correct_answers . ' correct answers!';
             $warnings->put($question->id, $warning);
         }
     }
     return $warnings;
 }
コード例 #19
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $questions = Question::where('required', 1)->pluck('type', 'id')->all();
     //                |->Lade Model Question
     //                        |->Hole alle Einträge und lade Sie in eine Collection
     //                                 |->Ordne die Daten anhand der ID und füge den Wert "type" hinzu.
     //                                                     |-> Gib das ganze als Array zurück
     foreach ($questions as $id => $type) {
         $typeText = $type === 0 ? 'radio_question' : 'text_question';
         $rules[$typeText . '.' . $id] = 'required';
     }
     return $rules;
 }
コード例 #20
0
ファイル: Questions.php プロジェクト: iamfaiz/lahm
 public function saveFromNested($test)
 {
     // Clear already existing questions for this particular test.
     Question::where('test_id', $test['id'])->delete();
     foreach ($test['questions'] as $question) {
         $savedQuestion = Question::create(['test_id' => $test['id'], 'title' => $question['title'], 'correct' => $question['correct']]);
         // Clear already existing options for this particular question.
         Option::where('question_id', $savedQuestion['id'])->delete();
         foreach ($question['options'] as $i => $option) {
             Option::create(['question_id' => $savedQuestion->id, 'value' => $option]);
         }
     }
 }
コード例 #21
0
 public function apply($link)
 {
     if (Auth::check()) {
         $this->info['namespace'] = "arii";
         $training = Training::where('link', $link)->first();
         $this->info['training_name'] = $training->name;
         $this->info['title'] = "Formular de aplicare | " . $this->info['title'];
         $this->info['questions'] = Question::where('training_id', $training->id)->get();
         return view('pages.quiz', ['info' => $this->info]);
     } else {
         return redirect('/cont');
     }
 }
コード例 #22
0
ファイル: Home.php プロジェクト: komphet5139/ubr
 public function questionDel(Request $request)
 {
     Question::find($request->get('id'))->delete();
     Question::where('subId', $request->get('id'))->delete();
     $log = new Log();
     $log->memberId = Auth::user()->id;
     $log->detail = 'Delete Post,' . $request->get('id');
     $log->save();
     if ($request->get('redirect') == '') {
         return redirect(route('home'));
     } else {
         return redirect(html_entity_decode($request->get('redirect')));
     }
 }
コード例 #23
0
 public function addQuestion(Request $request)
 {
     $validator = \Validator::make($request->all(), ['question' => 'required', 'answer' => 'required']);
     if ($validator->passes()) {
         $question = Question::where('question_id', $request->input('question'))->where('answer', $request->input('answer'))->first();
         if ($question) {
             $question->increment('agreements');
         } else {
             Question::create(['question_id' => $request->input('question'), 'answer' => $request->input('answer')]);
         }
         return response("OK", 200);
     }
     return response("Bad", 400);
 }
コード例 #24
0
 public function answer(Request $request, $questionId)
 {
     $this->validate($request, ['answer' => 'required']);
     $question = Question::where('id', $questionId)->firstOrFail();
     if (empty($question->answer)) {
         $question->answerer_id = Auth::user()->id;
         $question->answer = $request->answer;
         if (Auth::user()->role == 'teacher') {
             $question->approved = true;
         }
         $question->save();
     }
     return redirect(action('LessonController@show', [$question->lesson->course->slug, $question->lesson->slug]));
 }
コード例 #25
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Question::creating(function ($attributes) {
         $user = JWTAuth::parseToken()->authenticate();
         $user_id = $user->id;
         $question_exists = Question::where('user_id', $user_id)->get();
         if (!$question_exists->isEmpty()) {
             $published_questions = Question::where('user_id', $user_id)->where('is_published', true)->first();
             if ($published_questions != null) {
                 $published_questions->is_published = false;
                 $published_questions->save();
             }
         }
     });
 }
コード例 #26
0
 public function show($id)
 {
     if (Auth::user()) {
         $countryId = Auth::user()->country_id;
     } else {
         $location = GeoIPFacade::getLocation();
         $countryId = Country::where('country_code', '=', $location['isoCode'])->first()->id;
     }
     $questionCountry = QuestionsCountry::firstOrNew(array('country_id' => $countryId, 'question_id' => $id));
     $questionCountry->count++;
     $questionCountry->save();
     // Get all the blog posts
     $question = Question::where('questions.id', '=', $id)->with('answer')->first();
     return view('questions.view_question', compact('question'));
 }
コード例 #27
0
ファイル: HomeController.php プロジェクト: mish0501/exams
 public function index()
 {
     $subjects = collect(Subject::where('trash', '=', false)->get()->toArray())->groupBy('name')->count();
     $partitions = Partition::where('trash', '=', false)->count();
     $invites = Invite::count();
     $questions = Question::where('trash', '=', false)->count();
     $users = User::count();
     $trash = '';
     $testrooms = '';
     if (\Entrust::hasRole('admin')) {
         $trash = Question::where('trash', '=', true)->count() + Subject::where('trash', '=', true)->count() + Partition::where('trash', '=', true)->count() + TestRoom::where('teacher_id', '=', \Auth::user()->id)->where('trash', '=', true)->count();
     } elseif (\Entrust::hasRole('teacher')) {
         $testrooms = TestRoom::where('teacher_id', '=', \Auth::user()->id)->count();
     }
     return view('admin.welcome', ['subjects' => $subjects, 'partitions' => $partitions, 'invites' => $invites, 'questions' => $questions, 'users' => $users, 'trash' => $trash, 'testrooms' => $testrooms]);
 }
コード例 #28
0
 public function create(Request $request)
 {
     if ($request->isMethod('get')) {
         $this->data['roles'] = $this->getRoles();
         $this->data['types'] = $this->getTypes();
         $this->data['items'] = Question::where('enabled', 1)->get();
         return view('pages.question.create', $this->data);
     } elseif ($request->isMethod('post')) {
         $data = $request->all();
         if (!isset($data['helptext'])) {
             $data['helptext'] = null;
         }
         Question::create($data);
         return redirect('question');
     }
 }
コード例 #29
0
 public function updateFavoriteList(Request $request)
 {
     $data = $request->all();
     $questionResult = $data['question_id'];
     $result = explode(',', $questionResult);
     for ($i = 0; $i < count($result); $i++) {
         Favorite::where('user_id', $data['user_id'])->where('question_id', $result[$i])->delete();
     }
     $Favoritelist = Favorite::where('user_id', $data['user_id'])->get();
     for ($i = 0; $i < count($Favoritelist); $i++) {
         $Favoritelist[$i]['question'] = Question::where('id', $Favoritelist[$i]['question_id'])->first();
         $Favoritelist[$i]['question']['favorite'] = 1;
         $Favoritelist[$i]['question']['practice'] = 0;
         $Favoritelist[$i]['question']['delete'] = 0;
     }
     return response()->json(['RetCode' => '1', 'Content' => $Favoritelist]);
 }
コード例 #30
0
ファイル: SubjectController.php プロジェクト: mish0501/exams
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $subject = Subject::findOrFail($id);
     $partitions = Partition::where('subject_id', '=', $id);
     foreach ($partitions->get() as $value) {
         $questions = Question::where('subject_id', '=', $id)->where('partition_id', '=', $value->id);
         foreach ($questions->get() as $value) {
             $answers = Answer::where('question_id', '=', $value->id);
             $answers->update(['trash' => true]);
         }
         $questions->update(['trash' => true]);
     }
     $partitions->update(['trash' => true]);
     $subject->update(['trash' => true]);
     \Session::flash('flash_message', 'Предметът беше успешно преместено в кошчето!');
     return redirect()->route('admin.subject.index');
 }