You are here

function qformat_xml::import_numerical in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/xml/format.php \qformat_xml::import_numerical()

import numerical type question

Parameters

array question question array from xml tree:

Return value

object question object

1 call to qformat_xml::import_numerical()
qformat_xml::readquestions in includes/moodle/question/format/xml/format.php
parse the array of lines into an array of questions this *could* burn memory - but it won't happen that much so fingers crossed!

File

includes/moodle/question/format/xml/format.php, line 321

Class

qformat_xml

Code

function import_numerical($question) {

  // get common parts
  $qo = $this
    ->import_headers($question);

  // header parts particular to numerical
  $qo->qtype = NUMERICAL;

  // get answers array
  $answers = $question['#']['answer'];
  $qo->answer = array();
  $qo->feedback = array();
  $qo->fraction = array();
  $qo->tolerance = array();
  foreach ($answers as $answer) {

    // answer outside of <text> is deprecated
    $answertext = trim($this
      ->getpath($answer, array(
      '#',
      0,
    ), ''));
    $qo->answer[] = $this
      ->getpath($answer, array(
      '#',
      'text',
      0,
      '#',
    ), $answertext, true);
    if (empty($qo->answer)) {
      $qo->answer = '*';
    }
    $qo->feedback[] = $this
      ->getpath($answer, array(
      '#',
      'feedback',
      0,
      '#',
      'text',
      0,
      '#',
    ), '', true);
    $qo->tolerance[] = $this
      ->getpath($answer, array(
      '#',
      'tolerance',
      0,
      '#',
    ), 0);

    // fraction as a tag is deprecated
    $fraction = $this
      ->getpath($answer, array(
      '@',
      'fraction',
    ), 0) / 100;
    $qo->fraction[] = $this
      ->getpath($answer, array(
      '#',
      'fraction',
      0,
      '#',
    ), $fraction);

    // deprecated
  }

  // get units array
  $qo->unit = array();
  $units = $this
    ->getpath($question, array(
    '#',
    'units',
    0,
    '#',
    'unit',
  ), array());
  if (!empty($units)) {
    $qo->multiplier = array();
    foreach ($units as $unit) {
      $qo->multiplier[] = $this
        ->getpath($unit, array(
        '#',
        'multiplier',
        0,
        '#',
      ), 1);
      $qo->unit[] = $this
        ->getpath($unit, array(
        '#',
        'unit_name',
        0,
        '#',
      ), '', true);
    }
  }
  return $qo;
}