Esempio n. 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('answers')->truncate();
     $quiz = new Answer();
     $quiz->question_id = 1;
     $quiz->user_id = 1;
     $quiz->title = 'Seeded answer 1';
     $quiz->is_right = 1;
     $quiz->save();
     $quiz = new Answer();
     $quiz->question_id = 1;
     $quiz->user_id = 1;
     $quiz->title = 'Seeded answer 1';
     $quiz->is_right = 0;
     $quiz->save();
     $quiz = new Answer();
     $quiz->question_id = 2;
     $quiz->user_id = 1;
     $quiz->title = 'Seeded answer 1';
     $quiz->is_right = 0;
     $quiz->save();
     $quiz = new Answer();
     $quiz->question_id = 2;
     $quiz->user_id = 1;
     $quiz->title = 'Seeded answer 1';
     $quiz->is_right = 1;
     $quiz->save();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Esempio n. 2
0
 public function store_answer(Request $request)
 {
     $answer = new Answer();
     $answer->content = $request->answer_content;
     $answer->question_id = $request->question_id;
     $answer->user_id = $this->user->id;
     $answer->save();
     return $answer->id;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function postReply(AnswerRequest $request, $id)
 {
     $answer = Question::find($id)->answer;
     if (!$answer) {
         $answer = new Answer();
     }
     $answer->user_id_answered = Auth::id();
     $answer->content = $request->content;
     $answer->question_id = $id;
     $answer->save();
 }
Esempio n. 4
0
 public static function addUserFeedback($data)
 {
     $userID = \Auth::user()->id;
     foreach ($data['data'] as $d) {
         $answer = new Answer();
         $answer->uid = $userID;
         $answer->qid = $d['id'];
         $answer->answer = $d['value'];
         $answer->save();
         //echo $d['id'] ." ". $d['value']."\n";
     }
     return true;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $json = Storage::get('questions.json');
     $this->command->info($json);
     $questions = json_decode($json, true);
     foreach ($questions['questions'] as $question_keys => $question) {
         $this->command->info("Adding Question: " . $question_keys . "...");
         if ($question["type"] != "true-false") {
             $answers = $question['answers'];
             unset($question['answers']);
         }
         $q = new Question($question);
         $q->save();
         foreach ($question as $question_attribute_name => $question_attribute_value) {
             $this->command->info($question_attribute_name);
         }
         if ($q->type == "true-false") {
             $this->command->info("Adding True/False Question...");
             $answer = $question['answer'];
             $aFalse;
             $aTrue;
             if (Answer::where('text', 'true')->count() >= 1) {
                 $aTrue = Answer::where('text', 'true')->first();
             } else {
                 $aTrue = new Answer(['text' => 'true']);
                 $aTrue->save();
             }
             if (Answer::where('text', 'false')->count() >= 1) {
                 $aFalse = Answer::where('text', 'false')->first();
             } else {
                 $aFalse = new Answer(['text' => 'false']);
                 $aFalse->save();
             }
             $q->answers()->save($aFalse, ['is_correct' => $answer ? 0 : 1]);
             $q->answers()->save($aTrue, ['is_correct' => $answer ? 1 : 0]);
         } else {
             $this->command->info("Adding answers...");
             $answer_ids = array();
             foreach ($answers as $answer_index => $answer) {
                 $this->command->info("Adding " . ($answer_index + 1) . "...");
                 $a = new Answer($answer);
                 $a->save();
                 $q->answers()->save($a, ['is_correct' => $answer['is_correct'] === "false" ? 0 : 1]);
             }
         }
         $this->command->info("");
     }
 }
 /**
  * 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');
                         });
                     }
                 }
             }
         }
     }
 }
Esempio n. 7
0
 public function delete_item($a_id)
 {
     $a = Answer::find($a_id);
     $this->authorize('qna-edit', $a);
     $a->delete();
     return redirect("qs/{$a->q_id}");
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->bind('articles', function ($id) {
         $article = Article::findOrFail($id);
         // If the owner return all articles else return only published.
         if (Auth::user() && $article->user_id === Auth::user()->id) {
             $articles = Article::findOrFail($id);
         } else {
             $articles = Article::published()->findOrFail($id);
         }
         return $articles;
     });
     $router->bind('questions', function ($id) {
         return Question::findOrFail($id);
     });
     $router->bind('answers', function ($id) {
         return Answer::findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('users', function ($id) {
         return User::findOrFail($id);
     });
 }
Esempio n. 9
0
 /**
  * Responds to request to GET /answer/delete/{question_id}
  */
 public function getAnswerDelete($answer_id)
 {
     $answer = Answer::find($answer_id);
     $quiz_id = $answer->question->quiz_id;
     $answer->delete();
     return redirect('/edit/' . $quiz_id);
 }
Esempio n. 10
0
 public function destroy($id)
 {
     $answer = Answer::findOrFail($id);
     if ($answer->votes->contains(auth()->user())) {
         $answer->votes()->detach(auth()->user()->id);
     }
     return redirect()->back();
 }
Esempio n. 11
0
 public function sendFeedback()
 {
     if (\Request::ajax()) {
         $data = \Input::all();
         if (Answer::addUserFeedback($data)) {
             return 'sucess';
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('answers')->delete();
     $answers = array(['text' => 'answer1', 'user_id' => 3, 'question_id' => 1, 'follower_user' => '3_2'], ['text' => 'answer2', 'user_id' => 2, 'question_id' => 2, 'follower_user' => '8_2'], ['text' => 'answer3', 'user_id' => 1, 'question_id' => 2, 'follower_user' => '7_2'], ['text' => 'answer4', 'user_id' => 4, 'question_id' => 1, 'follower_user' => '6_2']);
     // Loop through each user above and create the record for them in the database
     foreach ($answers as $answer) {
         Answer::create($answer);
     }
 }
Esempio n. 13
0
 public function update(AnswerRequest $request, int $id)
 {
     $answer = Answer::findOrFail($id);
     $this->authorize('edit-answer', $answer);
     $answer->body = $request->get('body');
     $answer->save();
     session()->flash('success', 'La respuesta ha sido editada.');
     return redirect()->route('question.show', $answer->question->id);
 }
Esempio n. 14
0
 public static function getValue($element, $field, $user)
 {
     $answer = Answer::where('student', $user)->where('element', $element)->first();
     if (is_object($answer) and array_key_exists($field, json_decode($answer->value, true))) {
         return json_decode($answer->value, true)[$field];
     } else {
         return "";
     }
 }
Esempio n. 15
0
 /**
  * Fetch current user answer's weight
  *
  * @return answer weight on success, otherwise return 0.
  */
 public function weight()
 {
     $answer = Answer::findOrFail($this->answer_id);
     if ($answer) {
         return $answer->weight;
     } else {
         return 0;
     }
 }
Esempio n. 16
0
 public function reply()
 {
     $questionId = Request::get('questionId');
     $chosenAnswerId = Request::get('chosenAnswerId');
     $replyResult = Answer::findOrFail($chosenAnswerId)->is_correct;
     \Auth::user()->replies()->updateOrCreate(['question_id' => $questionId], ['is_correct' => $replyResult]);
     $answers = Question::find($questionId)->answers();
     $correctAnswerId = $answers->where('is_correct', '=', true)->first()->id;
     return response()->json(['correctAnswerId' => $correctAnswerId, 'chosenAnswerId' => $chosenAnswerId, 'replyResult' => $replyResult, 'answers' => $answers->get()]);
 }
Esempio n. 17
0
 public function fieldFormModel($id, array $fields)
 {
     $answer = Answer::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $answer->{$field};
     }
     return $fields;
 }
Esempio n. 18
0
 public function storeAnswer($id, AnswerRequest $request)
 {
     if ($request->input('to_message') == $id) {
         Answer::create(['answer' => $request->input('answer'), 'user_id' => \Auth::id(), 'user_name' => \Auth::user()->name, 'to_message' => $request->input('to_message')]);
         flash()->success('Wiadomość prywatna została wysłana!');
         return redirect('/private/' . $request->input('to_message') . '');
     } else {
         return 'Oszust!';
     }
 }
Esempio n. 19
0
 public function show($id, Request $request)
 {
     //show answers
     if ($request->user()->role == "teacher") {
         $submitted = Homework::findOrFail($id)->with(['Answer'])->get();
     } elseif ($request->user()->role == "student") {
         $homework = Homework::findOrFail($id);
         $submitted = Answer::where('homework_id', $id)->where('user_id', $request->user()->id)->with('user')->get();
         return view('submitted')->with("submitted", $submitted)->with('homework', $homework);
     }
     return view('submitted')->with("submitted", $submitted);
 }
Esempio n. 20
0
 /**
  * Get Children by User id.
  * @given Id of the user :id
  * @param Request $request
  * @return User
  */
 public function getUserChildren(Request $request)
 {
     $user = User::find($this->user->id);
     if (isset($user->id)) {
         $items = $user->getDescendants()->toHierarchy();
         if (count($items) > 0) {
             return Answer::set(200, $items);
         } else {
             return Answer::set(200, Lang::get('api.noUserChildren'), 404);
         }
     }
     return Answer::set(404, Lang::get('api.noUser'), 404);
 }
 public function store(AnswerRequest $request)
 {
     $client = Client::create();
     //Was macht hier das ->all();
     $questionData = $request->all();
     foreach ($questionData["radio_question"] as $question => $value) {
         $answer = new Answer();
         $answer->question_id = $question;
         $answer->answer = $value;
         $answer->client_id = $client->id;
         //Unterschied zwischen ->save und ::create
         $answer->save();
     }
     //Kann man das irgendwie sauberer lösen als mit dieser foreach Schleife, damit es DRY-Kompatibel ist?
     foreach ($questionData["text_question"] as $question => $value) {
         $answer = new Answer();
         $answer->question_id = $question;
         $answer->comment = $value;
         $answer->client_id = $client->id;
         //Unterschied zwischen ->save und ::create
         $answer->save();
     }
 }
Esempio n. 22
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Factory::create('fr_FR');
     $subjectsCount = Subject::all()->count();
     for ($qcms = 0; $qcms < 100; $qcms++) {
         $qcm = Qcm::create(['user_id' => 1, 'subject_id' => rand(1, $subjectsCount - 1), 'name' => $faker->sentence(6), 'description' => $faker->sentence(40)]);
         for ($questions = 0; $questions < rand(5, 10); $questions++) {
             $question = Question::create(['qcm_id' => $qcm->id, 'question' => $faker->sentence(20)]);
             for ($answers = 0; $answers < rand(2, 4); $answers++) {
                 Answer::create(['question_id' => $question->id, 'answer' => $faker->sentence(10), 'isValid' => $answers == 0]);
             }
         }
     }
 }
Esempio n. 23
0
 function answers()
 {
     $add = 1;
     $faker = Faker::create();
     $users = User::all();
     $questions = Question::lists('id');
     foreach ($users as $user) {
         foreach ($questions as $q) {
             $add++;
             $ts = \Carbon\Carbon::createFromDate(2015, 07, 22)->addMinutes($add)->toDateTimeString();
             Answer::create(['user_id' => $user->id, 'question_id' => $q, 'body' => $faker->paragraph, 'created_at' => $ts, 'updated_at' => $ts]);
         }
     }
 }
Esempio n. 24
0
 public function storeQuiz(Request $request, $lecture_id, $subject_id, $assignment_id)
 {
     $point = 0;
     $answers = Input::get('answers');
     $request->user()->assignments()->attach(array($assignment_id));
     $request->user()->answers()->attach($answers);
     foreach ($answers as $answer_id) {
         $answer = Answer::find($answer_id);
         if ($answer->correct) {
             $point++;
         }
     }
     DB::update('UPDATE (users_assignments) SET point=? WHERE user_id=? AND assignment_id=?', [$point, $request->user()->id, $assignment_id]);
     return redirect('/lectures/' . $lecture_id . '/assignments');
 }
 public function storeQuiz(Request $request, $lecture_id, $subject_id, $topic_id, $knowledgeunit_id)
 {
     $point = 0;
     $answers = Input::get('answers');
     $request->user()->knowledgeunits()->attach(array($knowledgeunit_id));
     $request->user()->answers()->attach($answers);
     foreach ($answers as $answer_id) {
         $answer = Answer::find($answer_id);
         if ($answer->correct) {
             $point++;
         }
     }
     DB::update('UPDATE (users_knowledgeunits) SET point=? WHERE user_id=? AND knowledgeunit_id=?', [$point, $request->user()->id, $knowledgeunit_id]);
     return redirect('/lectures/' . $lecture_id . '/subjects/' . $subject_id . '/topics/' . $topic_id . '/knowledgeunits/' . $knowledgeunit_id . '/quiz');
 }
Esempio n. 26
0
 /**
  * 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');
 }
Esempio n. 27
0
 public function store()
 {
     $data = Input::all();
     if (Input::get('comment_id') == '') {
         if (Comment::create($data)) {
             return Redirect::back()->withErrors(Null);
         } else {
             return Redirect::back()->withInput()->withErrors('comment publish fail!');
         }
     } else {
         if (Answer::create($data)) {
             return Redirect::back()->withErrors(Null);
         } else {
             return Redirect::back()->withInput()->withErrors('comment reply fail!');
         }
     }
 }
 /**
  * Store a user's quiz score into storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  Quiz $quiz
  * @return \Illuminate\Http\Response
  */
 public function userQuiz(Request $request, Quiz $quiz)
 {
     //        if(Gate::denies('allow-quiz', $quiz->id)){
     //            redirect()->action('QuizzesController@index');
     //        };
     $answers = collect([]);
     for ($i = 0; $i < $quiz->questions->count(); $i++) {
         if ($request->has('select.' . $i)) {
             $answer = Answer::findOrFail($request->input('select.' . $i));
             $answers = $answers->merge([$answer]);
         }
     }
     $score = $answers->whereLoose('correct', 1)->count();
     $attempt = Auth::user()->hasQuizAttempt($quiz->id) ? Auth::user()->lastQuizTaken($quiz->id)->pivot->attempt + 1 : 1;
     Auth::user()->quizzes()->attach($quiz->id, ['score' => $score, 'attempt' => $attempt]);
     return view('quiz.score', ['answers' => $answers, 'attempt' => $attempt]);
 }
Esempio n. 29
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $test = Test::create($request->all());
     $score = 0;
     $quiz = Quiz::find($request->get('quiz_id'));
     foreach ($quiz->questions as $question) {
         if ($request->has($question->id)) {
             $result = Result::create(['quiz_id' => $request->get('quiz_id'), 'user_id' => $request->get('user_id'), 'test_id' => $test->id, 'question_id' => $question->id, 'answer_id' => $request->get($question->id)]);
             $answer = Answer::find($request->get($question->id));
             if ($answer->correct) {
                 $score += 1;
             }
         }
     }
     $test->score = $score;
     $test->save();
     return redirect()->route('tests.result', $test);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     // $this->call(ClassTableSeeder::class);
     //Optional just to clear table
     // DB::table('answers')->delete();
     // DB::table('questions')->delete();
     // DB::table('classes')->delete();
     // DB::table('users')->delete();
     $student1 = User::create(['name' => 'Scotty Gomez', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $student2 = User::create(['name' => 'Misha Dowd', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $lecturer = User::create(['name' => 'Dr. Andre Chen', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'lecturer']);
     $this->command->info('User Created!');
     $course = Course::create(['name' => 'Math', 'term' => 'Fall2020', 'lecturer_id' => $lecturer->id]);
     $this->command->info('Course Created!');
     $quiz = Quiz::create(['course_id' => $course->id, 'description' => 'A Quiz to Test Your Might!', 'quizTime' => '20', 'startDate' => '10.29.2015', 'endDate' => '10.30.2015']);
     $this->command->info('Quiz Created!');
     //Questions
     $q = Question::create(['prompt' => 'What is the sqare root of 4?', 'difficulty' => 'easy']);
     $q1 = Question::create(['prompt' => 'What is 2 X 3?', 'difficulty' => 'easy']);
     $this->command->info('2 Questions Created!');
     //Answers
     $a = Answer::create(['text' => '6', 'image' => NULL]);
     $a1 = Answer::create(['text' => '2', 'image' => NULL]);
     $a2 = Answer::create(['text' => '6', 'image' => NULL]);
     $a11 = Answer::create(['text' => '5', 'image' => NULL]);
     $this->command->info('All 4 Answers Created!');
     // Adding User to Course
     $course->users()->sync([$student1->id, $student2->id]);
     // Syncing Quiz to Questions
     $quiz->questions()->sync([$q->id, $q1->id]);
     // Syncing (Binding Qustion to Answer)
     $q->answers()->sync([$a->id, $a1->id]);
     $q1->answers()->sync([$a2->id, $a11->id]);
     $this->command->info('Everything Created and Linked!');
     Model::reguard();
 }