/**
  * Setting question to not answered, if question wasnt answered.
  *
  * @return Response
  */
 public function setNotanswered($id)
 {
     $question = \App\Question::find($id);
     $question->status = "notanswered";
     $question->save();
     return redirect()->to('moderator');
 }
 /**
  * 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']]);
     }
 }
 public function storeTranscription($surveyId, $questionId, Request $request)
 {
     $callSid = $request->input('CallSid');
     $question = Question::find($questionId);
     $questionResponse = $question->responses()->where('session_sid', $callSid)->firstOrFail();
     $questionResponse->responseTranscription()->create(['transcription' => $this->_transcriptionMessageIfCompleted($request)]);
 }
Exemple #4
0
 public function delete_item($q_id)
 {
     $q = Question::find($q_id);
     $this->authorize('qna-edit', $q);
     $q->delete();
     return redirect('qs');
 }
 public function store($questionId)
 {
     $answer = Request::user()->answers()->create(['answer' => Request::input('answer')]);
     $question = Question::find($questionId);
     $question->answers()->save($answer);
     return redirect()->back();
 }
Exemple #6
0
 public function proposeSolution()
 {
     $questionId = Request::get('questionId');
     $question = Question::find($questionId);
     $answers = $question->answers()->get()->toArray();
     // Prepare array of proposed answers
     $proposedSolution = [];
     if ($question->question_type == 'one_variant') {
         $proposedSolution[] = (int) Request::get('chosenAnswer');
     } else {
         $proposedSolution = Request::get('chosenAnswers');
     }
     // Prepare array of correct answers
     $correctSolution = [];
     foreach ($answers as $answer) {
         if ($answer['is_correct']) {
             $correctSolution[] = $answer['id'];
         }
     }
     $proposedSolutionResult = $proposedSolution == $correctSolution;
     // pass to response detailed results on proposed solution
     $proposedSolutionWithDetailedResult = [];
     foreach ($proposedSolution as $answerId) {
         foreach ($answers as $answer) {
             if ($answer['id'] == $answerId) {
                 $is_correct = $answer['is_correct'];
             }
         }
         $proposedSolutionWithDetailedResult[$answerId] = $is_correct;
     }
     if (\Auth::user()) {
         \Auth::user()->replies()->updateOrCreate(['question_id' => $questionId], ['is_correct' => $proposedSolutionResult]);
     }
     return response()->json(['correctSolution' => $correctSolution, 'proposedSolutionWithDetailedResult' => $proposedSolutionWithDetailedResult, 'proposedSolutionResult' => $proposedSolutionResult]);
 }
 /**
  * Store a newly created resource in storage.
  * Assumption: All quesitons are multi-value,
  *      Questions are in the database already
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $scoreCard = session('score_card');
     if (Question::find($request->qID)->type == 'free-response') {
         $free_response;
         $question = Question::find($request->qID);
         if ($scoreCard->responses()->where('question_id', $question->id)->count() >= 1) {
             $free_response_id = $scoreCard->responses()->where('question_id', $question->id)->first()->id;
             $free_response = FreeResponse::find($free_response_id);
         } else {
             $free_response = new FreeResponse();
         }
         $free_response->question_id = $request->qID;
         $free_response->response = $request->response;
         $free_response->score_card_id = $scoreCard->id;
         $free_response->save();
         $scoreCard->responses()->save($free_response);
     } else {
         $answers = $scoreCard->answer_questions()->wherePivot('question_id', '=', $request->qID)->get();
         $student_response = $scoreCard->questions()->where('questions.id', '=', $request->qID)->get();
         $studentAnswers = array();
         foreach (Question::find($request->qID)->answers()->get() as $a) {
             if ($request->has('cb' . $a->pivot->id)) {
                 array_push($studentAnswers, $a->pivot->id);
             }
         }
         if (count($studentAnswers) > 0) {
             // echo "detaching...<br>";
             $scoreCard->questions()->detach($request->qID);
             foreach ($studentAnswers as $a) {
                 // echo "attaching...".$a."<br>";
                 $scoreCard->questions()->attach($request->qID, array('answer_question_id' => $a));
             }
         } else {
             $scoreCard->questions()->detach($request->qID);
             $scoreCard->questions()->attach($request->qID, array('answer_question_id' => null));
         }
     }
     if ($request->has('next')) {
         $question = $scoreCard->next();
         if ($question != null) {
             $questionNumber = $request->session()->get('questionNumber');
             $questionNumber++;
             $request->session()->put('questionNumber', $questionNumber);
             return $this->goto_qustion($question, $scoreCard);
         } else {
             return redirect('/finished_quiz');
         }
     }
     if ($request->has('prev')) {
         $question = $scoreCard->prev();
         if ($question != null) {
             $questionNumber = $request->session()->get('questionNumber');
             $questionNumber--;
             $request->session()->put('questionNumber', $questionNumber);
             return $this->goto_qustion($question, $scoreCard);
         }
     }
 }
 /**
  * Responds to request to POST /question/edit/{question_id}
  */
 public function postQuestionEdit($question_id, Request $request)
 {
     $this->validate($request, ['question' => 'required|min:5']);
     $question = Question::find($question_id);
     $question->question = $request->question;
     $question->save();
     return redirect('/edit/' . $question->quiz_id . '#question' . $question_id);
 }
 private function _questionAfter($questionId)
 {
     $question = \App\Question::find($questionId);
     $survey = \App\Survey::find($question->survey_id);
     $allQuestions = $survey->questions()->orderBy('id', 'asc')->get();
     $position = $allQuestions->search($question);
     $nextQuestion = $allQuestions->get($position + 1);
     return $this->_idIfNotNull($nextQuestion);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = $request->user();
     $question = Question::find($request->id);
     if ($user && $user->id === $question->user_id) {
         return $next($request);
     }
     return redirect()->back();
 }
