Beispiel #1
0
 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
 }
 /**
  * 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 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 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));
 }
 /**
  * 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]);
 }
 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));
 }
Beispiel #8
0
 public function getQuestion($id)
 {
     $question = Questions::find($id);
     return $question->question_name;
 }
Beispiel #9
0
 /**
  * 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]);
 }
Beispiel #10
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]);
     }
 }