public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $s = Subquestions::find($id); if (count($s) < 1) { return redirect('/'); } $answers = Answers::where('SubQuestionID', '=', $id)->delete(); $s->delete(); }
public static function destroy($SpaceID) { if (!AuthController::checkPermission()) { return redirect('/'); } $space = Spaces::find($SpaceID); $answers = Answers::where('SpaceID', '=', $SpaceID)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } $space->delete(); return; }
public function show($title, $id) { if ($id == "") { return ""; } $data["question"] = Questions::with('question_classif')->where('id', $id)->first(); // print_r($data["question"]); /* clients can see only question with status 0002 */ if (!Auth::check() && $data["question"]->status != '0002') { return redirect('/questions'); } $data['answers'] = Answers::where('qid', $id)->get(); $data['tags'] = DB::table('questions_tags')->join('questions_tags_rel', 'questions_tags.id', '=', 'questions_tags_rel.tid')->where('questions_tags_rel.qid', '=', $id)->get(); return view('questions/question', $data); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if (!AuthController::checkPermission()) { return redirect('/'); } $data = $request->all(); $newCount = $data['numAnswer']; $setOfOldAnswers = Answers::where('QuestionID', '=', $id)->get()->toArray(); $oldCount = count($setOfOldAnswers); // dd($setOfOldAnswers); $result = $data['resultQuestion']; // update answers // overwrite min($newCount, $oldCount) record $needToOverwrite = $newCount < $oldCount ? $newCount : $oldCount; for ($i = 0; $i < $needToOverwrite; $i++) { $answer = Answers::find($setOfOldAnswers[$i]['id']); // dd($answer); // $answer->QuestionID = $data['QuestionID']; $detail = $data['answer' . ($i + 1)]; $answer->Detail = trim($this->c2s_convert($detail)); if ($result != $i + 1) { $answer->Logical = 0; } else { $answer->Logical = 1; } // dd($answer); $answer->update(); } // if $newCount < $oldCount => delete redudant record for ($i = $newCount; $i < $oldCount; $i++) { $answer = Answers::find($setOfOldAnswers[$i]['id']); $answer->delete(); } // if $newCount > $oldCount => insert new record for ($i = $oldCount; $i < $newCount; $i++) { $this->add_answer($id, $result != $i + 1 ? 0 : 1, $this->c2s_convert($data['answer' . ($i + 1)])); } return redirect(route('answer.edit', $id)); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { //Question database tablosundan ilgili id ile veriyi(soruyu) cekiyor. $question = Questions::findOrNew($id); $votes = Vote::where('content_id', $id)->where('content', 'question')->get(['vote']); if ($votes) { $vote = 0; foreach ($votes as $vote_t) { $vote += $vote_t['vote']; } $question['vote'] = $vote; } else { $question['vote'] = 0; } //Answers tablosundan ilgili questionla ilgili var ise cevaplari(Answers) buluyor ve getiriyor. $answers = Answers::where('question_id', $id)->get(); foreach ($answers as $answer) { $answer_votes = Vote::where('content_id', $answer->id)->where('content', 'q_answer')->get(['vote']); if ($answer_votes) { $vote = 0; foreach ($answer_votes as $vote_t) { $vote += $vote_t['vote']; } $answer['vote'] = $vote; } else { $answer['vote'] = 0; } } //Gerekli view a aldigi verilerle birlikte gonderiyor ve sayfa aciliyor. return view('QA.show')->with('question', $question)->with('answers', $answers); }
public function get_answers_ids_by_question_id($q_id) { $answers = Answers::where('question_id', '=', $q_id)->get(); return $answers; }
public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $question = Questions::find($id); @unlink(public_path('images/imageQuestion/' . $question['Photo'])); $postid = $question['PostID']; $format = $question['FormatID']; switch ($format) { case 1: case 6: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { AnswersController::destroy($answer['id']); } break; case 2: $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray(); foreach ($spaces as $value) { SpacesController::destroy($value['id']); } break; case 3: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { AnswersController::destroy($answer['id']); } break; case 4: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { AnswersController::destroy($answer['id']); } break; case 5: $subq = Subquestions::where('QuestionID', '=', $id)->get()->toArray(); foreach ($subq as $s) { SubquestionsController::destroy($s['id']); } } $question->delete(); return redirect(route('user.viewpost', $postid)); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $question = Questions::find($id); @unlink(public_path('images/imageQuestion/' . $question['Photo'])); $postid = $question['PostID']; $format = Posts::find($postid)['FormatID']; if ($format == 1) { $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } } else { if ($format == 2) { $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray(); foreach ($spaces as $value) { SpacesController::destroy($value['id']); } } } $question->delete(); return redirect(route('user.viewpost', $postid)); }
public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } // return redirect('/'); $s = Subquestions::find($id); if (count($s) < 1) { return redirect('/'); } $answers = Answers::where('SubQuestionID', '=', $id)->get()->toArray(); foreach ($answers as $a) { AnswersController::destroy($a['id']); } @unlink(public_path('images/imageSubquestion/' . $s['Photo'])); $s->delete(); }
echo $count_answer++; ?> :</h3></a> @else <h3 class="title" id="title_question_{!! $key + 1 !!}">Câu hỏi số <?php echo $count_answer++; ?> :</h3> @endif <h4 class="title"> <?php $subP = \App\Questions::getFilledQuestion($q['Question']); $Answers = array(); $Spaces = \App\Spaces::where('QuestionID', '=', $q['id'])->get()->toArray(); foreach ($Spaces as $value) { $Answers += array($value['id'] => \App\Answers::where('SpaceID', '=', $value['id'])->get()->toArray()); } foreach ($Spaces as $key => $value) { $setOfSpaces = array_merge($setOfSpaces, [$value['id']]); } reset($Spaces); // don't know what's different between this view & viewfilledquestion ?> <div style="color:#cc0066; font-weight:bold;"> @if (strlen($q['Description']) > 0) {!! nl2br($q['Description']) . ":" !!} @endif </div> <div> @foreach ($subP as $value) {!! nl2br($value) !!}
/** * @param $id * @param $input * @param $organizations * @return bool * @throws GeneralException */ public function update($id, $input, $project) { $result = $this->findOrThrowException($id, true); //print_r($input); print_r($result);die(); $related_id = $input['related_data']['q']; if (!empty($related_id)) { $this->flushParent($related_id, $result); } $result->section = $input['section']; if ($input['report'] == 'none' || empty($input['report'])) { $result->report = null; } else { $result->report = $input['report']; } $result->answers = $input['answers']; $result->related_data = $input['related_data']; $result->answer_view = $input['answer_view']; $result->sameanswer = isset($input['sameanswer']) ? 1 : 0; $display['qnum'] = isset($input['display']['qnum']) ? 1 : 0; $display['result'] = isset($input['display']['result']) ? 1 : 0; $result->display = $display; //$result->save(); //$toUpdate = $result->whereQnum($input['qnum'])->whereProjectId($project['project_id'])->first(); //dd($toUpdate); if ($result->whereQnum($input['qnum'])->whereProjectId($project['project_id'])->first()->update($input)) { \App\Answers::where('status_id', $result->id)->delete(); foreach ($input['answer'] as $qnum => $answers) { $q = $this->questions->getQuestionByQnum($qnum, $project->id); foreach ($answers as $akey => $aval) { if ($akey == 'radio') { $answerkey = $aval; } else { $answerkey = $akey; } $qanswer = $q->qanswers->where('akey', $answerkey)->first(); if (in_array($qanswer->type, ['radio', 'checkbox'])) { $answerVal = $qanswer->value; } else { $answerVal = $aval; } $answerR = \App\Answers::firstOrNew(['qid' => $q->id, 'akey' => $answerkey, 'status_id' => $result->id]); if (!empty($answerVal)) { $answerR->value = $answerVal; $result->answers()->save($answerR); } } } return true; } throw new GeneralException('There was a problem updating this result. Please try again.'); }
public function qa($id, $q, Request $request) { $user = User::find($request->user()->id); $exam = Exams::where(['code' => $id])->firstOrFail(); $availableQuestions = $exam->questions()->count(); if ($availableQuestions < $exam->items) { $exam->items = $availableQuestions; } $this->data['exam'] = $exam; if ($q == 0) { $thisactivity = new Activity(); $thisactivity->createActivity($user, 'exam', 'took the Exam : ' . $exam->title, 0); $thisassess = $user->assessment()->create(['exam_id' => $exam->id, 'status' => 0]); $this->data['status'] = "start"; } else { $assesment = User::find($user->id)->assessment()->where(['exam_id' => $exam->id])->get()->last(); $questions = $exam->questions()->whereNotExists(function ($query) use($user, $assesment) { $query->select('answers.question_id')->from('answers')->whereRaw('answers.question_id = questions.id AND answers.exam_id = questions.exam AND answers.user_id = "' . $user->id . '" AND answers.assessment_id = "' . $assesment->id . '"'); })->get(); if (count($questions)) { $question = $questions->random(1)->toArray(); $this->data['status'] = "exam"; $question['questionid'] = $q; $ac = 0; $questionarray = json_decode($question['choices']); $question['choices'] = array_map(function ($k, $a) { $b = []; $b['text'] = $a; $b['id'] = $k; return $b; }, range(0, count($questionarray) - 1), $questionarray); shuffle($question['choices']); $this->data['assessment'] = $assesment->toArray(); $this->data['question'] = $question; } else { $this->data['status'] = "result"; $correct = Answers::where(['exam_id' => $exam->id, 'assessment_id' => $assesment->id, 'user_id' => $user->id, 'answer' => 0])->count(); $answered = Answers::where(['exam_id' => $exam->id, 'assessment_id' => $assesment->id, 'user_id' => $user->id])->count(); $this->data['score'] = ['total' => $exam->items, 'answered' => $answered, 'correct' => $correct]; $assessment = $assesment; $assessment->status = 1; if ($exam->items > 0) { $assessment->score = $correct / $exam->items; } else { $assessment->score = 0; } $assessment->save(); } } return view('home.questions', $this->data); }
public function viewPost($postID) { if (!auth() || !auth()->user()) { $browser = get_browser(null, true); // Allow crawler && Facebook Bot view post without logging in. if ($browser['crawler'] != 1 && stripos($_SERVER["HTTP_USER_AGENT"], 'facebook') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'face') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'google') === false) { $redirectPath = '/post/' . $postID; return redirect('/auth/login')->with('redirectPath', $redirectPath); } $token = md5(rand(), false); $DisplayedQuestions = ConstsAndFuncs::$FreeQuestionsForCrawler; } $post = Posts::find($postID); if (count($post) < 1) { return view('errors.404'); } $post->visited++; $post->update(); $post = $post->toArray(); $courseID = $post['CourseID']; if (auth() && auth()->user()) { $userID = auth()->user()->getAuthIdentifier(); $tmp = Learning::where('UserID', '=', $userID)->where('CourseID', '=', $courseID)->get()->toArray(); if (count($tmp) < 1) { $learning = new Learning(); $learning->UserID = $userID; $learning->CourseID = $courseID; $learning->save(); $course = Courses::find($courseID); $course->NoOfUsers++; $course->update(); } // Insert a new record into DoExams Table to mark the time user start answering questions in post. $exam = new Doexams(); $exam->UserID = $userID; $exam->PostID = $postID; $token = md5($userID . rand(), false) . md5($postID . rand(), false); $exam->token = $token; $exam->save(); // Check if user is vip or not $user = User::find(auth()->user()->getAuthIdentifier()); if ($user['vip'] == 0) { $DisplayedQuestions = $post['FreeQuestions']; } else { $DisplayedQuestions = new \DateTime($user['expire_at']) >= new \DateTime() ? -1 : $post['FreeQuestions']; } if ($user['admin'] == 1) { $DisplayedQuestions = -1; } } $photo = $post['Photo']; if ($DisplayedQuestions > 0) { $questions = Questions::where('PostID', '=', $postID)->take($DisplayedQuestions)->get()->toArray(); } else { $questions = Questions::where('PostID', '=', $postID)->get()->toArray(); } $bundle = array(); $bundleAnswer = array(); $maxscore = 0; foreach ($questions as $q) { $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $bundle += array($q['id'] => $answer); $bundleAnswer += [$q['id'] => AnswersController::getAnswer($q['id'])]; if (count($answer) > 0) { $maxscore++; } } $Comments = Comments::all()->toArray(); $result = array('Comments' => json_encode($Comments), 'Title' => $post['Title'], 'Description' => $post['Description'], 'PostID' => $postID, 'Thumbnail' => $post['ThumbnailID'], 'Questions' => $questions, 'Photo' => $photo, 'Video' => $post['Video'], 'Bundle' => $bundle, 'BundleAnswers' => $bundleAnswer, 'MaxScore' => $maxscore, 'NumOfQuestions' => count($questions = Questions::where('PostID', '=', $postID)->get()->toArray()), 'Token' => $token, 'DisplayedQuestions' => $DisplayedQuestions); $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->get()->toArray(); $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->first()->toArray()['id']]; $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->get()->toArray(); $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->orderBy('created_at', 'desc')->first()->toArray()['id']]; $newpost = array_merge($nextPost, $previousPost); $result += ['newpost' => $newpost]; // dd($newpost); // return view('viewpost')->with(compact(['result', 'newpost'])); if ($post['FormatID'] == 1) { return view('viewpost', $result); } if ($post['FormatID'] == 2) { return view('viewfilledpost')->with($result); } }
/** * * Get single question page **/ public function getSingleQuestionPage($id) { $question = Questions::find($id); $quiz = QuestionCategories::where('question_id', '=', $id)->get()->first(); $is_answered = count(Answers::where('question_id', '=', $id)->get()); if ($is_answered > 0) { $is_answered = true; } else { $is_answered = false; } if (count($question) > 0) { return view('admin.single-question')->with(['quiz' => $quiz, 'question' => $question, 'is_answered' => $is_answered]); } }
/** * @param type $project * @param type $section * @param type $answers * @param type $incident_id * @param type $resultable * @param type $resultable_type * @return type * @throws GeneralException */ private function saveResults($project, $section, $raw_answers, $incident_id, $resultable, $resultable_type) { // this function defined in app\helpers.php $answers = array_filter_recursive($raw_answers); /** * Result is link between questions,location,paricipants and actual answer * mark the status * Results table is polymophic table between Participants, Locations and Results */ $result = Result::firstOrNew(['section_id' => $section, 'project_id' => $project->id, 'incident_id' => $incident_id, 'resultable_id' => $resultable->id, 'resultable_type' => $resultable_type]); if ($incident_id) { $result->incident_id = $incident_id; } $result->resultable_id = $resultable->id; $result->results = $answers; $result->section_id = $section; $current_user = auth()->user(); $result->user()->associate($current_user); $result->project()->associate($project); if (isset($resultable)) { $result->resultable()->associate($resultable); } if (!empty($answers)) { $result->information = $this->updateStatus($project, $section, $answers, $incident_id, $resultable, $resultable_type); if ($result->save()) { /** * Save actual answers after result status saved * delete all related answers before save. * More like overwriting old answers */ Answers::where('status_id', $result->id)->delete(); foreach ($answers as $qslug => $ans) { $q = $this->questions->getQuestionByQnum($qslug, $section, $project->id); foreach ($ans as $akey => $aval) { if ($akey == 'radio') { $answerkey = $aval; } else { $answerkey = $akey; } $qanswer = $q->qanswers->where('slug', $answerkey)->first(); if (!is_null($qanswer)) { if (in_array($qanswer->type, ['radio', 'checkbox'])) { $answerVal = $qanswer->value; } else { $answerVal = $aval; } $answerR = Answers::firstOrNew(['qid' => $q->id, 'akey' => $answerkey, 'status_id' => $result->id]); if (isset($answerVal) && !empty($answerVal)) { $answerR->value = $answerVal; $result->answers()->save($answerR); } } } } return $result; } } }
public function getSingleCorrectAnswer($id) { $answer = Answers::where('question_id', '=', $id)->get(); return $answer; }
public function viewPost($postID) { if (!auth() || !auth()->user()) { $browser = get_browser(null, true); // Allow crawler && Facebook Bot view post without logging in. if ($browser['crawler'] != 1 && stripos($_SERVER["HTTP_USER_AGENT"], 'facebook') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'face') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'google') === false) { $redirectPath = '/post/' . $postID; return redirect('/login')->with('redirectPath', $redirectPath); } $token = md5(rand(), false); $DisplayedQuestions = ConstsAndFuncs::$FreeQuestionsForCrawler; } $post = Posts::find($postID); if (count($post) < 1) { return view('errors.404'); } $courseID = $post['CourseID']; $course = Courses::find($courseID); $post->visited++; $post->update(); $post = $post->toArray(); if (auth() && auth()->user()) { $userID = auth()->user()->getAuthIdentifier(); if (User::find($userID)['admin'] < ConstsAndFuncs::PERM_ADMIN) { if ($course['Hidden'] == 1 || $post['Hidden'] == 1) { return view('errors.404'); } } $tmp = Learnings::where('UserID', '=', $userID)->where('CourseID', '=', $courseID)->get()->toArray(); if (count($tmp) < 1) { $learnings = new Learnings(); $learnings->UserID = $userID; $learnings->CourseID = $courseID; $learnings->save(); $course->NoOfUsers++; $course->update(); } // Insert a new record into DoExams Table to mark the time user start answering questions in post. $exam = new Doexams(); $exam->UserID = $userID; $exam->PostID = $postID; $token = md5($userID . rand(), false) . md5($postID . rand(), false); $exam->token = $token; $exam->save(); // Check if user is vip or not $user = User::find(auth()->user()->getAuthIdentifier()); if ($user['vip'] == 0) { $DisplayedQuestions = $post['NoOfFreeQuestions']; } else { $DisplayedQuestions = new \DateTime($user['expire_at']) >= new \DateTime() ? -1 : $post['NoOfFreeQuestions']; } if ($user['admin'] >= ConstsAndFuncs::PERM_ADMIN) { $DisplayedQuestions = -1; } // If web hasn't provide some VIP package // every user will be able to see full post if (ConstsAndFuncs::IS_PAID == 0) { $DisplayedQuestions = -1; } } $photo = $post['Photo']; if ($DisplayedQuestions > 0) { $questions = Questions::where('PostID', '=', $postID)->take($DisplayedQuestions)->get()->toArray(); } else { $questions = Questions::where('PostID', '=', $postID)->get()->toArray(); } $AnswersFor1 = array(); $TrueAnswersFor1 = array(); $AnswersFor2 = array(); $Spaces = array(); $SetOfSpaceIDs = array(); $Subquestions = array(); $AnswersFor5 = array(); $QuestionFor5IDs = array(); $AnswersFor6 = array(); $DragDropIDs = array(); $CompleteAnswersFor6 = array(); $AnswersFor3 = array(); $AnswersFor4 = array(); $FillCharacterIDs = array(); $ArrangedIDs = array(); $maxscore = 0; foreach ($questions as $q) { switch ($q['FormatID']) { case 1: // Trắc nghiệm $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); foreach ($answers as $a) { if ($a['Logical'] == 1) { $TrueAnswersFor1 += [$q['id'] => $a['id']]; break; } } $info = [$q['id'] => $answers]; if (count($answers) > 0) { $maxscore++; } $AnswersFor1 += $info; continue; case 2: // Điền từ $spaces = Spaces::where('QuestionID', '=', $q['id'])->get()->toArray(); $Spaces += [$q['id'] => $spaces]; foreach ($spaces as $s) { $SetOfSpaceIDs = array_merge($SetOfSpaceIDs, [$s['id']]); $a = Answers::where('SpaceID', '=', $s['id'])->get()->toArray(); shuffle($a); $AnswersFor2 += [$s['id'] => $a]; } $maxscore += count($spaces); continue; case 3: $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor3 += [$q['id'] => $answer[0]]; $ArrangedIDs = array_merge($ArrangedIDs, [$q['id']]); $maxscore++; continue; case 4: $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor4 += [$q['id'] => $answer[0]]; $FillCharacterIDs = array_merge($FillCharacterIDs, [$q['id']]); $maxscore++; continue; case 5: // Nối $subquestions = Subquestions::where('QuestionID', '=', $q['id'])->get()->toArray(); $answer = array(); foreach ($subquestions as $s) { $a = Answers::where('SubQuestionID', '=', $s['id'])->get()->toArray(); $answer += [$s['id'] => $a[0]]; } $AnswersFor5 += [$q['id'] => $answer]; $maxscore += count($subquestions); $Subquestions += [$q['id'] => $subquestions]; $QuestionFor5IDs = array_merge($QuestionFor5IDs, [$q['id']]); continue; case 6: // Kéo thả $DragDropIDs = array_merge($DragDropIDs, [$q['id']]); $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor6 += [$q['id'] => $answers]; $s = ''; foreach ($answers as $a) { $s .= $a['Detail'] . ' '; } $CompleteAnswersFor6 += [$q['id'] => $s]; // $CompleteAnswersFor6 = array_merge($CompleteAnswersFor6, [$s]); $maxscore++; continue; } } $Comments = Comments::all()->toArray(); $result = array('Comments' => json_encode($Comments), 'Questions' => $questions, 'Post' => $post, 'MaxScore' => $maxscore, 'NumOfQuestions' => count($questions = Questions::where('PostID', '=', $postID)->get()->toArray()), 'Token' => $token, 'DisplayedQuestions' => $DisplayedQuestions); if (auth() && auth()->user() && User::find(auth()->user()->getAuthIdentifier())['admin'] >= ConstsAndFuncs::PERM_ADMIN) { $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->get()->toArray(); $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->get()->toArray(); $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->first()->toArray()['id']]; $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->orderBy('created_at', 'desc')->first()->toArray()['id']]; } else { $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->where('Hidden', '=', 0)->get()->toArray(); $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->where('Hidden', '=', 0)->get()->toArray(); $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->first()->toArray()['id']]; $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->orderBy('created_at', 'desc')->first()->toArray()['id']]; } $newpost = array_merge($nextPost, $previousPost); $result += ['newpost' => $newpost]; // dd($newpost); // dd($post); $ahtk = Tags::where('PostID', '=', $postID)->get()->toArray(); $Hashtag = array(); foreach ($ahtk as $k) { $ht = Hashtags::find($k['HashtagID'])['Hashtag']; if (strlen($ht) > 0) { $Hashtag = array_merge($Hashtag, [$ht]); } } return view('viewpost')->with($result)->with(compact(['result', 'newpost', 'Hashtag', 'AnswersFor1', 'TrueAnswersFor1', 'AnswersFor3', 'ArrangedIDs', 'Spaces', 'AnswersFor2', 'SetOfSpaceIDs', 'AnswersFor4', 'FillCharacterIDs', 'subquestions', 'AnswersFor5', 'Subquestions', 'QuestionFor5IDs', 'AnswersFor6', 'DragDropIDs', 'CompleteAnswersFor6'])); }
public function check_mcq($event_id) { $user = Auth::user(); $data = Input::all(); $answer = $data['ans']; // $event_id = $data['event_id']; $event = Event::where('event_name', $event_id)->first(); $score = Score::where('user_id', Auth::user()->id)->where('event_id', $event->id)->first(); //dd($score); $points = 0; foreach ($answer as $res) { $ans = Answers::where('ques_id', $res['ques_id'])->first(); //dd($ans); if ($ans->answer == $res['ans']) { $points += $ans->score; } else { $points += $ans->incorrect; } } $score->update(['score' => $points]); return Redirect::route('end_of_event'); }