You are here

function qformat_xml::import_truefalse in Quiz 6.5

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

import true/false type question

Parameters

array question question array from xml tree:

Return value

object question object

1 call to qformat_xml::import_truefalse()
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 229

Class

qformat_xml

Code

function import_truefalse($question) {

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

  // 'header' parts particular to true/false
  $qo->qtype = TRUEFALSE;

  // get answer info
  //
  // In the past, it used to be assumed that the two answers were in the file
  // true first, then false. Howevever that was not always true. Now, we
  // try to match on the answer text, but in old exports, this will be a localised
  // string, so if we don't find true or false, we fall back to the old system.
  $first = true;
  $warning = false;
  foreach ($question['#']['answer'] as $answer) {
    $answertext = $this
      ->getpath($answer, array(
      '#',
      'text',
      0,
      '#',
    ), '', true);
    $feedback = $this
      ->getpath($answer, array(
      '#',
      'feedback',
      0,
      '#',
      'text',
      0,
      '#',
    ), '', true);
    if ($answertext != 'true' && $answertext != 'false') {
      $warning = true;
      $answertext = $first ? 'true' : 'false';

      // Old style file, assume order is true/false.
    }
    if ($answertext == 'true') {
      $qo->answer = $answer['@']['fraction'] == 100;
      $qo->correctanswer = $qo->answer;
      $qo->feedbacktrue = $feedback;
    }
    else {
      $qo->answer = $answer['@']['fraction'] != 100;
      $qo->correctanswer = $qo->answer;
      $qo->feedbackfalse = $feedback;
    }
    $first = false;
  }
  if ($warning) {
    $a = new stdClass();
    $a->questiontext = $qo->questiontext;
    $a->answer = get_string($qo->answer ? 'true' : 'false', 'quiz');
    notify(get_string('truefalseimporterror', 'quiz', $a));
  }
  return $qo;
}