Exemple #11
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()]);
 }
 /**
  * @param $id
  * @param bool $withOrganizations
  * @return mixed
  * @throws GeneralException
  */
 public function findOrThrowException($id, $withProject = false)
 {
     if ($withProject) {
         $question = Question::with('project')->find($id);
     } else {
         $question = Question::find($id);
     }
     if (!is_null($question)) {
         return $question;
     }
     throw new GeneralException('That question does not exist.');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $q = Question::find($id);
     if (!$q) {
         return response()->json(array('msg' => 'Not found'), 404);
     }
     if ($q->update($request->all())) {
         return response()->json($q);
     }
     return response()->json(array('msg' => 'Update faild'), 400);
 }
Exemple #14
0
 public function questionDel(Request $request)
 {
     Question::find($request->get('id'))->delete();
     Question::where('subId', $request->get('id'))->delete();
     $log = new Log();
     $log->memberId = Auth::user()->id;
     $log->detail = 'Delete Post,' . $request->get('id');
     $log->save();
     if ($request->get('redirect') == '') {
         return redirect(route('home'));
     } else {
         return redirect(html_entity_decode($request->get('redirect')));
     }
 }
 /**
  * Delete a question
  * @param Request $request
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function destroy(Request $request, $id)
 {
     $event = Event::find($request->input('event'));
     $question = Question::find($id);
     if ($question && $event->user_id == $request->user()->id) {
         $question->delete();
         //Flash a message to the user
         \Flash::success('Question deleted');
     } else {
         //Flash a message to the user
         \Flash::danger('Sorry, permission denied');
     }
     //Redirect back to the admin page
     //return redirect(action('EventsController@admin', $request->input('event')));
     return Redirect::back()->with(['tabName' => 'questions']);
 }
Exemple #16
0
 public function editQuestion(Request $request)
 {
     $data = $request;
     $id = 0;
     if (isset($data->id)) {
         $id = $data->id;
     }
     if ($id > 0) {
         $obj = Question::find($id);
     }
     //$obj->category_id = $data->category;
     $obj->question = $data->question;
     $obj->possibilities = json_encode($data->possibilities);
     $obj->correct = $data->checkbox;
     $obj->save();
     return redirect('questions');
 }
 public function edit(Request $request, $lecture_id, $subject_id, $topic_id, $knowledgeunit_id, $question_id, $answer_id)
 {
     $lecture = Lecture::find($lecture_id);
     $subject = Subject::find($subject_id);
     $topic = Topic::find($topic_id);
     $knowledgeunit = KnowledgeUnit::find($knowledgeunit_id);
     $question = Question::find($question_id);
     $answer = Answer::find($answer_id);
     $data["nav"] = "<a href=\"" . url('/lectures/') . "\">" . $lecture->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/') . "\">" . $subject->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/') . "\">" . $topic->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/' . $topic->id . '/knowledgeunits') . "\">" . $knowledgeunit->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/' . $topic->id . '/knowledgeunits/' . $knowledgeunit->id . '/questions') . "\">" . $question->title . "</a>";
     $data["lecture_id"] = $lecture_id;
     $data["subject_id"] = $subject_id;
     $data["topic_id"] = $topic_id;
     $data["knowledgeunit_id"] = $knowledgeunit_id;
     $data["question_id"] = $question_id;
     $data["answer"] = $answer;
     return view('answer.edit', $data);
 }
Exemple #18
0
 public function saveQuestion()
 {
     $input = Input::all();
     if (!empty($input['questionid'])) {
         $question = Question::find($input['questionid']);
     } else {
         $question = new Question();
     }
     $question->exam = $input['exam'];
     $question->body = $input['examtitle'];
     $question->choices = json_encode($input['choices']);
     if (!empty($input['questionid'])) {
         $question->save();
     } else {
         $question->save();
     }
     return redirect()->intended('/assessment/exams/' . $input['examcode'] . '/edit');
 }
Exemple #19
0
 public function getUpvote($id)
 {
     $question = \App\Question::find($id);
     // count if user has alreqdy voted for question
     $checkVoteStatus = \App\Check::where('session_id', '=', Session::get('user'))->where('question_id', '=', $id)->count();
     if ($question) {
         if ($checkVoteStatus >= 1) {
             // if user has voted return a failed upvote response
             return response()->json(['success' => false]);
         }
         $question->votes += 1;
         $question->save();
         // saving session for checking users
         $checker = new \App\Check();
         $checker->question_id = $id;
         $checker->session_id = Session::get('user');
         $checker->save();
         return response()->json(['success' => true]);
     }
 }
 /**
  * Validates the answer
  *
  * @param Request $request
  * @param $id
  * @return mixed
  */
 public function validateAnswer(Request $request, $id)
 {
     $this->validate($request, ['answer' => 'required|in:A,B,C,D']);
     $answer = $request->answer;
     $data = [];
     $question = Question::find($id);
     if (!\Auth::user()->answeredQuestions->contains($question->id)) {
         $data['answered'] = false;
         $user_response = 'option_' . $answer;
         $correct_answer = 'option_' . $question->answer;
         \Auth::user()->answeredQuestions()->attach($question->id, array('user_response' => $question->{$user_response}, 'answer' => $question->{$correct_answer}, 'question' => $question->question));
         $data['answer'] = $question->answer;
         if ($question->answer == $answer) {
             $data['correct'] = true;
             $data['score'] = \Auth::user()->score += $question->difficulty_rating;
         } else {
             $data['score'] = \Auth::user()->score -= 1;
         }
         \Auth::user()->save();
     } else {
         $data['answered'] = true;
     }
     return \Response::json($data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // retrieve model from database and delete it
     $question = Question::find($id);
     $question->delete();
     // after deletion, redirect
     return redirect('/question');
 }
 public function store(Request $request)
 {
     if (!Auth::check()) {
         return redirect('home')->with('message', "Veuillez d'abord vous connecter");
     }
     // this block takes care of redirecting to the proper question
     if ($request->input('next')) {
         $user = Auth::user();
         $question = Question::find($request->input('question_id'));
         $question->setAnswer($request->input('user_reply'));
         if ($request->input('next_question_id')) {
             return redirect('questions/' . $request->input('next_question_id'));
         } else {
             return redirect('finish');
         }
     }
     if ($request->input('previous')) {
         $user = Auth::user();
         $question = Question::find($request->input('question_id'));
         $question->setAnswer($request->input('user_reply'));
         return redirect('questions/' . $request->input('previous_question_id'));
     }
     // this is the normal flow when a new question is stored :
     $this->validate($request, ['question' => 'required', 'replies' => 'required', 'help' => 'required']);
     Question::create($request->all());
     return redirect('questions');
 }
Exemple #23
0
 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]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroyQuestion($id)
 {
     $question = \App\Question::find($id);
     $question->delete();
     return redirect()->back();
 }
 public function destroy(Request $request, $lecture_id, $subject_id, $topic_id, $knowledgeunit_id, $question_id)
 {
     $question = Question::find($question_id);
     $question->delete();
     return redirect('/lectures/' . $lecture_id . '/subjects/' . $subject_id . '/topics/' . $topic_id . '/knowledgeunits/' . $knowledgeunit_id . '/questions');
 }
 public function delete($id)
 {
     $row = Question::find($id);
     $row->delete();
     return redirect('question');
 }
Exemple #27
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     $question = Question::find($id);
     return view('question.edit', compact('question'));
 }
 public function edit($id)
 {
     $question = Question::find($id);
     return view('questions.edit')->with('question', $question);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param $id
  * @return Response
  */
 public function postDelete(DeleteRequest $request, $id)
 {
     $question = Question::find($id);
     $question->delete();
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $question = Question::find($id);
     return $question->toJson();
 }