You are here

function qformat_qti2::handle_questions_media in Quiz 6.5

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

copies all files needed by the questions to the given $path, and flattens the file names

Parameters

array $questions the question objects:

string $path the full path name to where the media files need to be copied:

int $courseid:

Return value

mixed true on success, an array of error messages otherwise

1 call to qformat_qti2::handle_questions_media()
qformat_qti2::exportprocess in includes/moodle/question/format/qti2/format.php
exports the questions in a question category to the given location

File

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

Class

qformat_qti2

Code

function handle_questions_media(&$questions, $path, $courseid) {
  global $CFG;
  $errors = array();
  foreach ($questions as $key => $question) {

    // todo: handle in-line media (specified in the question text)
    if (!empty($question->image)) {
      $location = $questions[$key]->image;
      $questions[$key]->mediaurl = $this
        ->flatten_image_name($location);
      if (!@copy("{$CFG->dataroot}/{$courseid}/{$location}", "{$path}/{$questions[$key]->mediaurl}")) {
        $errors[] = "Failed to copy {$CFG->dataroot}/{$courseid}/{$location} to {$path}/{$questions[$key]->mediaurl}";
      }
      if (empty($question->mediamimetype)) {
        $questions[$key]->mediamimetype = mimeinfo('type', $question->image);
      }
    }
  }
  return empty($errors) ? true : $errors;
}