Esempio n. 1
0
 public function store()
 {
     if (!Auth::check()) {
         return;
     }
     $validator = Validator::make(['name' => Input::get("name"), 'surname' => Input::get("surname"), 'answer' => Input::get("answer")], ['name' => 'max:255', 'surnmae' => 'max:255', 'answer' => 'required']);
     if ($validator->fails()) {
         return "Answer is mandatory";
     }
     if (Input::get("id") != "") {
         $data = Answers::find(Input::get("id"));
     } else {
         $data = new Answers();
     }
     $data->name = Input::get("name");
     $data->surname = Input::get("surname");
     $data->answer = Input::get("answer");
     $satus = Classif::where('name', 'ANSWER_STATUS')->where('code', '0002')->first();
     $data->cid = $satus->id;
     $data->qid = Input::get("question_id");
     $data->save();
     if (Input::get("question_id") != "") {
         return redirect("/question/" . Input::get("question_id") . "/" . Input::get("question_id"));
     } else {
         return redirect('/question');
         //maybe dynamic insert without refresh
     }
 }
 public function update($QuestionID)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = Request::capture();
     $count = $data['numAnswer'];
     // delete all old spaces with corresponding answers
     $oldSpaces = Spaces::where('QuestionID', '=', $QuestionID)->get()->toArray();
     foreach ($oldSpaces as $value) {
         SpacesController::destroy($value['id']);
     }
     for ($i = 0; $i < $count; $i++) {
         $rawAnswer = trim(AnswersController::c2s_convert($data['answer' . ($i + 1)]));
         preg_match_all('/([^;]+);/', $rawAnswer, $matches, PREG_PATTERN_ORDER);
         $arrayOfAnswer = $matches[1];
         $SpaceID = DB::table('spaces')->insertGetId(['QuestionID' => $QuestionID, 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()]);
         $true = true;
         foreach ($arrayOfAnswer as $value) {
             $a = new Answers();
             $a->Logical = $true;
             $a->SpaceID = $SpaceID;
             $a->Detail = trim($value);
             $a->save();
             $true = false;
         }
     }
     return redirect(route('user.viewquestion', $QuestionID));
 }
Esempio n. 3
0
 public function post_answer($user_id, $question_id, $answer_content)
 {
     $answer = new Answers();
     $answer->user_id = $user_id;
     $answer->question_id = $question_id;
     $answer->content = $answer_content;
     if ($answer->save()) {
         return TRUE;
     }
     return FALSE;
 }
Esempio n. 4
0
 public function newAnswer(Request $request)
 {
     if (Auth::guest()) {
         return Redirect::to('/auth/login');
     } else {
         $answer = new Answers();
         $answer->user_id = Auth::user()->id;
         $answer->question_id = $request->q_id;
         $answer->answer = $request->message;
         $answer->rate = 0;
         $answer->date = date("Y-m-d H:i:s");
         $answer->save();
         return back();
     }
 }
Esempio n. 5
0
 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));
 }
Esempio n. 7
0
 public function add_answer($QuestionID, $Logical, $Detail)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $answer = new Answers();
     $answer->QuestionID = $QuestionID;
     $answer->Logical = $Logical;
     $answer->Detail = $Detail;
     $answer->save();
 }
 public function saveQuestion($PostID)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = Request::capture();
     $question = new Questions();
     $question->PostID = $PostID;
     $question->ThumbnailID = $data['ThumbnailID'];
     $question->Question = $data['Question'];
     $question->Description = $data['Description'];
     $question->FormatID = $data['FormatID'];
     $a = $data['Answer'];
     switch ($data['ThumbnailID']) {
         case '1':
             // Photo
             $question->save();
             $question = Questions::orderBy('id', 'desc')->first();
             //Photo
             $file = Request::capture()->file('Photo');
             if ($file != null) {
                 $question->Photo = 'Question_' . $PostID . '_' . $question->id . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension();
                 $file->move(base_path() . '/public/images/imageQuestion/', $question->Photo);
             }
             $question->update();
             break;
         case '2':
             // Video
             $linkVideo = $data['Video'];
             $question->Video = PostsController::getYoutubeVideoID($linkVideo);
             $question->save();
             break;
     }
     // var_dump($data);
     if ($question->FormatID == '3' || $question->FormatID == '4') {
         $answer = new Answers();
         $answer->Detail = $a;
         $answer->QuestionID = $question->id;
         $answer->Logical = 1;
         $answer->save();
     }
     echo $question->id;
     return;
 }
Esempio n. 9
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']);
 }