You are here

function qformat_hotpot::process_jmatch in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/hotpot/format.php \qformat_hotpot::process_jmatch()
1 call to qformat_hotpot::process_jmatch()
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 258

Class

qformat_hotpot
@package questionbank @subpackage importexport

Code

function process_jmatch(&$xml, &$questions) {

  // define default grade (per matched pair)
  $defaultgrade = 1;
  $match_count = 0;

  // xml tags to the start of the matching exercise
  $tags = 'data,matching-exercise';
  $x = 0;
  while (($exercise = "[{$x}]['#']") && $xml
    ->xml_value($tags, $exercise)) {

    // there is usually only one exercise in a file
    if (method_exists($this, 'defaultquestion')) {
      $question = $this
        ->defaultquestion();
    }
    else {
      $question = new stdClass();
      $question->usecase = 0;

      // Ignore case
      $question->image = "";

      // No images with this format
    }
    $question->qtype = MATCH;
    $question->name = $this
      ->hotpot_get_title($xml, $x);
    $question->questiontext = $this
      ->hotpot_get_reading($xml);
    $question->questiontext .= $this
      ->hotpot_get_instructions($xml);
    $question->subquestions = array();
    $question->subanswers = array();
    $p = 0;
    while (($pair = $exercise . "['pair'][{$p}]['#']") && $xml
      ->xml_value($tags, $pair)) {
      $left = $xml
        ->xml_value($tags, $pair . "['left-item'][0]['#']['text'][0]['#']");
      $right = $xml
        ->xml_value($tags, $pair . "['right-item'][0]['#']['text'][0]['#']");
      if ($left && $right) {
        $match_count++;
        $question->subquestions[$p] = $this
          ->hotpot_prepare_str($left);
        $question->subanswers[$p] = $this
          ->hotpot_prepare_str($right);
      }
      $p++;
    }
    $question->defaultgrade = $match_count * $defaultgrade;
    $questions[] = $question;
    $x++;
  }
}