Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\Admin\Questions\Store $request, Prototype $Prototype)
 {
     $Question = new Question();
     $Question->fill($request->input('question'));
     $Question->prototype()->associate($Prototype);
     $Question->save();
     if ($request->hasFile('image') && $request->file('image')->isValid()) {
         $QuestionImage = $request->file('image');
         $QuestionImage = $QuestionImage->move('upload\\questions', $Question->id . '.' . $QuestionImage->getClientOriginalExtension());
         $Question->image = $QuestionImage->getPathname();
         $Question->save();
     } elseif ($request->has('question.delete_image') && $request->input('question.delete_image') == 'on') {
         $Question->image = null;
         $Question->save();
     }
     foreach ($request->input('answers') as $key => $answer) {
         $Answer = Answer::create(['text' => $answer['text'], 'right' => isset($answer['right'])]);
         $Question->answers()->save($Answer);
         if ($request->hasFile('answers.' . $key . '.image') && $request->file('answers.' . $key . '.image')->isValid()) {
             $AnswerFile = $request->file('answers.' . $key . '.image');
             $AnswerFile = $AnswerFile->move('upload\\answers', $Answer->id . '.' . $AnswerFile->getClientOriginalExtension());
             $Answer->image = $AnswerFile->getPathname();
             $Answer->save();
         } elseif ($request->has('answers.' . $key . '.delete_image') && $request->input('answers.' . $key . '.delete_image') == 'on') {
             $Answer->image = null;
             $Answer->save();
         }
     }
     return redirect(route('admin.prototypes.edit', $Prototype));
 }
 public function run()
 {
     DB::table('answers')->delete();
     Answer::create(['student_id' => 1, 'question_id' => 51, 'option_id' => 201]);
     Answer::create(['student_id' => 1, 'question_id' => 53, 'option_id' => 209]);
     Answer::create(['student_id' => 1, 'question_id' => 54, 'option_id' => 216]);
     Answer::create(['student_id' => 1, 'question_id' => 55, 'option_id' => 219]);
     Answer::create(['student_id' => 2, 'question_id' => 51, 'option_id' => 201]);
     Answer::create(['student_id' => 2, 'question_id' => 52, 'option_id' => 205]);
     Answer::create(['student_id' => 2, 'question_id' => 53, 'option_id' => 210]);
     Answer::create(['student_id' => 2, 'question_id' => 56, 'option_id' => 223]);
     Answer::create(['student_id' => 3, 'question_id' => 52, 'option_id' => 207]);
     Answer::create(['student_id' => 3, 'question_id' => 54, 'option_id' => 214]);
     Answer::create(['student_id' => 3, 'question_id' => 55, 'option_id' => 218]);
     Answer::create(['student_id' => 3, 'question_id' => 56, 'option_id' => 224]);
 }
Example #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $Role1 = \App\Models\Role::create(['title' => 'Пользователь', 'default' => true]);
     $Role2 = \App\Models\Role::create(['title' => 'Администратор', 'admin' => true]);
     \App\Models\Group::create(['title' => 'КИТ-10']);
     $Group1 = \App\Models\Group::create(['title' => 'КИТ-10']);
     \App\Models\Group::create(['title' => 'КИТ-20']);
     $Group2 = \App\Models\Group::create(['title' => 'КИТ-30']);
     \App\Models\Group::create(['title' => 'КИТ-40']);
     \App\User::create(['first_name' => 'Admin', 'last_name' => 'Admin', 'second_name' => 'Admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin'), 'group_id' => $Group2->id, 'role_id' => $Role2->id]);
     \App\User::create(['first_name' => 'Test first name', 'last_name' => 'Test last name', 'second_name' => 'Test second name', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'group_id' => $Group1->id, 'role_id' => $Role1->id]);
     \Illuminate\Support\Facades\DB::table('type_question')->insert([['title' => 'radio'], ['title' => 'checkbox']]);
     $Prototype = \App\Models\Prototype::create(['title' => 'Тест по биологии', 'time' => 40, 'count_questions' => 5]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько лап у ежа?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '4', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '6', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Много', 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какая длина хобота у слона?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => 'У слона нет хобота', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '2 метра', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Зависит от возраста', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько рёбер у человека?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '12 пар', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Кто такой человек?', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какие типы данных из перечисленных есть в PHP?', 'type' => 'checkbox']);
     $Answer = \App\Models\Answer::create(['text' => 'Integer', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Float', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'String', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Char', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Array', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Callbacks / Callables', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор выполняет строгое сравнение?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '==', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '===', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '&', 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор не правильный?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '$a and $b', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a or $b', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '! $a', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a => $b', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a <= $b', 'right' => true, 'question_id' => $Question->id]);
     // $this->call('UserTableSeeder');
 }
 public function store(Quiz $quiz, Request $request)
 {
     $student_id = Auth::user()->student()->first()->id;
     if (Score::whereQuizIdAndStudentId($quiz->id, $student_id)) {
         return "e";
     }
     $points = 0;
     foreach ($request->all() as $r) {
         $ca = CorrectAnswer::whereQuestionId($r['question_id'])->first()->option_id;
         if ($ca == $r['option_id']) {
             $points++;
         }
         if (!Answer::whereStudentIdAndQuestionId($student_id, $r['question_id'])->first()) {
             Answer::create(['student_id' => $student_id, 'question_id' => $r['question_id'], 'option_id' => $r['option_id']]);
         }
     }
     $score = Score::create(['score' => $points, 'time' => time() - strtotime($quiz->date_time), 'quiz_id' => $quiz->id, 'student_id' => $student_id]);
     DB::table('quiz_student')->insert(['student_id' => $student_id, 'quiz_id' => $quiz->id]);
     return $score;
 }