function qformat_hotpot::process_jcloze in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/hotpot/format.php \qformat_hotpot::process_jcloze()
1 call to qformat_hotpot::process_jcloze()
- qformat_hotpot::readquestions in includes/moodle/question/format/hotpot/format.php
- Parses an array of lines into an array of questions,
where each item is a question object as defined by
readquestion(). Questions are defined as anything
between blank lines.
File
- includes/moodle/question/format/hotpot/format.php, line 106
Class
- qformat_hotpot
- @package questionbank
@subpackage importexport
Code
function process_jcloze(&$xml, &$questions) {
$defaultgrade = 1;
$gap_count = 0;
global $CFG, $db;
$moodle_14 = false;
if ($columns = $db
->MetaColumns("{$CFG->prefix}question_multianswer")) {
foreach ($columns as $column) {
if ($column->name == 'answers' || $column->name == 'positionkey' || $column->name == 'answertype' || $column->name == 'norm') {
$moodle_14 = true;
}
}
}
$tags = 'data,gap-fill';
$x = 0;
while (($exercise = "[{$x}]['#']") && $xml
->xml_value($tags, $exercise)) {
if (method_exists($this, 'defaultquestion')) {
$question = $this
->defaultquestion();
}
else {
$question = new stdClass();
$question->usecase = 0;
$question->image = "";
}
$question->qtype = MULTIANSWER;
$question->name = $this
->hotpot_get_title($xml, $x);
$question->questiontext = $this
->hotpot_get_reading($xml);
if ($moodle_14) {
$question->answers = array();
}
else {
global $COURSE;
$question->course = $COURSE->id;
$question->options = new stdClass();
$question->options->questions = array();
}
$q = 0;
while ($text = $xml
->xml_value($tags, $exercise . "[{$q}]")) {
$question->questiontext .= $this
->hotpot_prepare_str($text);
$question_record = $exercise . "['question-record'][{$q}]['#']";
if ($xml
->xml_value($tags, $question_record)) {
$gap_count++;
$positionkey = $q + 1;
$question->questiontext .= '{#' . $positionkey . '}';
if ($moodle_14) {
$question->answers[$q]->positionkey = $positionkey;
$question->answers[$q]->answertype = SHORTANSWER;
$question->answers[$q]->norm = $defaultgrade;
$question->answers[$q]->alternatives = array();
}
else {
$wrapped = new stdClass();
$wrapped->qtype = SHORTANSWER;
$wrapped->usecase = 0;
$wrapped->defaultgrade = $defaultgrade;
$wrapped->questiontextformat = 0;
$wrapped->answer = array();
$wrapped->fraction = array();
$wrapped->feedback = array();
$answers = array();
}
$a = 0;
while (($answer = $question_record . "['answer'][{$a}]['#']") && $xml
->xml_value($tags, $answer)) {
$text = $this
->hotpot_prepare_str($xml
->xml_value($tags, $answer . "['text'][0]['#']"));
$correct = $xml
->xml_value($tags, $answer . "['correct'][0]['#']");
$feedback = $this
->hotpot_prepare_str($xml
->xml_value($tags, $answer . "['feedback'][0]['#']"));
if ($text) {
$fraction = empty($correct) ? 0 : 1;
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) {
}
else {
$wrapped->questiontext = '{' . $defaultgrade . ':SHORTANSWER:' . implode('~', $answers) . '}';
$question->options->questions[] = $wrapped;
}
}
$q++;
}
$question->defaultgrade = $gap_count * $defaultgrade;
$questions[] = $question;
$x++;
}
}