function qformat_blackboard::process_mc in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/blackboard/format.php \qformat_blackboard::process_mc()
1 call to qformat_blackboard::process_mc()
- qformat_blackboard::readquestions in includes/
moodle/ question/ format/ blackboard/ 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/ blackboard/ format.php, line 173
Class
Code
function process_mc($xml, &$questions) {
if (isset($xml["POOL"]["#"]["QUESTION_MULTIPLECHOICE"])) {
$mcquestions = $xml["POOL"]["#"]["QUESTION_MULTIPLECHOICE"];
}
else {
return;
}
for ($i = 0; $i < sizeof($mcquestions); $i++) {
$question = $this
->defaultquestion();
$question->qtype = MULTICHOICE;
$question->single = 1;
// Only one answer is allowed
$thisquestion = $mcquestions[$i];
// determine if the question is already escaped html
$ishtml = $thisquestion["#"]["BODY"][0]["#"]["FLAGS"][0]["#"]["ISHTML"][0]["@"]["value"];
// put questiontext in question object
if ($ishtml) {
$question->questiontext = html_entity_decode_php4(trim($thisquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"]));
}
$question->questiontext = addslashes($question->questiontext);
// put name of question in question object, careful of length
$question->name = substr($question->questiontext, 0, 254);
$choices = $thisquestion["#"]["ANSWER"];
for ($j = 0; $j < sizeof($choices); $j++) {
$choice = trim($choices[$j]["#"]["TEXT"][0]["#"]);
// put this choice in the question object.
if ($ishtml) {
$question->answer[$j] = html_entity_decode_php4($choice);
}
$question->answer[$j] = addslashes($question->answer[$j]);
$id = $choices[$j]["@"]["id"];
$correct_answer_id = $thisquestion["#"]["GRADABLE"][0]["#"]["CORRECTANSWER"][0]["@"]["answer_id"];
// if choice is the answer, give 100%, otherwise give 0%
if (strcmp($id, $correct_answer_id) == 0) {
$question->fraction[$j] = 1;
if ($ishtml) {
$question->feedback[$j] = html_entity_decode_php4(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_CORRECT"][0]["#"]));
}
$question->feedback[$j] = addslashes($question->feedback[$j]);
}
else {
$question->fraction[$j] = 0;
if ($ishtml) {
$question->feedback[$j] = html_entity_decode_php4(trim(@$thisquestion["#"]["GRADABLE"][0]["#"]["FEEDBACK_WHEN_INCORRECT"][0]["#"]));
}
$question->feedback[$j] = addslashes($question->feedback[$j]);
}
}
$questions[] = $question;
}
}