/** * * @param Question $question * @return int id of the Question inserted in base. False if it didn't work. */ public static function flush($question) { $questionId = $question->getId(); $questionVar = $question->getQuestion(); $theme = $question->getTheme()->getIdTheme(); if ($questionId > 0) { $sql = 'UPDATE question SET ' . 'question = ?, ' . 'THEME_id_theme = ? ' . 'WHERE id_question = ?'; $params = array('sii', &$questionVar, &$theme, &$questionId); } else { $sql = 'INSERT INTO question (question, THEME_id_theme) VALUES (?, ?)'; $params = array('si', &$questionVar, &$theme); } $idInsert = BaseSingleton::insertOrEdit($sql, $params); if ($idInsert !== false && $questionId > 0) { $idInsert = $questionId; } return $idInsert; }
/** * @return int * @param Question $q */ public static function updateQuestion($q) { $db = DB::getConn(); $stm = $db->prepare('update Question set title=:title, category=:cate, point=:point, explain=:explain where id=:id'); $stm->bindParam(':title', $q->getTitle()); $stm->bindParam(':cate', $q->getCategory()); $stm->bindParam(':point', $q->getPoint()); $stm->bindParam(':explain', $q->getExplain()); $stm->bindParam(':id', $q->getId()); $stm->execute(); return QuestionCtrl::getLastID(); }
$newQuestions = array(); $found = false; // open questions file $fileName = "questions.json"; $dataFile = fopen($fileName, "r+"); // if file existed before if (filesize($fileName) > 0) { // read all file contents $fileContents = fread($dataFile, filesize($fileName)); // create array of stdClass objects from contents $stdQuestions = json_decode($fileContents); // convert array elements into Question objects // also insert/overwrite with the submitted question foreach ($stdQuestions as $stdQuestion) { $question = Question::fromStdObj($stdQuestion); if ($question->getId() == $submittedQuestion->getId()) { array_push($newQuestions, $submittedQuestion); $found = true; } else { array_push($newQuestions, $question); } } } // insert submitted question if it has not been used to replace a previous question if (!$found) { array_push($newQuestions, $submittedQuestion); } // close read-access file fclose($dataFile); // overwrite file with write access // (ftruncate to clear the existing file lead to errors :-/)
?> <div class="accordion"> <?php foreach ($survey_questions as $question_id) { $question = new Question(); $question->get_from_db($question_id); if ($question->getType() == 1) { ?> </div> <h3 class="no-float ac"><?php print_r($question->getTitle()); ?> </h3> <div class="al"> <?php $answers = get_survey_answers($question->getId()); foreach ($answers as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); ?> <p>   <?php print_r($answer->getValue()); ?> </p> <?php } ?> </div> <div class="accordion"> <?php } elseif ($question->getType() == 0) {
function test_getAnswers() { //Arrange $test_field = "What is their name?"; $test_description = "What you want to call your character."; $test_question = new Question($test_field, $test_description); $test_question->save(); $test_field = "Joe GetAll"; $test_quest_id = $test_question->getId(); $test_answer = new Answer($test_field, $test_quest_id); $test_answer->save(); //Act $test_question->addAnswer($test_answer->getId()); //Assert $result = $test_question->getAnswers($test_answer->getId()); $this->assertEquals($test_answer, $result[0]); }
/** * Function to handle the "/questions" REST-POST call. * * It stores the transmitted question on the file system * and redirects to the previous page. */ function save_question() { // create question from POST data $submittedQuestion = new Question($_POST["questionId"], $_POST["question"], array($_POST["answer1"], $_POST["answer2"], $_POST["answer3"], $_POST["answer4"]), $_POST["correct-answer"] - 1); $submittedQuestion->saveToFile(); // create coin only after question has been saved to ensure the id has been initialized $coin = new Coin($submittedQuestion->getId()); $coin->saveToFile(); // redirect back to previous page header('Location: ' . $_SERVER['HTTP_REFERER']); }
<div class="accordion"> <?php foreach ($survey_questions as $question_id) { $question = new Question(); $question->get_from_db($question_id); if ($question->getType() == 1) { ?> </div> <div class="clearfix"> <h3 class="no-float ac"><?php print_r($question->getTitle()); ?> </h3> <?php $answers = get_survey_answers($question->getId()); foreach ($answers as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); if ($answer->getType() == "textbox") { ?> <div class="al">    <?php print_r($answer->getValue()); ?> </div> <?php } } ?> <div class="al">
require_once './lib/question.class.php'; $exercise = new Exercise(); $exercise->load($exId); if ($exercise->getShuffle() && isset($_REQUEST['shuffle']) && $_REQUEST['shuffle'] == 1) { $questionList = $exercise->getRandomQuestionList(); } else { $questionList = $exercise->getQuestionList(); } foreach ($questionList as $_id => $question) { $questionObj = new Question(); $questionObj->setExerciseId($exId); if ($questionObj->load($question['id'])) { $questionList[$_id]['description'] = $questionObj->getDescription(); $questionList[$_id]['attachment'] = $questionObj->getAttachment(); if (!empty($questionList[$_id]['attachment'])) { $questionList[$_id]['attachmentURL'] = get_conf('rootWeb') . 'courses/' . claro_get_current_course_id() . '/exercise/question_' . $questionObj->getId() . '/' . $questionObj->getAttachment(); } switch ($questionObj->getType()) { case 'MCUA': case 'MCMA': $questionList[$_id]['answers'] = $questionObj->answer->answerList; break; case 'TF': $questionList[$_id]['answers'][0]['answer'] = get_lang('True'); $questionList[$_id]['answers'][0]['feedback'] = $questionObj->answer->trueFeedback; $questionList[$_id]['answers'][1]['answer'] = get_lang('False'); $questionList[$_id]['answers'][1]['feedback'] = $questionObj->answer->falseFeedback; break; case 'FIB': $questionList[$_id]['answerText'] = $questionObj->answer->answerDecode($questionObj->answer->answerText); $questionList[$_id]['answerList'] = $questionObj->answer->answerList;