示例#1
0
 public function destroy()
 {
     if (!Auth::check()) {
         return;
     }
     $data = Answers::find(Input::get("id"));
     $data->delete();
     return "OK";
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $id = $request->input('parentID');
     $questions = Answers::find($id);
     $comment = new Comment();
     $comment->body = $request->input('comment');
     $comment->user_id = Auth::id();
     $questions->comments()->save($comment);
     echo $comment;
 }
示例#3
0
 public function saveAnswer()
 {
     $input = Input::all();
     $answer = new Answers();
     $answer->exam_id = $input['exam'];
     $answer->question_id = $input['question'];
     $answer->user_id = $input['user'];
     $answer->answer = $input['answer'];
     $answer->assessment_id = $input['assessment'];
     $answer->save();
     return redirect()->intended('/assessment/exams/' . $input['examcode'] . '/' . ++$input['item']);
 }
 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();
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $uri = $request->path();
     $uriExpanded = explode('/', $uri);
     $id = $uriExpanded[3];
     $userId = Auth::user()->id;
     $answer = Answers::findBySlugOrFail($id);
     if ($userId != $answer->user_id) {
         flash('You Are Not The Owner Of the Answer')->important();
         return redirect($uriExpanded[0] . '/' . $uriExpanded[1]);
     }
     return $next($request);
 }
 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;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $uri = $request->path();
     $UriExpanded = explode('/', $uri);
     $q_id = $UriExpanded[1];
     $question = Questions::findBySlugOrFail($q_id);
     $a_id = $UriExpanded[3];
     $answer = Answers::findBySlugOrFail($a_id);
     $id = $answer->questions_id;
     if ($id != $question->id) {
         return redirect(action('QuestionsController@index'));
     }
     return $next($request);
 }
示例#8
0
 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);
 }
 public function downVote(Request $request)
 {
     $id = $request->input('id');
     $answer = Answers::findorfail($id);
     if (!$answer->disliked()) {
         $answer->dislike();
         if ($answer->liked()) {
             $answer->unlike();
         }
         echo $answer->likeCount . " | Upvoted";
     } else {
         $answer->undislike();
         echo $answer->likeCount . " | Upvote";
     }
 }
示例#10
0
 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);
 }
