You are here

function qformat_qti2::quiz_export_prepare_questions in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/qti2/format.php \qformat_qti2::quiz_export_prepare_questions()

Prepares questions for quiz export

The questions are changed as follows:

  • the question answers atached to the questions
  • image set to an http reference instead of a file path
  • qti specific info added
  • exporttext added, which contains an xml-formatted qti assesmentItem

Parameters

array $questions - an array of question objects:

int $quizid:

Return value

an array of question arrays

1 call to qformat_qti2::quiz_export_prepare_questions()
qformat_qti2::exportprocess_quiz in includes/moodle/question/format/qti2/format.php
This function is called to export a quiz (as opposed to exporting a category of questions)

File

includes/moodle/question/format/qti2/format.php, line 411

Class

qformat_qti2

Code

function quiz_export_prepare_questions($questions, $quizid, $courseid, $shuffleanswers = null) {
  global $CFG;

  // add the answers to the questions and format the image property
  foreach ($questions as $key => $question) {
    $questions[$key] = get_question_data($question);
    $questions[$key]->courseid = $courseid;
    $questions[$key]->quizid = $quizid;
    if ($question->image) {
      if (empty($question->mediamimetype)) {
        $questions[$key]->mediamimetype = mimeinfo('type', $question->image);
      }
      $localfile = substr(strtolower($question->image), 0, 7) == 'http://' ? false : true;
      if ($localfile) {

        // create the http url that the player will need to access the file
        if ($CFG->slasharguments) {

          // Use this method if possible for better caching
          $questions[$key]->mediaurl = "{$CFG->wwwroot}/file.php/{$question->image}";
        }
        else {
          $questions[$key]->mediaurl = "{$CFG->wwwroot}/file.php?file={$question->image}";
        }
      }
      else {
        $questions[$key]->mediaurl = $question->image;
      }
    }
  }
  $this
    ->add_qti_info($questions);
  $questions = $this
    ->questions_with_export_info($questions, $shuffleanswers);
  $questions = $this
    ->objects_to_array($questions);
  return $questions;
}