You are here

function qformat_blackboard::process_ma in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/question/format/blackboard/format.php \qformat_blackboard::process_ma()
1 call to qformat_blackboard::process_ma()
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 237

Class

qformat_blackboard

Code

function process_ma($xml, &$questions) {
  if (isset($xml["POOL"]["#"]["QUESTION_MULTIPLEANSWER"])) {
    $maquestions = $xml["POOL"]["#"]["QUESTION_MULTIPLEANSWER"];
  }
  else {
    return;
  }
  for ($i = 0; $i < sizeof($maquestions); $i++) {
    $question = $this
      ->defaultquestion();
    $question->qtype = MULTICHOICE;
    $question->defaultgrade = 1;
    $question->single = 0;

    // More than one answers allowed
    $question->image = "";

    // No images with this format
    $thisquestion = $maquestions[$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
    $question->name = substr($question->questiontext, 0, 254);
    $choices = $thisquestion["#"]["ANSWER"];
    $correctanswers = $thisquestion["#"]["GRADABLE"][0]["#"]["CORRECTANSWER"];
    for ($j = 0; $j < sizeof($choices); $j++) {
      $choice = trim($choices[$j]["#"]["TEXT"][0]["#"]);

      // put this choice in the question object.
      $question->answer[$j] = addslashes($choice);
      $correctanswercount = sizeof($correctanswers);
      $id = $choices[$j]["@"]["id"];
      $iscorrect = 0;
      for ($k = 0; $k < $correctanswercount; $k++) {
        $correct_answer_id = trim($correctanswers[$k]["@"]["answer_id"]);
        if (strcmp($id, $correct_answer_id) == 0) {
          $iscorrect = 1;
        }
      }
      if ($iscorrect) {
        $question->fraction[$j] = floor(100000 / $correctanswercount) / 100000;

        // strange behavior if we have more than 5 decimal places
        $question->feedback[$j] = addslashes(trim($thisquestion["#"]["GRADABLE"][$j]["#"]["FEEDBACK_WHEN_CORRECT"][0]["#"]));
      }
      else {
        $question->fraction[$j] = 0;
        $question->feedback[$j] = addslashes(trim($thisquestion["#"]["GRADABLE"][$j]["#"]["FEEDBACK_WHEN_INCORRECT"][0]["#"]));
      }
    }
    $questions[] = $question;
  }
}