/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($id, $question, Answer_validate $request) { $request->all(); $id1 = Auth::id(); $answer = new answer(array('Content' => $request->get('content'))); $answer->id = $id1; $answer->qid = $id; $answer->save(); return redirect('/Userhome'); }
/** * abstract function which creates the form to create / edit the answers of the question * @param FormValidator $form */ function processAnswersCreation($form) { if (!self::isAnswered()) { $table = Database::get_course_table(TABLE_QUIZ_ANSWER); Database::delete($table, array('c_id = ? AND question_id = ?' => array($this->course['real_id'], $this->id))); $answer = $form->getSubmitValue('answer'); $formula = $form->getSubmitValue('formula'); $lowestValues = $form->getSubmitValue('lowestValue'); $highestValues = $form->getSubmitValue('highestValue'); $answerVariations = $form->getSubmitValue('answerVariations'); $this->weighting = $form->getSubmitValue('weighting'); // Create as many answers as $answerVariations for ($j = 0; $j < $answerVariations; $j++) { $auxAnswer = $answer; $auxFormula = $formula; $nb = preg_match_all('/\\[[^\\]]*\\]/', $auxAnswer, $blanks); if ($nb > 0) { for ($i = 0; $i < $nb; ++$i) { $blankItem = $blanks[0][$i]; $replace = array("[", "]"); $newBlankItem = str_replace($replace, "", $blankItem); $newBlankItem = "[" . trim($newBlankItem) . "]"; // take random float values when one or both edge values have a decimal point $randomValue = strpos($lowestValues[$i], '.') !== false || strpos($highestValues[$i], '.') !== false ? mt_rand($lowestValues[$i] * 100, $highestValues[$i] * 100) / 100 : mt_rand($lowestValues[$i], $highestValues[$i]); $auxAnswer = str_replace($blankItem, $randomValue, $auxAnswer); $auxFormula = str_replace($blankItem, $randomValue, $auxFormula); } require_once api_get_path(LIBRARY_PATH) . 'evalmath.class.php'; $math = new EvalMath(); $result = $math->evaluate($auxFormula); $result = number_format($result, 2, ".", ""); // Remove decimal trailing zeros $result = rtrim($result, "0"); // If it is an integer (ends in .00) remove the decimal point if (mb_substr($result, -1) === ".") { $result = str_replace(".", "", $result); } // Attach formula $auxAnswer .= " [" . $result . "]@@" . $formula; } $this->save(); $objAnswer = new answer($this->id); $objAnswer->createAnswer($auxAnswer, 1, '', $this->weighting, null); $objAnswer->position = array(); $objAnswer->save(); } } }
/** * abstract function which creates the form to create / edit the answers of the question * @param FormValidator $form */ function processAnswersCreation($form) { global $charset; $answer = $form->getSubmitValue('answer'); //remove the :: eventually written by the user $answer = str_replace('::', '', $answer); // get the blanks weightings $nb = preg_match_all('/\\[[^\\]]*\\]/', $answer, $blanks); if (isset($_GET['editQuestion'])) { $this->weighting = 0; } if ($nb > 0) { $answer .= '::'; for ($i = 0; $i < $nb; ++$i) { $blankItem = $blanks[0][$i]; $replace = array("[", "]"); $newBlankItem = str_replace($replace, "", $blankItem); $newBlankItem = "[" . trim($newBlankItem) . "]"; $answer = str_replace($blankItem, $newBlankItem, $answer); $answer .= $form->getSubmitValue('weighting[' . $i . ']') . ','; $this->weighting += $form->getSubmitValue('weighting[' . $i . ']'); } $answer = api_substr($answer, 0, -1); } $is_multiple = $form->getSubmitValue('multiple_answer'); $answer .= '@' . $is_multiple; $this->save(); $objAnswer = new answer($this->id); $objAnswer->createAnswer($answer, 0, '', 0, '1'); $objAnswer->save(); }
/** * abstract function which creates the form to create / edit the answers of the question * @param the formvalidator instance */ function processAnswersCreation($form) { global $charset; $answer = $form->getSubmitValue('answer'); //Due the fckeditor transform the elements to their HTML value $answer = api_html_entity_decode($answer, ENT_QUOTES, $charset); //remove the :: eventually written by the user $answer = str_replace('::', '', $answer); // get the blanks weightings $nb = preg_match_all('/\\[[^\\]]*\\]/', $answer, $blanks); if (isset($_GET['editQuestion'])) { $this->weighting = 0; } if ($nb > 0) { $answer .= '::'; for ($i = 0; $i < $nb; ++$i) { $answer .= $form->getSubmitValue('weighting[' . $i . ']') . ','; $this->weighting += $form->getSubmitValue('weighting[' . $i . ']'); } $answer = api_substr($answer, 0, -1); } $is_multiple = $form->getSubmitValue('multiple_answer'); $answer .= '@' . $is_multiple; $this->save(); $objAnswer = new answer($this->id); $objAnswer->createAnswer($answer, 0, '', 0, ''); $objAnswer->save(); }
/** * Update the specified post in storage. * * @param int $id * @return Response */ public function update($id) { $validate = Validator::make(Input::all(), Answer::$rules); if ($validate->passes()) { $audio = Input::file('audio'); $name = time() . "-" . $audio->getClientOriginalName(); $avatar = $audio->move("./answers/", $name); $answer = new answer(); $answer->title = Input::get('title'); $answer->info = Input::get('info'); $answer->audio = $name; if (Auth::check()) { $answer->user_id = Auth::id(); } else { $answer->user_id = 0; } $answer->question_id = $id; $answer->save(); return Redirect::action('AnswerController@index'); $response = array('status' => 'success', 'msg' => 'Setting created successfully'); return Response::json($response); } return Redirect::back()->withErrors($validate)->withInput(); }