/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = JWTAuth::parseToken()->authenticate(); $user_id = $user->id; $question = Question::find($request['question_id']); if (!$question) { return response()->json(['success' => false, 'message' => "invalid question id."]); } $question_owner = $question->owner(); // dd($question_owner); if ($user->points == 0) { return response()->json(['success' => false, 'message' => "Please recharge"]); } //validate data $validator = Validator::make($request->all(), array('text' => 'required', 'question_id' => 'required')); if ($validator->fails()) { return $validator->errors()->all(); } else { $previousAnswer = Answer::where('question_id', $request['question_id'])->where('user_id', $user_id)->get(); if (count($previousAnswer) > 0) { return response()->json(['success' => false, 'message' => "You've already answered this question before.", 'answer' => $request['text']]); } else { $follower_user = $user->id . "_" . $question_owner->id; Answer::create(['text' => $request['text'], 'user_id' => $user_id, 'question_id' => $request['question_id'], 'follower_user' => $follower_user]); try { $user->addFollowing($question_owner); $user->points = $user->points - 1; $user->save(); } catch (Exception $e) { } } return response()->json(['success' => true, 'message' => "Answer Added Successfully", 'answer' => $request['text']]); } }
/** * 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'); }); } } } } } }
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 ""; } }
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); }
/** * api function get answers for a questions * * @param $request the request * @param int $qid the question for which to fetch answers * @return json the answers json object */ public function all(Request $request, $qId) { if (!Auth::check()) { return Response::json(['error' => ['message' => 'not authorized, not logged in']]); } else { if (!Auth::user()->isAdmin()) { return Response::json(['error' => ['message' => 'not authorized, elevated permissions needed']]); } } $answerCount = Answer::count(); // get the questions for that page $answers = Answer::where('question_id', $qId)->get(); $result = array('answers' => $answers, 'answerCount' => $answerCount, 'qId' => $qId); return $result; }
/** * 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(""); } }
/** * 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'); }
public function edit_question() { $data = Input::all(); $event = Event::where('id', Session::get('event_id'))->first(); $question = Question::where('id', '=', Session::get('qid'))->first(); $question->event_id = Session::get('event_id'); $question->question = $data['question']; $image = array(); if (isset($data['file'])) { if (Input::file('file')->isValid()) { $destinationPathvfile = 'uploads'; $extensionvfile = Input::file('file')->getClientOriginalExtension(); $fileNamevfile = $event->id . '.' . $extensionvfile; // renaming image Input::file('file')->move($destinationPathvfile, $fileNamevfile); $question->image = $fileNamevfile; } } if (isset($data['html'])) { $question->html = $data['html']; } if (intval($event->type) > 2) { $question->options = serialize($data['options']); $answers = $data['answers']; $question->save(); Session::put('qid', Question::all()->last()->id); $answer = Answer::where('ques_id', '=', Session::get('qid'))->delete(); foreach ($answers as $ans) { $answer = new Answer(); $answer->ques_id = Session::get('qid'); $answer->answer = $ans; $answer->score = 1; $answer->incorrect = 0; $answer->save(); } } else { $question->level = $data['level']; $question->save(); Session::put('qid', Question::all()->last()->id); $answer = Answer::where('ques_id', '=', Session::get('qid'))->first(); $answer->ques_id = Session::get('qid'); $answer->answer = $data['answer']; $answer->score = 1; $answer->incorrect = 0; $answer->save(); } Session::put('event_id', $event->id); return Redirect::route('viewquestions', ['event_id' => $event->id])->with('message', 'Question Successfully Edited'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $question = Question::findOrFail($id); $answers = Answer::where('question_id', '=', $id); $answers->update(['trash' => true]); $question->update(['trash' => true]); \Session::flash('flash_message', 'Въпросът беше успешно изтрит!'); return redirect()->route('admin.question.index'); }
/** * 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'); }
/** * Count the number of correct answers for a question * * @return int */ public function numberOfCorrectAnswers() { return Answer::where('question_id', '=', $this->id)->where('correct', 1)->count(); }
public function timeline($element, $student) { $diagramme = Answer::where("element", $element)->where('student', $student)->get(); return view('auswertung.timeline', compact('diagramme')); }
public function removeAnswersBy($user) { try { $answers = Answer::where('follower_user', $user->id . '_' . $this->id)->get(); if ($answers) { foreach ($answers as $ans) { $ans->delete(); } } } catch (Exception $ex) { } }
/** * Get all of the answers for a given question. * * @param Question $question_id * @return Collection */ public function forQuestion($question_id) { return Answer::where('answers.question_id', $question_id)->orderBy('created_at', 'asc')->get(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $answers = Answer::where('user_id', Auth::user()->id)->paginate(); return view('teacher.answers.index')->with('answers', $answers)->with('title', trans('titles.answers')); }
public function manage($question_id) { $answers = Answer::where('question_id', $question_id)->get()->reverse(); $question = Question::find($question_id); return view('questions.answers.manage')->with(['answers' => $answers, 'question' => $question]); }
public function getAllFollower() { $user = JWTAuth::parseToken()->authenticate(); $followers = $user->getAllFollowers(); foreach ($followers as $follower) { $ans = Answer::where('follower_user', $follower->id . '_' . $user->id)->orderBy('created_at', 'desc')->first()->text; array_add($follower, 'answer', $ans); } return response()->json(['success' => true, 'follower' => $followers]); }
public function editquestion($id) { $data = Question::where('id', '=', $id)->first(); Session::put('qid', $id); if (Auth::user()->privilege > 6 || Event::where('id', $data->event_id)->first()->society_id == Auth::user()->id) { $type = Event::where('id', $data->event_id)->first()->type; $ans = Answer::where('ques_id', $id)->get()->pluck('answer')->toArray(); return \View::make('edit_ques', ['data' => $data, 'type' => $type, 'ans' => $ans]); } else { return Redirect::route('dashboard')->with('error', "Access Denied"); } }
public function viewPastQuiz($year, $month, $day) { if ($year < date('Y')) { // } else { if ($year == date('Y') && $month < date('n')) { /// } else { if ($year == date('Y') && $month == date('n') && $day < date('j')) { // } else { return redirect()->route('home'); } } } $firstMonday = date("j", strtotime('first monday of ' . $year . '-' . $month)); $leagueYear = $year; if ($firstMonday > $day) { $leagueMonth = $month - 1; if (!$leagueMonth) { $leagueMonth = 12; $leagueYear--; } } else { $leagueMonth = $month; } $dayOffset = 0; $round = 0; for ($i = 0; $i < 20; $i++) { $round++; if (date("d-m-Y") == date("d-m-Y", strtotime('first monday of ' . $leagueYear . '-' . $leagueMonth) + 86400 * $dayOffset)) { break; } if (($i + 1) % 5 == 0) { $dayOffset = $dayOffset + 3; } else { $dayOffset++; } } if ($round % 10 == 0) { $solo = true; } else { $solo = false; } $questions = Question::where('year', $year)->where('month', $month)->where('day', $day)->get(); $filetype = []; $answers = []; foreach ($questions as $key => $question) { $filetype[$question->genre_id] = pathinfo($question->filename, PATHINFO_EXTENSION); $answers[$question->genre_id] = ''; } $user_id = Auth::user()->id; $submitted = false; foreach ($questions as $key => $question) { $answer = Answer::where('question_id', $question['id'])->where('user_id', $user_id)->where('submitted', 1)->first(); if ($answer) { $answers[$question['genre_id']] = $answer; if ($answer->submitted) { $submitted = true; } } else { $answers[$question['genre_id']] = null; } } return view('quiz_answered')->with(['questions' => $questions, 'answers' => $answers, 'filetype' => $filetype, 'year' => $year, 'month' => $month, 'day' => $day, 'solo' => $solo]); }
public function startTestRoomTest($code) { $testroom = TestRoom::where('code', '=', $code)->get()[0]; $questions_id = explode(', ', $testroom->questions_id); foreach ($questions_id as $key => $value) { $questions[$key] = Question::find($value); } shuffle($questions); Session::put('questions', $questions); foreach ($questions as $key => $value) { $answers[$key] = Answer::where('question_id', '=', $value->id)->orderByRaw("RAND()")->get(); } Session::put('answers', $answers); return view('test.test', ['question' => $questions['0'], 'answers' => $answers['0'], 'type' => $questions[0]->type, 'key' => '0', 'testroomcode' => $code]); }
public function viewCheats($year, $month, $day, $user_id) { $user = User::find($user_id); $start = Carbon::createFromDate($year, $month, $day)->hour(0)->minute(0)->second(0); $end = Carbon::createFromDate($year, $month, $day)->hour(23)->minute(59)->second(59); $cheats = Cheat::where('user_id', $user_id)->whereBetween('created_at', [$start, $end])->get(); $answers = Answer::where('user_id', $user_id)->whereBetween('created_at', [$start, $end])->get(); $bigdata = $cheats->merge($answers)->sortBy('created_at'); return view('admin/cheats')->with(['bigdata' => $bigdata, 'user' => $user]); }
/** * Get the answers this questin uses. */ public function answers() { return Answer::where('answer_set_id', $this->answerSet->id)->get(); }
public function deleteQuestion($id) { $questions = Question::where('id', '=', $id)->where('trash', '=', true)->delete(); $answers = Answer::where('question_id', '=', $id)->where('trash', '=', true)->delete(); return back(); }