You are here

function qformat_xml::import_multichoice in Quiz 6.6

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

import multiple choice question

Parameters

array question question array from xml tree:

Return value

object question object

1 call to qformat_xml::import_multichoice()
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 170

Class

qformat_xml

Code

function import_multichoice($question) {

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

  // 'header' parts particular to multichoice
  $qo->qtype = MULTICHOICE;
  $single = $this
    ->getpath($question, array(
    '#',
    'single',
    0,
    '#',
  ), 'true');
  $qo->single = $this
    ->trans_single($single);
  $shuffleanswers = $this
    ->getpath($question, array(
    '#',
    'shuffleanswers',
    0,
    '#',
  ), 'false');
  $qo->answernumbering = $this
    ->getpath($question, array(
    '#',
    'answernumbering',
    0,
    '#',
  ), 'abc');
  $qo->shuffleanswers = $this
    ->trans_single($shuffleanswers);
  $qo->correctfeedback = $this
    ->getpath($question, array(
    '#',
    'correctfeedback',
    0,
    '#',
    'text',
    0,
    '#',
  ), '', true);
  $qo->partiallycorrectfeedback = $this
    ->getpath($question, array(
    '#',
    'partiallycorrectfeedback',
    0,
    '#',
    'text',
    0,
    '#',
  ), '', true);
  $qo->incorrectfeedback = $this
    ->getpath($question, array(
    '#',
    'incorrectfeedback',
    0,
    '#',
    'text',
    0,
    '#',
  ), '', true);

  // There was a time on the 1.8 branch when it could output an empty answernumbering tag, so fix up any found.
  if (empty($qo->answernumbering)) {
    $qo->answernumbering = 'abc';
  }

  // run through the answers
  $answers = $question['#']['answer'];
  $a_count = 0;
  foreach ($answers as $answer) {
    $ans = $this
      ->import_answer($answer);
    $qo->answer[$a_count] = $ans->answer;
    $qo->fraction[$a_count] = $ans->fraction;
    $qo->feedback[$a_count] = $ans->feedback;
    ++$a_count;
  }
  return $qo;
}