Permalink
Browse files

removed weighting from questiontext in JCloze import

  • Loading branch information...
1 parent 95f4edc commit aa35bd09910e512d1ae34b575279031012788c38 gbateson committed Dec 31, 2005
Showing with 61 additions and 66 deletions.
  1. +61 −66 mod/quiz/format/hotpot/format.php
View
127 mod/quiz/format/hotpot/format.php
@@ -65,19 +65,16 @@ function readquestions ($lines) {
function process_jcloze(&$xml, &$questions) {
- static $moodle_14;
-
- if (!isset($moodle_14)) {
- global $CFG, $db;
- $moodle_14 = false;
- if ($columns = $db->MetaColumns("{$CFG->prefix}quiz_multianswers")) {
- foreach ($columns as $column) {
- if ($column->name=='answers' || $column->name=='positionkey' || $column->name=='answertype' || $column->name=='norm') {
- $moodle_14 = true;
- }
- }
- }
- }
+ // sniff early Moodles
+ global $CFG, $db;
+ $moodle_14 = false;
+ if ($columns = $db->MetaColumns("{$CFG->prefix}quiz_multianswers")) {
+ foreach ($columns as $column) {
+ if ($column->name=='answers' || $column->name=='positionkey' || $column->name=='answertype' || $column->name=='norm') {
+ $moodle_14 = true;
+ }
+ }
+ }
$x = 0;
while ($exercise = &$xml['#']['data'][0]['#']['gap-fill'][$x]['#']) {
@@ -93,71 +90,69 @@ function process_jcloze(&$xml, &$questions) {
$question->name = get_hotpotatoes_title($xml, $x);
$question->questiontext = get_hotpotatoes_reading($xml);
- if ($moodle_14) {
- // Moodle 1.4 (or earlier)
- $question->answers = array();
- } else {
- // Moodle 1.5 (or greater)
- global $course; // set in mod/quiz/import.php
- $question->course = $course->id;
- $question->options = new stdClass();
- $question->options->questions = array(); // one for each gap
- }
+ // setup answer arrays
+ if ($moodle_14) {
+ $question->answers = array();
+ } else {
+ global $course; // set in mod/quiz/import.php
+ $question->course = $course->id;
+ $question->options = new stdClass();
+ $question->options->questions = array(); // one for each gap
+ }
$q = 0;
while ($question_record = &$exercise['question-record'][$q]['#']) {
- $positionkey = $q+1;
+ $positionkey = $q+1;
if (isset($exercise[$q])) {
$question->questiontext .= addslashes($exercise[$q]);
}
$question->questiontext .= '{#'.$positionkey.'}';
-
- if ($moodle_14) {
- // Moodle 1.4 (or earlier)
- $question->answers[$q]->positionkey = $positionkey;
- $question->answers[$q]->answertype = SHORTANSWER;
- $question->answers[$q]->norm = 1;
- $question->answers[$q]->alternatives = array();
- } else {
- // Moodle 1.5 (or greater)
- $wrapped = new stdClass();
- $wrapped->qtype = SHORTANSWER;
- $wrapped->usecase = 0;
- $wrapped->defaultgrade = 1;
- $wrapped->questiontextformat = 0;
- $wrapped->answer = array();
- $wrapped->fraction = array();
- $wrapped->feedback = array();
- $answers = array();
- }
+
+ // initialize answer settings
+ if ($moodle_14) {
+ $question->answers[$q]->positionkey = $positionkey;
+ $question->answers[$q]->answertype = SHORTANSWER;
+ $question->answers[$q]->norm = 1;
+ $question->answers[$q]->alternatives = array();
+ } else {
+ $wrapped = new stdClass();
+ $wrapped->qtype = SHORTANSWER;
+ $wrapped->usecase = 0;
+ $wrapped->defaultgrade = 1;
+ $wrapped->questiontextformat = 0;
+ $wrapped->answer = array();
+ $wrapped->fraction = array();
+ $wrapped->feedback = array();
+ $answers = array();
+ }
$a = 0;
while ($answer = &$question_record['answer'][$a]['#']) {
- $text = addslashes($answer['text'][0]['#']);
- $fraction = empty($answer['correct'][0]['#']) ? 0 : 1;
- $feedback = addslashes($answer['feedback'][0]['#']);
- if ($moodle_14) {
- // Moodle 1.4 (or earlier)
- $question->answers[$q]->alternatives[$a] = new stdClass();
- $question->answers[$q]->alternatives[$a]->answer = $text;
- $question->answers[$q]->alternatives[$a]->fraction = $fraction;
- $question->answers[$q]->alternatives[$a]->feedback = $feedback;
- } else {
- // Moodle 1.5 (or greater)
- $wrapped->answer[] = $text;
- $wrapped->fraction[] = $fraction;
- $wrapped->feedback[] = $feedback;
- $answers[] = (empty($fraction) ? '' : '=').$text.(empty($feedback) ? '' : ('#'.$feedback));
- }
+ // extract answer details from XML
+ $text = addslashes($answer['text'][0]['#']);
+ $fraction = empty($answer['correct'][0]['#']) ? 0 : 1;
+ $feedback = addslashes($answer['feedback'][0]['#']);
+ // store answer
+ if ($moodle_14) {
+ $question->answers[$q]->alternatives[$a] = new stdClass();
+ $question->answers[$q]->alternatives[$a]->answer = $text;
+ $question->answers[$q]->alternatives[$a]->fraction = $fraction;
+ $question->answers[$q]->alternatives[$a]->feedback = $feedback;
+ } else {
+ $wrapped->answer[] = $text;
+ $wrapped->fraction[] = $fraction;
+ $wrapped->feedback[] = $feedback;
+ $answers[] = (empty($fraction) ? '' : '=').$text.(empty($feedback) ? '' : ('#'.$feedback));
+ }
$a++;
}
- if ($moodle_14) {
- // Moodle 1.4 (or earlier)
- } else {
- // Moodle 1.5 (or greater)
- $wrapped->questiontext = '{'.$positionkey.':SHORTANSWER:'.implode('~', $answers).'}';
- $question->options->questions[] = $wrapped;
- }
+ // compile answers into question text, if necessary
+ if ($moodle_14) {
+ // do nothing
+ } else {
+ $wrapped->questiontext = '{:SHORTANSWER:'.implode('~', $answers).'}';
+ $question->options->questions[] = $wrapped;
+ }
$q++;
}
if (isset($exercise[$q])) {

0 comments on commit aa35bd0

Please sign in to comment.