public function update() { //implement new state answered $data = Questions::find(Input::get("id")); if (!$data || !Auth::check()) { return "not found"; } $validator = Validator::make(['title' => Input::get("title")], ['title' => 'max:255']); if ($validator->fails()) { return "i wanna more"; } if (Input::get("title") != "") { $data->title = Input::get("title"); } if (Input::get("question") != "") { $data->question = Input::get("question"); } if (Input::get("status") != "") { $data->status = Input::get("status"); } if (Input::get("state") != "") { $state = Classif::where('name', 'PARAGRAPH_STATE')->where('code', Input::get("state"))->first(); if ($state->id) { $data->cid = $state->id; } $data->save(); return $state; } $data->save(); //return redirect("/question/$data->title/$data->id"); //maybe dynamic insert without refresh }
public function get_child_categories_and_questions() { // $user_info = Auth::user()->toArray(); // if ($user_info['user_type'] == 2) { $parent_id = Input::get('main_category'); $category = new Category(); $categories = $category->get_categories_by_parent_id($parent_id); $child_ids_array = array(); if (!empty($categories)) { foreach ($categories as $single_categoty) { array_push($child_ids_array, $single_categoty['id']); } } else { $categories = array(); } array_push($child_ids_array, $parent_id); $question = new Questions(); $all_questions = $question->gat_category_questions_in_array($child_ids_array); $return_data = array('0' => $categories, '1' => $all_questions); return $return_data; // } // $message = "you are not admin. you can't use this method"; // return view('welcome') // ->withMessage($message); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $id = $request->input('parentID'); $questions = Questions::find($id); $comment = new Comment(); $comment->body = $request->input('comment'); $comment->user_id = Auth::id(); $questions->comments()->save($comment); echo $comment; }
public function contact(Request $request) { $this->validate($request, ['question' => 'required', 'email' => 'email']); if (!isset($request->confirmed)) { return View('contact.confirm', compact('request')); } else { if (isset($request->art_id)) { $art_id = $request->art_id; } else { $art_id = 0; } $input = new Questions(); $input->art_id = $art_id; $input->question = $request->question; $input->question = $request->email; $input->user_id = Auth::user()->id; $input->save(); return View('contact.contact')->withSuccess(trans('succes.asked')); } }
public function get_all_questions_where_in($ids_array) { $question = Questions::whereIn('questions.id', $ids_array)->leftJoin('answers', 'questions.id', '=', 'answers.question_id')->selectRaw('questions.*, count(answers.id) as total_answers')->groupBy('questions.id')->get(); // ->toSql(); // print_r($question); // die; if (count($question) > 0) { return $question; } else { return ""; } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $user_id = Auth::user()->id; $uri = $request->path(); $UriExpanded = explode('/', $uri); $q_id = $UriExpanded[1]; $question = Questions::findBySlugOrFail($q_id); $id = DB::table('answers')->where('questions_id', '=', $question->id)->where('user_id', '=', $user_id)->count(); if ($id >= 1) { return redirect(action('QuestionsController@index')); } return $next($request); }
/** * 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[1]; $userId = Auth::user()->id; $question = Questions::findBySlugOrFail($id); if ($userId != $question->user_id) { flash('You Are Not The Owner Of the Question')->important(); return redirect($uriExpanded[0] . '/' . $uriExpanded[1]); } return $next($request); }
/** * 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); }
public function update($QuestionID) { $question = Questions::find($QuestionID); $old_subquestions = Subquestions::where('QuestionID', '=', $QuestionID)->get()->toArray(); foreach ($old_subquestions as $value) { SubquestionsController::destroy($value['id']); } $data = Request::capture()->all(); $count = $data['numAnswer']; for ($i = 0; $i < $count; $i++) { $subQ = $data['answer' . ($i + 1)]; $SubQuestionID = DB::table('subquestions')->insertGetId(['QuestionID' => $QuestionID, 'Question' => $subQ, 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()]); $answer = new Answers(); $answer->SubQuestionID = $SubQuestionID; $answer->Detail = $data['ta_answer' . ($i + 1)]; $answer->Logical = 1; $answer->save(); } return redirect(route('user.viewquestion', $QuestionID)); }
public function adminViewCourse($courseid) { $course = Courses::find($courseid); if (count($course) < 1) { return view('errors.404'); } // $result = array('Title' => $course['Title']); $course = $course->toArray(); $posts = Posts::where('CourseID', '=', $courseid)->get()->toArray(); $numQuestions = []; foreach ($posts as $p) { $numQuestions += [$p['id'] => count(Questions::where('PostID', '=', $p['id'])->get()->toArray())]; } $r = array('posts' => $posts); $r += array('Title' => $course['Title']); $r += array('NumQuestions' => $numQuestions); $r += array('CourseID' => $courseid); // return var_dump($r); // dd($r); return view('viewcourse', $r); }
public function update($QuestionID) { $question = Questions::find($QuestionID); $old_subquestions = Subquestions::where('QuestionID', '=', $QuestionID)->get()->toArray(); foreach ($old_subquestions as $value) { SubquestionsController::destroy($value['id']); } $request = Request::capture(); $data = $request->all(); $count = $data['numAnswer']; for ($i = 1; $i <= $count; $i++) { $subQ = $data['answer' . $i]; $SubQuestionID = DB::table('subquestions')->insertGetId(['QuestionID' => $QuestionID, 'Question' => $subQ, 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()]); $file = $request->file('subquestion_photo_' . $i); if ($file != null) { $sq = Subquestions::orderBy('id', 'desc')->first(); $sq->Photo = 'Subquestion_' . $QuestionID . '_' . $SubQuestionID . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/images/imageSubquestion/', $sq->Photo); $sq->update(); } $answer = new Answers(); $answer->SubQuestionID = $SubQuestionID; $answer->Detail = $data['ta_answer' . $i]; $answer->Logical = 1; $answer->save(); if ($request->hasFile('answer_photo_' . $i) && $request->file('answer_photo_' . $i)->isValid()) { $a = Answers::orderBy('id', 'desc')->first(); $file = $request->file('answer_photo_' . $i); if ($file != null) { $a->Photo = 'Answer_SQ_' . $SubQuestionID . '_' . $a->id . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/images/imageAnswer/', $a->Photo); $a->update(); } } } return redirect(route('user.viewquestion', $QuestionID)); }
private function syncTags(Questions $questions, array $tags, $courses_id) { //dd($questions); $questions->tags()->detach(); foreach ($tags as $tag) { $newTags = Tags::firstOrCreate(['name' => $tag, 'courses_id' => $courses_id, 'user_id' => Auth::user()->id]); $questions->tags()->attach($newTags); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($QuestionID) { if (!AuthController::checkPermission()) { return redirect('/'); } $Answers = Answers::where('QuestionID', '=', $QuestionID)->get(); foreach ($Answers as $answer) { $answer['Detail'] = $this->s2c_convert($answer['Detail']); } $question = Questions::find($QuestionID)->toArray(); switch ($question['FormatID']) { case 1: $view = 'admin.editanswer'; break; case 6: $view = 'admin.editdragdropanswer'; break; default: $view = 'admin.editanswer'; break; } $photo = $question['Photo']; return view($view)->with(['PostID' => $question['PostID'], "QuestionID" => $QuestionID, 'Answers' => $Answers, 'Photo' => $photo]); }
/** * * 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]); } }
/** * 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); }
/** * @param $id * @return \Illuminate\View\View */ public function write($id) { $question = Questions::findBySlugOrFail($id); return view('Answer.write', compact('question')); }
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); }
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)); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($QuestionID) { if (!AuthController::checkPermission()) { return redirect('/'); } $Answers = Answers::where('QuestionID', '=', $QuestionID)->get(); foreach ($Answers as $answer) { $answer['Detail'] = $this->s2c_convert($answer['Detail']); } $question = Questions::find($QuestionID)->toArray(); $photo = $question['Photo']; return view('admin.editanswer')->with(['PostID' => $question['PostID'], "QuestionID" => $QuestionID, 'Answers' => $Answers, 'Photo' => $photo]); }
@if ((auth()->user()) && (auth()->user()->admin == 1)) <a style="text-decoration: none;" href="{{route('user.viewquestion', $q['id'])}}"><img class="img-responsive" alt="{{$q['Question'] . ' - Evangels English - '}}{{$_SERVER['HTTP_HOST']}}" src="/images/imageQuestion/{{$q['Photo']}}" /></a> @else <img class="img-responsive" alt="{{$q['Question'] . ' - Evangels English - '}}{{$_SERVER['HTTP_HOST']}}" src="/images/imageQuestion/{{$q['Photo']}}" /> @endif </li> @endif @elseif ($q['ThumbnailID'] == 2) @if ($q['Video'] != null) <div class="embed-responsive embed-responsive-4by3"> <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/{{$q['Video']}}" frameborder="0" allowfullscreen></iframe> </div> @endif @endif <?php $subP = \App\Questions::getFilledQuestion($q['Question']); 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) !!} @if (count($Spaces[$q['id']]) > 0) <select style="color:#cc0066" id="select_space_{{current($Spaces[$q['id']])['id']}}" data-show-icon="true"> <?php $this_answers = $AnswersFor2[current($Spaces[$q['id']])['id']];
public function getQuestion($id) { $question = Questions::find($id); return $question->question_name; }
public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $post = Posts::find($id); @unlink(public_path('images/imagePost/' . $post['Photo'])); $questions = Questions::where('PostID', '=', $id)->get()->toArray(); foreach ($questions as $question) { QuestionsController::destroy($question['id']); } $courseid = $post['CourseID']; $post->delete(); $course = Courses::find($post->CourseID); $course->NoOfPosts--; $course->update(); return redirect(route('admin.viewcourse', $courseid)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Questions::destroy($id); return redirect('questions'); }