function qformat_hotpot::process_jquiz in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/question/format/hotpot/format.php \qformat_hotpot::process_jquiz()
1 call to qformat_hotpot::process_jquiz()
- 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 357
Class
- qformat_hotpot
- @package questionbank
@subpackage importexport
Code
function process_jquiz(&$xml, &$questions) {
$defaultgrade = 1;
$tags = 'data,questions';
$x = 0;
while (($exercise = "[{$x}]['#']") && $xml
->xml_value($tags, $exercise)) {
$q = 0;
while (($question_record = $exercise . "['question-record'][{$q}]['#']") && $xml
->xml_value($tags, $question_record)) {
if (method_exists($this, 'defaultquestion')) {
$question = $this
->defaultquestion();
}
else {
$question = new stdClass();
$question->usecase = 0;
$question->image = "";
}
$question->defaultgrade = $defaultgrade;
$question->name = $this
->hotpot_get_title($xml, $q, true);
$text = $xml
->xml_value($tags, $question_record . "['question'][0]['#']");
$question->questiontext = $this
->hotpot_prepare_str($text);
if ($xml
->xml_value($tags, $question_record . "['answers']")) {
$answers = $question_record . "['answers'][0]['#']";
}
else {
$answers = $question_record;
}
if ($xml
->xml_value($tags, $question_record . "['question-type']")) {
$type = $xml
->xml_value($tags, $question_record . "['question-type'][0]['#']");
}
else {
switch ($xml->quiztype) {
case 'jbc':
$must_select_all = $xml
->xml_value($tags, $question_record . "['must-select-all'][0]['#']");
if (empty($must_select_all)) {
$type = 1;
}
else {
$type = 4;
}
break;
case 'jquiz':
$type = 2;
break;
default:
$type = 0;
}
}
$question->qtype = $type == 2 ? SHORTANSWER : MULTICHOICE;
$question->single = $type == 4 ? 0 : 1;
$no_of_correct_answers = 0;
if ($type == 4) {
$a = 0;
while (($answer = $answers . "['answer'][{$a}]['#']") && $xml
->xml_value($tags, $answer)) {
$correct = $xml
->xml_value($tags, $answer . "['correct'][0]['#']");
if (empty($correct)) {
}
else {
$no_of_correct_answers++;
}
$a++;
}
}
$a = 0;
$question->answer = array();
$question->fraction = array();
$question->feedback = array();
$aa = 0;
$correct_answers = array();
$correct_answers_all_zero = true;
while (($answer = $answers . "['answer'][{$a}]['#']") && $xml
->xml_value($tags, $answer)) {
$correct = $xml
->xml_value($tags, $answer . "['correct'][0]['#']");
if (empty($correct)) {
$fraction = 0;
}
else {
if ($type == 4) {
$fraction = round(1 / $no_of_correct_answers, 5);
}
else {
if ($xml
->xml_value($tags, $answer . "['percent-correct']")) {
$percent = $xml
->xml_value($tags, $answer . "['percent-correct'][0]['#']");
$fraction = $percent / 100;
}
else {
$fraction = 1;
}
}
}
$answertext = $this
->hotpot_prepare_str($xml
->xml_value($tags, $answer . "['text'][0]['#']"));
if ($answertext != '') {
$question->answer[$aa] = $answertext;
$question->fraction[$aa] = $fraction;
$question->feedback[$aa] = $this
->hotpot_prepare_str($xml
->xml_value($tags, $answer . "['feedback'][0]['#']"));
if ($correct) {
if ($fraction) {
$correct_answers_all_zero = false;
}
$correct_answers[] = $aa;
}
$aa++;
}
$a++;
}
if ($correct_answers_all_zero) {
foreach ($correct_answers as $aa) {
$question->fraction[$aa] = 1;
}
}
if (!empty($question->questiontext)) {
$questions[] = $question;
}
$q++;
}
$x++;
}
}