You are here

function qformat_qti2::copy_and_flatten in Quiz 6.5

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

flattens $object['media'], copies $object['media'] to $path, and sets $object['mediamimetype']

@return: mixed - true on success or in case of an empty media field, an error string if the file copy fails

Parameters

array &$object containing a field 'media':

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

int $courseid:

File

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

Class

qformat_qti2

Code

function copy_and_flatten(&$object, $path, $courseid) {
  global $CFG;
  if (!empty($object['media'])) {
    $location = $object['media'];
    $object['media'] = $this
      ->flatten_image_name($location);
    if (!@copy("{$CFG->dataroot}/{$courseid}/{$location}", "{$path}/{$object['media']}")) {
      return "Failed to copy {$CFG->dataroot}/{$courseid}/{$location} to {$path}/{$object['media']}";
    }
    if (empty($object['mediamimetype'])) {
      $object['mediamimetype'] = mimeinfo('type', $object['media']);
    }
  }
  return true;
}