示例#11
0
 public function result(Request $req)
 {
     $input = $req->all();
     if (isset($input['option'])) {
         $array_of_options = $input['option'];
         foreach ($array_of_options as $key => $value) {
             //$key = question id
             //$value = user submitted answer
             $answer = Answers::select('option_id')->where('question_id', '=', $key)->get();
             if (count($answer) === 1) {
                 //Single answer
                 $answer = $answer->first();
                 if ($answer->option_id === $value) {
                     //User answer is correct
                     $correct_answer[$key] = $value;
                 } else {
                     //User answer isn't correct
                     $wrong_answer[$key] = $value;
                 }
             } else {
                 //Multiple answer
                 foreach ($answer as $ans) {
                     foreach ($value as $val) {
                         if ($ans->option_id === $val) {
                             $multiple_right_answer[] = $val;
                         }
                     }
                 }
                 if (isset($multiple_right_answer)) {
                     if (count($multiple_right_answer) === count($answer)) {
                         $correct_answer[$key] = $value;
                     } else {
                         $wrong_answer[$key] = $value;
                     }
                 } else {
                     $wrong_answer[$key] = $value;
                 }
             }
             //End of Multiple answer
             $multiple_right_answer = null;
         }
         if (isset($correct_answer)) {
             $correct_answer_count = count($correct_answer);
             //Get the skill result
             $correct_answer_array = array_keys($correct_answer);
             $chart = $this->getSkillResult($correct_answer_array);
             $this->generatePdf($chart);
         } else {
             $correct_answer_count = 0;
             $correct_answer = null;
             $chart = null;
         }
         if (isset($wrong_answer)) {
             $wrong_answer_count = count($wrong_answer);
         } else {
             $wrong_answer_count = 0;
             $wrong_answer = null;
         }
         $success_percentage = $correct_answer_count * 100 / ($correct_answer_count + $wrong_answer_count);
         $result_data = ['user_id' => \Auth::user()->id, 'quiz_id' => $req->input('quiz_id'), 'total_attempt' => $correct_answer_count + $wrong_answer_count, 'correct_answers' => $correct_answer_count, 'percentage' => $success_percentage];
         \DB::table('results')->insert($result_data);
         $user_given_inputs = $input['option'];
         //Call the pdf creation and sending email function here to include the $skill data and user result data
         return view('result')->with(['chart' => $chart, 'user_given_inputs' => $user_given_inputs, 'percentage' => $success_percentage, 'correct_answer' => $correct_answer, 'wrong_answer' => $wrong_answer]);
     } else {
         return view('result')->with(['message' => 'You did not answer any question. Try again!']);
     }
 }
 /**
  * @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;
         }
     }
 }
示例#13
0
 public function get_answers_ids_by_qid_array($q_id_array)
 {
     $answers = count(Answers::whereIn('question_id', $q_id_array)->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));
 }
示例#15
0
 /**
  *
  * 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]);
     }
 }
示例#16
0
 public function question($q_id)
 {
     $user = new User();
     if (Auth::check()) {
         $user_data = $user->get_user_profile_data();
         //id , username and user rank
     } else {
         $user_data['id'] = "";
     }
     // Get question Data
     $question = new Questions();
     $question_item = $question->get_question_by_id($q_id);
     $q_data['q_id'] = $question_item[0]['id'];
     $q_data['q_content'] = $question_item[0]['content'];
     $q_data['user_id'] = $question_item[0]['user_id'];
     // get all answer of givern question ID
     $answers = new Answers();
     $get_all_answers = $answers->get_answers_ids_by_question_id($q_data['q_id']);
     $get_all_answers_ids = array();
     $get_all_users_ids = array();
     $get_all = array();
     $answers_status = new Answers_status();
     if ($get_all_answers != NULL) {
         // make array of all answer's IDs
         foreach ($get_all_answers as $answer) {
             array_push($get_all_answers_ids, $answer['id']);
             array_push($get_all_users_ids, $answer['user_id']);
         }
     }
     // get all usernames from user ids in array
     //        $users_data = $user->get_user_names_by_ids($get_all_users_ids);
     //        $username_array = array();
     // get all statuses of all answers
     $gat_status_in_array = $answers_status->gat_status_in_array($get_all_answers_ids);
     $status_array = array();
     if ($gat_status_in_array != null) {
         foreach ($gat_status_in_array as $key => $item) {
             $status_array[$item['answer_id']][$key] = $item;
         }
         ksort($status_array, SORT_NUMERIC);
     }
     if ($get_all_answers != NULL) {
         foreach ($get_all_answers as $answer) {
             $like_count = 0;
             $dislike_count = 0;
             $spam_count = 0;
             if ($status_array != null) {
                 foreach ($gat_status_in_array as $status) {
                     if ($answer['id'] == $status['answer_id']) {
                         if ($status['status'] == 1) {
                             $like_count++;
                         } elseif ($status['status'] == 0) {
                             $dislike_count++;
                         } elseif ($status['status'] == 2) {
                             $spam_count++;
                         }
                     }
                 }
             }
             // get user name
             $username = $user->get_user_name_by_id($answer['user_id']);
             $all_array = array('answer_data' => $answer->toArray(), 'likes' => $like_count, 'dislikes' => $dislike_count, 'spam' => $spam_count, 'user_name' => $username);
             array_push($get_all, $all_array);
         }
     }
     return view('user/question_data')->withQuestionId($q_data['q_id'])->withQuestionUserId($q_data['user_id'])->withQuestionContent($q_data['q_content'])->withUserId($user_data['id'])->withAnswersArray($get_all);
 }
示例#17
0
 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);
     }
 }
 /**
  * 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));
 }
 /**
  * @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.');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(QuestionAnswerRequest $request, $qid, $aid)
 {
     $answer = Answers::findBySlugOrFail($aid);
     $answer->update($request->all());
     flash('Your Answer Has been Edited');
     return redirect(action('QuestionsAnswersController@show', [$qid, $answer->slug]));
 }
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) !!}
示例#22
0
 /**
  * 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);
 }
示例#23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $answer = Answers::find($id);
     $answer->delete();
 }
示例#24
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     // return redirect('/');
     $answer = Answers::find($id);
     if (count($answer) < 1) {
         return redirect('/');
     }
     @unlink(public_path('images/imageAnswer/' . $answer['Photo']));
     $answer->delete();
 }
示例#25
0
 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();
 }
示例#26
0
 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']));
 }
示例#27
0
 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');
 }