public function testQuery() { $app_id = "XASVlMZE1IVe3zCDpHT5mzhTiEd3su7IWM68Uepa"; $rest_key = "zBwmJIkcOE1dvX3GUIpJT5ebLOhhPhn1NmsdWC6e"; $master_key = "0zNVL0uJnxUiU9r1Ogvii7vLW8tOASIyS5j5HK4G"; ParseClient::$HOST_NAME = "http://localhost/parse/public/"; ParseClient::initialize($app_id, $rest_key, $master_key); \App\Test::truncate(); $response = $this->generalQuery(); $this->assertArrayHasKey("results", $response); $this->assertEmpty($response["results"]); $this->objects = factory(\App\Test::class, 50)->create(); $response = $this->generalQuery(); $this->assertArrayHasKey("results", $response); $this->assertEquals(50, count($response["results"])); $response = $this->firstQuery(); $this->assertArrayHasKey("results", $response); $this->assertEquals(1, count($response["results"])); $response = $this->equalToQuery(); $this->assertArrayHasKey("results", $response); $this->assertEquals(1, count($response["results"])); $response = $this->notEqualToQuery(); $this->assertArrayHasKey("results", $response); $this->assertEquals(49, count($response["results"])); $response = $this->limitQuery(); $this->assertArrayHasKey("results", $response); $this->assertEquals(10, count($response["results"])); }
/** генерирует страницу со списком доступных тестов */ public function index() { $tr_tests = []; //массив id тренировочных тестов $ctr_tests = []; //массив id контрольных тестов $tr_names = []; //массив названий тренировочных тестов $ctr_names = []; //массив названий тренировочных тестов $current_date = date('U'); $query = Test::select('id_test', 'test_course', 'test_name', 'start', 'end', 'test_type')->get(); foreach ($query as $test) { if ($current_date >= strtotime($test->start) && $current_date <= strtotime($test->end) && $test->test_course == 'Рыбина') { //проверка, что тест открыт и он не из Рыбинских $test_type = $test->test_type; if ($test_type == 'Тренировочный') { array_push($tr_tests, $test->id_test); //название тренировочного теста состоит из слова "Тренировочный" и array_push($tr_names, $test->test_name); //самого названия теста } else { array_push($ctr_tests, $test->id_test); array_push($ctr_names, $test->test_name); } } } $tr_amount = count($tr_tests); $ctr_amount = count($ctr_tests); return view('tests.index', compact('tr_tests', 'ctr_tests', 'tr_names', 'ctr_names', 'tr_amount', 'ctr_amount')); }
public function postIndex() { $test = Test::all(); $test = array('username' => Input::get('frmName'), 'email' => Input::get('frmEmail'), 'comment' => Input::get('frmComment')); // save the guestbook entry to the database Test::create($test); return Redirect::to('/'); }
public function limitReached($quiz_id) { $today = Test::where('quiz_id', $quiz_id)->where('user_id', Auth::id())->where('created_at', '>=', new \DateTime('today'))->get(); if ($this->isExaminee() && count($today) >= 3) { return true; } return false; }
/** * Run the database seeds. * * @return void */ public function run() { // Test::create ([ // 'user_id' =>1, // 'status_id'=>3 // ]); Test::create(['user_id' => 3, 'status_id' => 3]); }
public function show($id) { $test = Test::find($id); //获取指定记录 if (!$test) { return $this->response()->errorNotFound('Test Not Found'); } return $this->item($test, new TestTransformer()); }
public function saveNewTest($test) { $newTest = Test::create(['name' => $test['name'], 'preparation' => $test['preparation'], 'time' => $test['time']]); // Nested loop to add questions > options foreach ($test['questions'] as $question) { $savedQuestion = Question::create(['test_id' => $newTest->id, 'title' => $question['title'], 'correct' => $question['correct']]); foreach ($question['options'] as $i => $option) { Option::create(['question_id' => $savedQuestion->id, 'value' => $option]); } } }
public function show($id) { //controle que l'épreuve existe if (!Test::exists($id)) { return redirect('/'); } //contrôle que l'épreuve est visible if (!Test::isVisible($id)) { return redirect('/'); } //demande si l'épreuve est corrigée $is_corrected = Test::isCorrected($id); //appelle la vue return view('etudiant.epreuve')->with(['nb_results_not_read' => User::nbResultsNotRead(), 'first_name' => User::firstName(), 'last_name' => User::lastName(), 'test' => $is_corrected ? User::getTestWithMark($id) : User::getTestWithoutMark($id), 'is_corrected' => $is_corrected, 'qcms' => User::getGrid($id)]); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $test = Test::find($id); return view('test.edit')->with('test', $test); }
public function check($id, Request $request, TestValidator $testvalidator) { $test = Test::findOrFail($id); $validation = $testvalidator->WithRequest($test, $request); $hasPassed = $validation['num_correct'] / $validation['total'] >= 0.5; $hasPassedFull = $validation['num_correct'] == $validation['total']; $minimumToPass = ceil($validation['total'] * 0.5); $customErrors = new MessageBag(); $errors = []; if (!Auth::check()) { $authenticationType = $request->input('authentication_type'); switch ($authenticationType) { case 0: $authvalidator = \Validator::make($request->all(), ['user-name' => 'required', 'user-email' => 'required|email|unique:users,email', 'user-password' => 'required|min:8|confirmed'], ['user-name.required' => 'Nimi on pakollinen.', 'user-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-email.unique' => 'Tunnus samalla sähköpostiosoitteella on jo olemassa.', 'user-password.required' => 'Salasana on pakollinen.', 'user-password.min' => 'Salasanan pitää olla ainakin :min merkkiä pitkä.', 'user-password.confirmed' => 'Salasanat eivät täsmää.']); break; case 1: $authvalidator = \Validator::make($request->all(), ['user-login-email' => 'required|email', 'user-login-password' => 'required'], ['user-login-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-login-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-login-password.required' => 'Salasana on pakollinen.']); break; } $group = false; $shouldJoinGroup = false; if (strlen($request->input('group-code')) > 0) { $group = Group::where('code', $request->input('group-code')); if (!$group->exists()) { $customErrors->add('group-code', 'Annettua ryhmää ei löytynyt. Syötä oikea ryhmäkoodi.'); } else { $shouldJoinGroup = true; } } if ($authvalidator->passes() && $customErrors->isEmpty()) { switch ($authenticationType) { case 0: $user = new User(); $user->name = $request->input('user-name'); $user->email = $request->input('user-email'); $user->password = Hash::make($request->input('user-password')); $user->access_level = 'USER'; $user->save(); Mail::send('email.user_account_created', ['user' => $user], function ($m) use($user) { $m->to($user->email, $user->name)->subject('Käyttäjätunnus luotu Media7 raamattuopistoon'); }); Auth::login($user); if ($shouldJoinGroup) { $group->first()->join(); } break; case 1: $credentials = ['email' => $request->input('user-login-email'), 'password' => $request->input('user-login-password')]; $remember = $request->input('remember_me'); if (!Auth::attempt($credentials, $remember)) { $customErrors->add('user-login-email', 'Kirjautuminen annetuilla tunnuksilla ei onnistunut!'); } else { if ($shouldJoinGroup) { $group->first()->join(); } return redirect('/test/' . $test->id); } break; } } $errors = array_merge($authvalidator->errors()->all(), $customErrors->all()); } if (Auth::check() && $customErrors->isEmpty()) { $archive = Auth::user()->archives()->where('test_id', $id)->first(); $data = $validation; if (!$archive) { $archive = new Archive(); $archive->user_id = Auth::user()->id; $archive->test_id = $test->id; } else { $old_data = json_decode($archive->data, true); if (@$old_data['feedback']) { $data['feedback'] = $old_data['feedback']; } } $archive->data = json_encode($data); $archive->save(); } return view('test.show')->with(array_merge($validation, ['test' => $test, 'feedback' => @$data['feedback'], 'hasPassed' => @$hasPassed, 'hasPassedFull' => @$hasPassedFull, 'minimumToPass' => @$minimumToPass, 'authentication_type' => @$authenticationType, 'isMaterialPage' => false, 'authFailed' => !Auth::check() && !$authvalidator->passes(), 'old' => $request->all()]))->withInput($request)->withErrors(@$errors); }
/** * Execute the console command. * * @return mixed */ public function handle() { $test = new Test(); $test->content = 'test'; $test->save(); }
/** Проверка теста */ public function checkTest(Request $request) { //обработать ответ на вопрос if (Session::has('test')) { //проверяем повторность обращения к результам $current_test = Session::get('test'); } else { return redirect('tests'); } Session::forget('test'); //тест считается честно пройденым Session::forget('end_time'); $amount = $request->input('amount'); $id_test = $request->input('id_test'); $test = new Test(); $score_sum = 0; //сумма набранных баллов $points_sum = 0; //сумма максимально овзможных баллов $choice = []; //запоминаем выбранные варианты пользователя $j = 1; $query = $test->whereId_test($id_test)->select('total', 'test_name', 'amount', 'test_type')->first(); $total = $query->total; $test_type = $query->test_type; for ($i = 0; $i < $amount; $i++) { //обрабатываем каждый вопрос $data = $request->input($i); $array = json_decode($data); $data = $this->check($array); $right_or_wrong[$j] = $data['mark']; $choice[$j] = $data['choice']; $j++; $score_sum += $data['score']; //сумма набранных баллов $points_sum += $data['points']; //сумма максимально возможных баллов } if ($points_sum != 0) { $score = $total * $score_sum / $points_sum; $score = round($score, 1); } else { $score = $total; } $mark_bologna = $this->calcMarkBologna($total, $score); //оценки $mark_rus = $this->calcMarkRus($total, $score); $result = new Result(); $date = date('Y-m-d H:i:s', time()); //текущее время if ($test_type != 'Тренировочный') { //если тест контрольный $result->whereId_result($current_test)->update(['result_date' => $date, 'result' => $score, 'mark_ru' => $mark_rus, 'mark_eu' => $mark_bologna]); return view('tests.ctrresults', compact('score', 'mark_bologna', 'mark_rus')); } else { //если тест тренировочный $amount = $query->amount; $widgets = []; $query = $result->whereId_result($current_test)->first(); //берем сохраненный тест из БД $saved_test = $query->saved_test; $saved_test = unserialize($saved_test); for ($i = 0; $i < $amount; $i++) { $widgets[] = View::make($saved_test[$i]['view'] . 'T', $saved_test[$i]['arguments'])->with('choice', $choice[$i + 1]); } $result->whereId_result($current_test)->update(['result_date' => $date, 'result' => $score, 'mark_ru' => $mark_rus, 'mark_eu' => $mark_bologna]); $widgetListView = View::make('questions.student.training_test', compact('score', 'right_or_wrong', 'mark_bologna', 'mark_rus'))->with('widgets', $widgets); return $widgetListView; } }
public function destroy(Request $request, $id) { if ($id) { Test::destroy($id); Session::flash('flash_message', 'Test has been deleted successfully.'); Session::flash('flash_type', 'alert-success'); } return redirect('admin/tests'); }
/** * Run the database seeds. * * @return void */ public function run() { $nb_epreuves_classees_corrigees = 5; $nb_qcm_par_epreuve = 15; DB::table('epreuve')->truncate(); DB::table('correction_qcm')->truncate(); DB::table('statistiques_qcm')->truncate(); DB::table('statistiques_epreuve')->truncate(); DB::table('utilisateur_note_epreuve')->truncate(); DB::table('grille_qcm')->truncate(); DB::table('utilisateur_note_grille_qcm')->truncate(); $session_scolaire_courrante_id = DB::table('session_scolaire')->whereNull('date_fin')->pluck('id'); //affectation cyclique des UE aux épreuves $ue_disponibles = DB::table('ue')->where('session_scolaire_id', $session_scolaire_courrante_id); $nb_ue_disponibles = $ue_disponibles->count(); $ue_affectee_id = null; //création de 5 épreuves classées et corrigées for ($i = 1; $i <= $nb_epreuves_classees_corrigees; $i++) { //date de l'épreuve : on fait une épreuve par semaine $date_epreuve = time() - $i * 3600 * 24 * 7; //epreuve $ue_affectee_id = $ue_disponibles->offset($i % $nb_ue_disponibles)->pluck('id'); $epreuve_id = DB::table('epreuve')->insertGetId(['session_scolaire_id' => $session_scolaire_courrante_id, 'ue_id' => $ue_affectee_id, 'titre' => 'Epreuve ' . $i, 'date' => $date_epreuve, 'visible' => true, 'date_modif_correction' => time()]); $array_correction_qcm_to_insert = null; $array_statistiques_qcm_to_insert = null; //15 QCM par epreuve for ($j = 1; $j <= $nb_qcm_par_epreuve; $j++) { //barème aléatoire parmi les choix possibles dans la table barème $nb_baremes = DB::table('bareme')->count(); $bareme_id = DB::table('bareme')->offset(rand(0, $nb_baremes - 1))->pluck('id'); //réponse aux items $item_a = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé = mis en double $item_b = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_c = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_d = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_e = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé //correction QCM $array_correction_qcm_to_insert[] = ['epreuve_id' => $epreuve_id, 'numero_qcm' => $j, 'bareme_id' => $bareme_id, 'annule' => rand(1, 50) == 1, 'item_a' => $item_a, 'item_b' => $item_b, 'item_c' => $item_c, 'item_d' => $item_d, 'item_e' => $item_e, 'date_modif' => $date_epreuve + 3600 * 24]; //statistiques aléatoires par qcm; $ecart = (rand(0, 400) - 200) / 1000; $array_statistiques_qcm_to_insert[] = ['epreuve_id' => $epreuve_id, 'numero_qcm' => $j, 'taux_item_a' => pow(rand(0, 1000) / 1000, 1 / 5), 'taux_item_b' => pow(rand(0, 1000) / 1000, 1 / 5), 'taux_item_c' => pow(rand(0, 1000) / 1000, 1 / 5), 'taux_item_d' => pow(rand(0, 1000) / 1000, 1 / 5), 'taux_item_e' => pow(rand(0, 1000) / 1000, 1 / 5), 'taux_0_discordance' => 0.2 + $ecart, 'taux_1_discordance' => 0.2 + $ecart * 0.5, 'taux_2_discordance' => 0.2 + $ecart * 0.1, 'taux_3_discordance' => 0.2 - $ecart * 0.1, 'taux_4_discordance' => 0.2 - $ecart * 0.5, 'taux_5_discordance' => 0.2 - $ecart]; } DB::table('correction_qcm')->insert($array_correction_qcm_to_insert); DB::table('statistiques_qcm')->insert($array_statistiques_qcm_to_insert); //notes et classements individuels + grille QCM, $etudiants = DB::table('utilisateur')->where('statut', '=', 'student')->get(); $nb_etudiants = count($etudiants); $nb_qcm_epreuve = DB::table('correction_qcm')->where('epreuve_id', $epreuve_id)->count(); //note max de l'ue $note_max_ue = DB::table('epreuve')->join('ue', 'epreuve.ue_id', '=', 'ue.id')->where('epreuve.id', $epreuve_id)->pluck('ue.note_max'); $array_utilisateur_note_epreuve_to_insert = null; $array_nb_discordances_to_insert = null; foreach ($etudiants as $etudiant) { if (rand(1, 7) != 1) { $note_base = rand(0, 1000) / 1000; $note_reelle = $note_base * $note_max_ue; $note_ajustee = sqrt($note_base) * $note_max_ue; //note et classement $array_utilisateur_note_epreuve_to_insert[] = ['utilisateur_id' => $etudiant->id, 'epreuve_id' => $epreuve_id, 'classement' => rand(1, $nb_etudiants), 'note_reelle' => $note_reelle, 'note_ajustee' => $note_ajustee]; //grille reponse for ($k = 1; $k < $nb_qcm_epreuve + 1; $k++) { DB::table('grille_qcm')->insert(['utilisateur_id' => $etudiant->id, 'epreuve_id' => $epreuve_id, 'numero_qcm' => $k, 'item_a' => rand(0, 1), 'item_b' => rand(0, 1), 'item_c' => rand(0, 1), 'item_d' => rand(0, 1), 'item_e' => rand(0, 1)]); //on compte les discordances $user_qcm = DB::table('grille_qcm')->where('utilisateur_id', $etudiant->id)->where('epreuve_id', $epreuve_id)->where('numero_qcm', $k)->first(); $correction_qcm = DB::table('correction_qcm')->where('epreuve_id', $epreuve_id)->where('numero_qcm', $k)->first(); $nb_discordances = Test::countDiscordances($user_qcm, $correction_qcm); $array_nb_discordances_to_insert[] = ['utilisateur_id' => $etudiant->id, 'epreuve_id' => $epreuve_id, 'numero_qcm' => $k, 'nb_discordances' => $nb_discordances]; } } } DB::table('utilisateur_note_epreuve')->insert($array_utilisateur_note_epreuve_to_insert); DB::table('utilisateur_note_grille_qcm')->insert($array_nb_discordances_to_insert); //statistiques des épreuves $nb_participants = count(DB::table('utilisateur_note_epreuve')->where('epreuve_id', $epreuve_id)->get()); $min = DB::table('utilisateur_note_epreuve')->where('epreuve_id', $epreuve_id)->min('note_reelle'); $max = DB::table('utilisateur_note_epreuve')->where('epreuve_id', $epreuve_id)->max('note_reelle'); $moy = DB::table('utilisateur_note_epreuve')->where('epreuve_id', $epreuve_id)->avg('note_reelle'); DB::table('statistiques_epreuve')->insert(['epreuve_id' => $epreuve_id, 'nb_participants' => $nb_participants, 'min' => $min, 'max' => $max, 'moy' => $moy, 'date_generation' => time() + 10]); } //création de 1 épreuve corrigée sans classement for ($i = 1; $i < 2; $i++) { //date de l'épreuve : on fait une épreuve par semaine $date_epreuve = time(); //epreuve $ue_affectee_id = $ue_disponibles->offset($i % $nb_ue_disponibles)->pluck('id'); $epreuve_id = DB::table('epreuve')->insertGetId(['session_scolaire_id' => $session_scolaire_courrante_id, 'ue_id' => $ue_affectee_id, 'titre' => 'Epreuve non classée ' . $i, 'date' => $date_epreuve, 'visible' => true, 'date_modif_correction' => time() + 10]); //15 QCM par epreuve for ($j = 1; $j < 16; $j++) { //barème aléatoire parmi les choix possibles dans la table barème $nb_baremes = DB::table('bareme')->count(); $bareme_id = DB::table('bareme')->offset(rand(0, $nb_baremes - 1))->pluck('id'); //réponse aux items $item_a = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_b = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_c = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_d = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé $item_e = rand(1, 100) != 1 ? rand(0, 1) : 2; //1 chance sur 100 que l'item soit annulé //correction QCM DB::table('correction_qcm')->insert(['epreuve_id' => $epreuve_id, 'numero_qcm' => $j, 'bareme_id' => $bareme_id, 'annule' => rand(1, 50) == 1, 'item_a' => $item_a, 'item_b' => $item_b, 'item_c' => $item_c, 'item_d' => $item_d, 'item_e' => $item_e, 'date_modif' => $date_epreuve + 3600 * 24]); } } //création de 1 épreuve non corrigée, invisible for ($i = 1; $i < 2; $i++) { //date de l'épreuve : on fait une épreuve par semaine $date_epreuve = time(); //epreuve $ue_affectee_id = $ue_disponibles->offset($i % $nb_ue_disponibles)->pluck('id'); $epreuve_id = DB::table('epreuve')->insertGetId(['session_scolaire_id' => $session_scolaire_courrante_id, 'ue_id' => $ue_affectee_id, 'titre' => 'Epreuve non corrigée ' . $i, 'date' => $date_epreuve, 'visible' => false]); } }
protected function _saveTest($data) { $isNewEntry = !array_key_exists('id', $data); if ($isNewEntry) { $test = new Test(); $latest_test_on_course = Test::where(['course_id' => $data['course']['id']])->orderBy('order', 'DESC')->first(); $next_course_order = ($latest_test_on_course ? $latest_test_on_course->order : 0) + 1; $test->order = $next_course_order; } else { $test = Test::find($data['id']); $submitted_questions = []; foreach ($data['questions'] as $qkey => $qdata) { if (array_key_exists('id', $qdata)) { $submitted_questions[] = $qdata['id']; } } foreach ($test->questions as $question) { if (!in_array($question->id, $submitted_questions)) { $question->delete(); } } if ($test->course->id != $data['course']['id']) { $latest_test_on_course = Test::where(['course_id' => $data['course']['id']])->orderBy('order', 'DESC')->first(); $next_course_order = ($latest_test_on_course ? $latest_test_on_course->order : 0) + 1; $test->order = $next_course_order; } } $test->course_id = $data['course']['id']; $test->title = $data['title']; $test->description = $data['description']; $test->autodiscard = $data['autodiscard']; $test->save(); /////////////////////// $isNewPage = !array_key_exists('id', $data['page']); $pageBody = trim($data['page']['body']); $page = false; if ($isNewPage) { $page = new Page(); } else { $page = Page::find($data['page']['id']); } if ($page) { $page->test_id = $test->id; $page->body = $pageBody; $page->hidden = false; if (strlen(trim(strip_tags($pageBody, '<img>'))) == 0) { $page->hidden = true; } $page->save(); } ///////////////////////// foreach ($data['questions'] as $qkey => $question_data) { if (!array_key_exists('id', $question_data)) { $question = new Question(); } else { $question = Question::find($question_data['id']); $submitted_answers = []; foreach ($question_data['answers'] as $adata) { if (array_key_exists('id', $adata)) { $submitted_answers[] = $adata['id']; } } foreach ($question->answers as $akey => &$answer) { if (!in_array($answer->id, $submitted_answers) || $question_data['type'] == "TEXT" && $akey > 0 || $question_data['type'] == "TEXTAREA") { $answer->delete(); } } } $question->test_id = $test->id; $question->type = $question_data['type']; $question->title = $question_data['title']; $question->subtitle = $question_data['subtitle']; $question->order = $qkey + 1; $question->data = array_key_exists('data', $question_data) ? $question_data['data'] : '{}'; switch ($question->type) { case 'MULTITEXT': if (!property_exists($question->data, 'multitext_required') || is_null($question->data->multitext_required) || $question->data->multitext_required > count($question_data['answers'])) { $question->data->multitext_required = count($question_data['answers']); } break; } $question->save(); /////////////////////////// foreach ($question_data['answers'] as $akey => $answer_data) { if (!array_key_exists('id', $answer_data)) { $answer = new Answer(); } else { $answer = Answer::find($answer_data['id']); } if (!@$answer) { $answer = new Answer(); } $answer->question_id = $question->id; $answer->text = $answer_data['text']; if ($question->type == "CHOICE") { $answer->is_correct = intval($question_data['correct_answer']) == $akey; } else { $answer->is_correct = @$answer_data['is_correct'] ? true : false; } switch ($question->type) { case 'TEXT': case 'MULTITEXT': $answer->is_correct = true; break; } if (array_key_exists('error_margin', $answer_data)) { $answer->error_margin = $answer_data['error_margin']; } else { $answer->error_margin = 10; } $answer->save(); } } return $test->id; }
/** * Remove the specified resource from storage. * * @param Test $test * @return \Illuminate\Http\Response * @internal param int $id */ public function destroy(Test $test) { $test->destroy(); }
public function get() { $test = new Test(); $test->get(); }
public function delete_qcm(Request $r) { Test::deleteQCMCorrection($r->input('epreuve_id'), $r->input('numero_qcm')); Session::flash('flash_message_qcm', 'Question ' . $r->input('numero_qcm') . ' supprimée'); return redirect()->back(); }
/** * Evaluate the points of a single question * * @param Question $question * @param Test $test */ private function evaluate(Question $question, Test $test) { if ($question->correct1 + $question->correct2 + $question->correct3 + $question->correct4 + $question->correct5 == 0) { abort(404); } if ($question->correct1 == 1) { $test->points++; } if ($question->correct2 == 1) { $test->points++; } if ($question->correct3 == 1) { $test->points++; } if ($question->correct4 == 1) { $test->points++; } if ($question->correct5 == 1) { $test->points++; } $test->save(); }
/** * Display a listing of the resource. * * @return Response */ public function index(Test $test) { $test = Test::find(1); return view('test.index', array('test')); }
public function index() { $tests = Test::latest()->get(); return view('results.index', compact('tests')); }
/** Генерирует pdf файлы с тестом с заданным количеством вариантов */ public function pdfTest(Request $request) { $question = new Question(); $test = new Test(); $test_controller = new TestController($test); $question_controller = new QuestionController($question); $test_name = $request->input('test'); $num_var = $request->input('num-variants'); $query = Test::whereTest_name($test_name)->select('amount', 'id_test')->first(); $id_test = $query->id_test; $amount = $query->amount; // кол-во вопрососв в тесте $today = date("Y-m-d H-i-s"); $dir = 'download/pdf_tests/' . $today; mkdir($dir); define('FPDF_FONTPATH', 'C:\\wamp\\www\\uir\\public\\fonts'); for ($k = 1; $k <= $num_var; $k++) { // генерируем необходимое число вариантов $fpdf = new Mypdf(); $answered_fpdf = new Mypdf(); $this->headOfPdf($fpdf, $test_name, $k, $amount); $this->headOfPdf($answered_fpdf, $test_name, $k, $amount); $ser_array = $question_controller->prepareTest($id_test); // подготавливаем тест for ($i = 0; $i < $amount; $i++) { // показываем каждый вопрос из теста $id = $question_controller->chooseQuestion($ser_array); if (!$test_controller->rybaTest($id)) { //проверка на вопрос по рыбе return view('no_access'); } $this->pdfQuestion($fpdf, $id, $i + 1); $this->pdfQuestion($answered_fpdf, $id, $i + 1, true); $fpdf->Ln(10); $answered_fpdf->Ln(10); } $fpdf->Output(iconv('utf-8', 'windows-1251', $dir . '/variant' . $k . '.pdf'), 'F'); $answered_fpdf->Output(iconv('utf-8', 'windows-1251', $dir . '/answered_variant' . $k . '.pdf'), 'F'); } $zip = $this->pdfToZip($dir); // создаем архив $this->delPdf($dir); // удаляем созданную папку с тестами $this->download($zip); // скачать архив }
function class_load() { App\Test::hello(); }
public function receive_video_convert_notifications() { $post = file_get_contents('php://input'); $test = new Test(); $test->content = $post; $test->save(); $noti = json_decode($post); $message = json_decode($noti->Message); $jobId = $message->jobId; $video_name = '/videos/' . $message->outputs[0]->key; $video_url = config('app.s3_url') . $video_name; $publish_data = array("event" => "transcode-video", "data" => ["video_url" => $video_url, 'video_name' => $video_name, 'jobId' => $jobId, 'thumb_url' => $video_url]); Redis::publish('colorme-channel', json_encode($publish_data)); $tmp_file_name = "/" . $message->input->key; $s3 = \Illuminate\Support\Facades\Storage::disk('s3'); $s3->delete($tmp_file_name); return "done"; }
public function getactivetests() { $tests = \App\Test::where('status', 1)->get(); return $tests; }
public function activatetest($id) { $test = Test::findOrFail($id); if ($test->status == 1) { $test->status = 0; } else { $test->status = 1; } $test->save(); return back(); }
/** Добавляет новый тест в БД */ public function add(Request $request) { if ($request->input('training')) { $test_type = 'Тренировочный'; } else { $test_type = 'Контрольный'; } $total = $request->input('total'); $test_time = $request->input('test-time'); $start = $request->input('start-date') . ' ' . $request->input('start-time'); $end = $request->input('end-date') . ' ' . $request->input('end-time'); $structure = ''; $amount = 0; for ($i = 0; $i < $request->input('num-rows'); $i++) { $structure .= $this->struct($request->input('num')[$i], $request->input('section')[$i], $request->input('theme')[$i], $request->input('type')[$i]) . ';'; $amount += $request->input('num')[$i]; } $structure .= $this->struct($request->input('num')[$request->input('num-rows')], $request->input('section')[$request->input('num-rows')], $request->input('theme')[$request->input('num-rows')], $request->input('type')[$request->input('num-rows')]); $amount += $request->input('num')[$request->input('num-rows')]; Test::insert(array('test_name' => $request->input('test-name'), 'test_type' => $test_type, 'amount' => $amount, 'test_time' => $test_time, 'start' => $start, 'end' => $end, 'structure' => $structure, 'total' => $total)); return redirect()->route('test_create'); }
public function destroy($id) { Test::findOrFail($id)->delete(); return Redirect::route('test.index'); }
public function show($id, TestTransformer $testTransformer) { $rawTest = Test::where('id', $id)->with('questions.options')->firstOrFail(); $test = $testTransformer->transform($rawTest); return $test; }
/** * Receive answer from test and format next question and test * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $user = Auth::user(); $question = Question::with('skill')->with('difficulty')->with('skill.level')->with('skill.track')->find($request->question_id); // log $question->tests()->updateExistingPivot($request->test_id, ['answered' => TRUE], false); $user->tested_questions()->attach($request->question_id, ['correct' => $correct = $question->correct_answer == $request->answer]); // initialize $error_limit = Config::get('mathtest.error_test'); $success_limit = Config::get('mathtest.success_test'); $difficulty = $question->difficulty_id; $skill = $question->skill; $level = $skill->level; $track = $skill->track; $test = Test::find($request->test_id); $maxile = 0; // track if user has done questions of the same skill and difficulty $test_record = $test->questions()->selectRaw('question_test.question_id as id')->lists('id'); $total_correct = $user->numberCorrect()->where('questions.difficulty_id', '=', $difficulty)->where('questions.skill_id', '=', $skill->id)->take(max($error_limit, $success_limit))->first()->total_correct; // dd($total_correct); // dd($question->correct_answer == $request->answer); $new_question = new Question(); // return $track->users()->get(); if ($correct) { //if answer is correct // dd($correct); if ($total_correct < $success_limit - 1) { //cleared this difficulty if ($new_question = Question::similar($difficulty, $skill->id)->whereNotIn('id', $test_record)->first()) { // dd($correct); } } else { $user->track_results()->attach($question->track, ['difficulty_id' => $question->difficulty_id, 'skill_id' => $question->skill_id, 'level_id' => $question->skill->level->id, 'track_id' => $question->skill->track->id, 'maxile' => intval($question->skill->level->starting_maxile_level + 100 * ($difficulty / Difficulty::max('difficulty')) * ($skill->skill / Skill::whereLevelId($level->id)->max('skill')))]); if ($difficulty < Difficulty::max('difficulty')) { $new_question = Question::harder($difficulty, $skill->id)->whereNotIn('id', $test_record)->first(); } elseif ($skill->skill < Skill::whereTrackId($track->id)->whereLevelId($level->id)->max('skill')) { $new_question = Question::whereNotIn('id', $test_record)->upskill($skill, $track->id, $level->id)->first(); } elseif ($level->level < Level::max('level')) { $new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'asc')->first()->id)->first(); } else { return ['msg' => 'You have reached the maximum level and difficulty for all skills in this track.']; } } // if answer is wrong } elseif ($difficulty > Difficulty::min('difficulty')) { $new_question = Question::easier($difficulty, $skill->id)->whereNotIn('id', $test_record)->first(); } elseif ($skill->skill > Skill::whereTrackId($track->id)->whereLevelId($level->id)->min('skill')) { $new_question = Question::whereNotIn('id', $test_record)->downskill($skill, $track->id, $level->id)->first(); } elseif ($level->level > Level::min('level')) { $new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'desc')->first()->id)->first(); } else { return ['msg' => 'You have reached the minimum level and difficulty for all skills in this track.']; } // dd($new_question); if (isset($new_question) and $new_question->id != null) { $new_question->tests()->attach($request->test_id, ['answered' => FALSE]); return $this->formatQuiz($new_question, $request->test_id); } else { return ['result' => Track::join('track_user', 'id', '=', 'track_id')->where('track_user.user_id', '=', $user->id)->select('tracks.track')->selectRaw('max(track_user.maxile) as max')->groupBy('tracks.track')->get()]; } }