function qformat_qti2::exportprocess in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/qti2/format.php \qformat_qti2::exportprocess()
exports the questions in a question category to the given location
The parent class method was overridden because the IMS export consists of multiple files
Parameters
string $filename the directory name which will hold the exported files:
Return value
boolean - or errors out
Overrides qformat_default::exportprocess
File
- includes/
moodle/ question/ format/ qti2/ format.php, line 237
Class
Code
function exportprocess() {
global $CFG;
$courseid = $this->course->id;
// create a directory for the exports (if not already existing)
if (!($export_dir = make_upload_directory($this
->question_get_export_dir() . '/' . $this->filename))) {
error(get_string('cannotcreatepath', 'quiz', $export_dir));
}
$path = $CFG->dataroot . '/' . $this
->question_get_export_dir() . '/' . $this->filename;
// get the questions (from database) in this category
// $questions = get_records("question","category",$this->category->id);
// HACK FIXME EDIT a rare edit to the Moodle code
// why load from category when we already have the questions?
// $questions = get_questions_category( $this->category );
$questions = $this->questions;
notify("Exporting " . count($questions) . " questions.");
$count = 0;
// create the imsmanifest file
$smarty =& $this
->init_smarty();
$this
->add_qti_info($questions);
// copy files used by the main questions to the export directory
$result = $this
->handle_questions_media($questions, $path, $courseid);
if ($result !== true) {
notify(implode("<br />", $result));
}
$manifestquestions = $this
->objects_to_array($questions);
$manifestid = str_replace(array(
':',
'/',
), array(
'-',
'_',
), "question_category_{$this->category->id}---{$CFG->wwwroot}");
$smarty
->assign('externalfiles', 1);
$smarty
->assign('manifestidentifier', $manifestid);
$smarty
->assign('quiztitle', "question_category_{$this->category->id}");
$smarty
->assign('quizinfo', "All questions in category {$this->category->id}");
$smarty
->assign('questions', $manifestquestions);
$smarty
->assign('lang', $this->lang);
$smarty->error_reporting = 99;
$expout = $smarty
->fetch('imsmanifest.tpl');
$filepath = $path . '/imsmanifest.xml';
if (empty($expout)) {
error("Unkown error - empty imsmanifest.xml");
}
if (!($fh = fopen($filepath, "w"))) {
error("Cannot open for writing: {$filepath}");
}
if (!fwrite($fh, $expout)) {
error("Cannot write exported questions to {$filepath}");
}
fclose($fh);
// iterate through questions
foreach ($questions as $question) {
// results are first written into string (and then to a file)
$count++;
echo "<hr /><p><b>{$count}</b>. " . stripslashes($question->questiontext) . "</p>";
$expout = $this
->writequestion($question, null, true, $path) . "\n";
$expout = $this
->presave_process($expout);
$filepath = $path . '/' . $this
->get_assesment_item_id($question) . ".xml";
if (!($fh = fopen($filepath, "w"))) {
error("Cannot open for writing: {$filepath}");
}
if (!fwrite($fh, $expout)) {
error("Cannot write exported questions to {$filepath}");
}
fclose($fh);
}
// zip files into single export file
print "path: {$path}";
zip_files(array(
$path,
), "{$path}.zip");
// FIXME TODO EDIT rare edit to Moodle format code
// how else am I supposed to know what the filename of the zip is?
$this->filename = basename($path);
// remove the temporary directory
remove_dir($path);
return true;
}