You are here

function qformat_blackboard::process_matching in Quiz 6.6

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

Class

qformat_blackboard

Code

function process_matching($xml, &$questions) {
  if (isset($xml["POOL"]["#"]["QUESTION_MATCH"])) {
    $matchquestions = $xml["POOL"]["#"]["QUESTION_MATCH"];
  }
  else {
    return;
  }
  for ($i = 0; $i < sizeof($matchquestions); $i++) {
    $question = $this
      ->defaultquestion();
    $question->qtype = MATCH;
    $thisquestion = $matchquestions[$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["#"]["CHOICE"];
    for ($j = 0; $j < sizeof($choices); $j++) {
      $subquestion = NULL;
      $choice = $choices[$j]["#"]["TEXT"][0]["#"];
      $choice_id = $choices[$j]["@"]["id"];
      $question->subanswers[] = addslashes(trim($choice));
      $correctanswers = $thisquestion["#"]["GRADABLE"][0]["#"]["CORRECTANSWER"];
      for ($k = 0; $k < sizeof($correctanswers); $k++) {
        if (strcmp($choice_id, $correctanswers[$k]["@"]["choice_id"]) == 0) {
          $answer_id = $correctanswers[$k]["@"]["answer_id"];
          $answers = $thisquestion["#"]["ANSWER"];
          for ($m = 0; $m < sizeof($answers); $m++) {
            $answer = $answers[$m];
            $current_ans_id = $answer["@"]["id"];
            if (strcmp($current_ans_id, $answer_id) == 0) {
              $answer = $answer["#"]["TEXT"][0]["#"];
              $question->subquestions[] = addslashes(trim($answer));
              break;
            }
          }
          break;
        }
      }
    }
    $questions[] = $question;
  }
}