function qformat_blackboard_6::readdata in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/question/format/blackboard_6/format.php \qformat_blackboard_6::readdata()
Return complete file within an array, one item per line
Parameters
string filename name of file:
Return value
mixed contents array or false on failure
Overrides qformat_default::readdata
File
- includes/moodle/ question/ format/ blackboard_6/ format.php, line 153 
Class
Code
function readdata($filename) {
  /// Returns complete file with an array, one item per line
  global $CFG;
  // if the extension is .dat we just return that,
  // if .zip we unzip the file and get the data
  $ext = substr($this->realfilename, strpos($this->realfilename, '.'), strlen($this->realfilename) - 1);
  if ($ext == '.dat') {
    if (!is_readable($filename)) {
      error("File is not readable");
    }
    return file($filename);
  }
  $unique_code = time();
  $temp_dir = $CFG->dataroot . "/temp/bbquiz_import/" . $unique_code;
  $this->temp_dir = $temp_dir;
  if ($this
    ->check_and_create_import_dir($unique_code)) {
    if (is_readable($filename)) {
      if (!copy($filename, "{$temp_dir}/bboard.zip")) {
        error("Could not copy backup file");
      }
      if (unzip_file("{$temp_dir}/bboard.zip", '', false)) {
        // assuming that the information is in res0001.dat
        // after looking at 6 examples this was always the case
        $q_file = "{$temp_dir}/res00001.dat";
        if (is_file($q_file)) {
          if (is_readable($q_file)) {
            $filearray = file($q_file);
            /// Check for Macintosh OS line returns (ie file on one line), and fix
            if (ereg("\r", $filearray[0]) and !ereg("\n", $filearray[0])) {
              return explode("\r", $filearray[0]);
            }
            else {
              return $filearray;
            }
          }
        }
        else {
          error("Could not find question data file in zip");
        }
      }
      else {
        print "filename: {$filename}<br />tempdir: {$temp_dir} <br />";
        error("Could not unzip file.");
      }
    }
    else {
      error("Could not read uploaded file");
    }
  }
  else {
    error("Could not create temporary directory");
  }
}