From: thepurpleblob Date: Fri, 19 Jan 2007 14:38:18 +0000 (+0000) Subject: MDL-8226 Move aon import format from head into contrib. No longer maintained. Use... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=296fe50abbae61306180d031c7528c574254e6bb;p=moodle.git MDL-8226 Move aon import format from head into contrib. No longer maintained. Use GIFT instead. --- diff --git a/question/format/aon/format.php b/question/format/aon/format.php deleted file mode 100644 index 5c974a09ae..0000000000 --- a/question/format/aon/format.php +++ /dev/null @@ -1,227 +0,0 @@ -defaultquestion(); - - $text = implode($lines, " "); - - /// Find answer section - - $answerstart = strpos($text, "{"); - if ($answerstart === false) { - if ($this->displayerrors) { - echo "

$text

Could not find a {"; - } - return false; - } - - $answerfinish = strpos($text, "}"); - if ($answerfinish === false) { - if ($this->displayerrors) { - echo "

$text

Could not find a }"; - } - return false; - } - - $answerlength = $answerfinish - $answerstart; - $answertext = substr($text, $answerstart + 1, $answerlength - 1); - - /// Save the new question text - $question->questiontext = addslashes(substr_replace($text, "_____", $answerstart, $answerlength+1)); - $question->name = substr($question->questiontext, 0, 60)." ..."; - - - /// Parse the answers - $answers = explode("~", $answertext); - - $countanswers = count($answers); - - switch ($countanswers) { - case 0: // invalid question - if ($this->displayerrors) { - echo "

No answers found in $answertext"; - } - return false; - - case 1: - $question->qtype = SHORTANSWER; - - $answer = trim($answers[0]); - if ($answer[0] == "=") { - $answer = substr($answer, 1); - } - $question->answer[] = addslashes($answer); - $question->fraction[] = 1; - $question->feedback[] = ""; - - return $question; - - default: - $question->qtype = MULTICHOICE; - - $answers = swapshuffle($answers); - foreach ($answers as $key => $answer) { - $answer = trim($answer); - if ($answer[0] == "=") { - $question->fraction[$key] = 1; - $answer = substr($answer, 1); - } else { - $question->fraction[$key] = 0; - } - $question->answer[$key] = addslashes($answer); - $question->feedback[$key] = ""; - } - - $question->single = 1; // Only one answer is allowed - return $question; - } - } - - function importpostprocess() { - /// Goes through the questionids, looking for shortanswer questions - /// and converting random groups of 4 into matching questions. - - /// Doesn't handle shortanswer questions with more than one answer - - global $CFG; - - print_heading(count($this->questionids)." ".get_string("questions", "quiz")); - - $questionids = implode(',', $this->questionids); - - if (!$shortanswers = get_records_select("question", - "id IN ($questionids) AND qtype = ".SHORTANSWER, - "", "id,qtype")) { - return true; - } - - - $shortanswerids = array(); - foreach ($shortanswers as $key => $shortanswer) { - $shortanswerids[] = $key; - } - - $strmatch = get_string("match", "quiz")." (".$this->category->name.")"; - - $shortanswerids = swapshuffle($shortanswerids); - $count = $shortanswercount = count($shortanswerids); - $i = 1; - $matchcount = 0; - - $question->category = $this->category->id; - $question->qtype = MATCH; - $question->questiontext = get_string("randomsamatchintro", "quiz"); - $question->image = ""; - - while ($count > 4) { - $matchcount++; - $question->name = "$strmatch $i"; - $question->subquestions = array(); - $question->subanswers = array(); - - $extractids = implode(',', array_splice($shortanswerids, -4)); - $count = count($shortanswerids); - - $extracts = get_records_sql("SELECT q.questiontext, a.answer - FROM {$CFG->prefix}question q, - {$CFG->prefix}question_shortanswer sa, - {$CFG->prefix}question_answers a - WHERE q.id in ($extractids) - AND sa.question = q.id - AND a.id = sa.answers"); - - if (count($extracts) != 4) { - print_object($extracts); - notify("Could not find exactly four shortanswer questions with ids: $extractids"); - continue; - } - - $question->stamp = make_unique_id_code(); // Set the unique code (not to be changed) - $question->version = 1; // Original version of this question - $question->parent = 0; - - if (!$question->id = insert_record("question", $question)) { - error("Could not insert new question!"); - } - - foreach ($extracts as $shortanswer) { - $question->subquestions[] = addslashes($shortanswer->questiontext); - $question->subanswers[] = addslashes($shortanswer->answer); - } - - $result = save_question_options($question); - - if (!empty($result->error)) { - notify("Error: $result->error"); - } - - if (!empty($result->notice)) { - notify($result->notice); - } - - // Give the question a unique version stamp determined by question_hash() - set_field('question', 'version', question_hash($question), 'id', $question->id); - - /// Delete the old short-answer questions - - execute_sql("DELETE FROM {$CFG->prefix}question WHERE id IN ($extractids)", false); - execute_sql("DELETE FROM {$CFG->prefix}question_shortanswer WHERE question IN ($extractids)", false); - execute_sql("DELETE FROM {$CFG->prefix}question_answers WHERE question IN ($extractids)", false); - - } - - if ($count) { /// Delete the remaining ones - foreach ($shortanswerids as $shortanswerid) { - delete_records("question", "id", $shortanswerid); - delete_records("question_shortanswer", "question", $shortanswerid); - delete_records("question_answers", "question", $shortanswerid); - } - } - $info = "$shortanswercount ".get_string("shortanswer", "quiz"). - " => $matchcount ".get_string("match", "quiz"); - - print_heading($info); - - $options['category'] = $this->category->id; - echo '

'; - print_single_button("multiple.php", $options, get_string("randomcreate", "quiz")); - echo "
"; - - return true; - } - -} - -?>