Exemple #1
0
 public function update($id, Request $request)
 {
     $test = Test::find($id);
     $test->name = $request->name;
     $test->preparation = $request->preparation;
     $test->save();
     return Redirect::route('test.index');
 }
 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 getconfiguration($id)
 {
     $test = Test::find($id);
     if (count($test) > 0) {
         $test->ratings;
         foreach ($test->parts as $key => $part) {
             $part->subjects;
             foreach ($part->sections as $key => $section) {
                 $section->questions;
             }
         }
     }
     $subjects = Subject::orderBy('no', 'asc')->get();
     $chapters = Chapter::orderBy('no', 'asc')->get();
     $questiontypes = QuestionType::all();
     foreach ($chapters as $key => $chapter) {
         $chapter->module->subject;
     }
     return view('superadmin.configuretest')->with('test', $test)->with('subjects', $subjects)->with('chapters', $chapters)->with('questiontypes', $questiontypes);
 }
Exemple #4
0
 /**
  * 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);
 }
Exemple #5
0
 function update(Request $request, $id)
 {
     $input = $request->all();
     $files = $request->file('test_files');
     if (!empty($files[0])) {
         foreach ($files as $file) {
             $fileName = $file->getClientOriginalName();
             $file->move(public_path() . '/TestFiles/' . $id, $fileName);
             $file = new TestFile();
             $file::create(array('file_name' => $fileName));
         }
     }
     $getParam = Parameter::where('name', '=', $input['parameter'])->first();
     if (!empty($getParam)) {
         $arr['parameter_id'] = $getParam->id;
     }
     $getState = Parameter::where('name', '=', $input['state'])->first();
     if (!empty($getState)) {
         $arr['state_id'] = $getState->id;
     }
     $getMethod = Method::where('name', '=', $input['method'])->first();
     if (!empty($getMethod)) {
         $arr['method_id'] = $getMethod->id;
     }
     $getTestMethod = TestMethod::where('name', '=', $input['test_method'])->first();
     if (!empty($getTestMethod)) {
         $arr['test_method_id'] = $getTestMethod->id;
     }
     $test = Test::find($id);
     $test->update($arr);
     // update test items //
     DB::table('test_processes')->where('test_id', '=', $id)->delete();
     if ($request->has('test_item')) {
         $items = $request->get('test_item');
         foreach ($items as $key => $value) {
             $process = new Process();
             $process::create(array('test_id' => $id, 'item_id' => $value, 'status' => 1));
         }
     }
     Session::flash('flash_message', 'Test has been updated successfully.');
     Session::flash('flash_type', 'alert-success');
     return redirect('admin/tests');
 }
Exemple #6
0
 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;
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Test $test)
 {
     $test = Test::find(1);
     return view('test.index', array('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()];
     }
 }
 protected function _save($data)
 {
     $isNewEntry = !array_key_exists('id', $data);
     if ($isNewEntry) {
         $course = new Course();
     } else {
         $course = Course::find($data['id']);
     }
     $course->title = $data['title'];
     $course->description = $data['description'];
     $course->published = $data['published'];
     $course->save();
     if (!$isNewEntry) {
         foreach ($data['tests'] as $key => $tdata) {
             $test = Test::find($tdata['id']);
             $test->order = $key + 1;
             $test->save();
         }
     }
     return $course->id;
 }