diff --git a/question/export.php b/question/export.php
index 294175b..65d24d5 100644
--- a/question/export.php
+++ b/question/export.php
@@ -26,8 +26,6 @@
$categoryid = $pagevars['cat'];
}
- // ensure the files area exists for this course
- make_upload_directory("$COURSE->id");
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
print_error('nocategory','quiz');
@@ -76,7 +74,8 @@
print_error('exporterror', 'question', $thispageurl->out());
}
- if (! $qformat->exportprocess()) { // Process the export data
+ // export data to moodle file pool
+ if (!$userfile = $qformat->exportprocess()) { // Process the export data
print_error('exporterror', 'question', $thispageurl->out());
}
@@ -88,19 +87,16 @@
// link to download the finished file
$file_ext = $qformat->export_file_extension();
$filename = $from_form->exportfilename . $file_ext;
- if ($canaccessbackupdata) {
- $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename,
- array('forcedownload' => 1));
- echo '
';
- echo '' .
- get_string('downloadextra', 'quiz') . '
';
- } else {
- $efile = get_file_url($filename, null, 'questionfile');
- echo '' .
- get_string('yourfileshoulddownload', 'question', $efile) . '
';
- $PAGE->requires->js_function_call('document.location.replace', array($efile), false, 1);
- }
+
+ // build user private file url
+ $user_context = get_context_instance(CONTEXT_USER, $USER->id);
+ $efile = moodle_url::make_pluginfile_url($user_context->id, 'user', 'private', null, $userfile->get_filepath(), $userfile->get_filename(), true)->out();
+
+ echo $OUTPUT->box_start('boxaligncenter');
+ echo get_string('yourfileshoulddownload', 'question', $efile);
+ echo $OUTPUT->box_end();
+
+ $PAGE->requires->js_function_call('document.location.replace', array($efile), false, 1);
echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
echo $OUTPUT->footer();
@@ -113,4 +109,3 @@
$export_form->display();
echo $OUTPUT->footer();
-
diff --git a/question/format.php b/question/format.php
index cc0203f..b695cba 100644
--- a/question/format.php
+++ b/question/format.php
@@ -651,20 +651,14 @@ class qformat_default {
/**
* Do the export
* For most types this should not need to be overrided
- * @return boolean success
+ * @return stored_file
*/
function exportprocess() {
- global $CFG, $OUTPUT;
-
- // create a directory for the exports (if not already existing)
- if (! $export_dir = make_upload_directory($this->question_get_export_dir())) {
- print_error('cannotcreatepath', 'quiz', $export_dir);
- }
- $path = $CFG->dataroot.'/'.$this->question_get_export_dir();
+ global $CFG, $OUTPUT, $USER;
// get the questions (from database) in this category
// only get q's with no parents (no cloze subquestions specifically)
- if ($this->category){
+ if ($this->category) {
$questions = get_questions_category( $this->category, true );
} else {
$questions = $this->questions;
@@ -684,7 +678,6 @@ class qformat_default {
// iterate through questions
foreach($questions as $question) {
-
// do not export hidden questions
if (!empty($question->hidden)) {
continue;
@@ -714,7 +707,13 @@ class qformat_default {
// export the question displaying message
$count++;
- echo "
$count. ".$this->format_question_text($question)."
";
+
+ echo '
';
+ echo $OUTPUT->container_start();
+ echo '' . $count . '. ';
+ echo $this->format_question_text($question);
+ echo $OUTPUT->container_end();
+
if (question_has_capability_on($question, 'view', $question->category)){
$expout .= $this->writequestion( $question ) . "\n";
}
@@ -730,18 +729,26 @@ class qformat_default {
}
// final pre-process on exported data
- $expout = $this->presave_process( $expout );
-
- // write file
- $filepath = $path."/".$this->filename . $this->export_file_extension();
- if (!$fh=fopen($filepath,"w")) {
- print_error( 'cannotopen','quiz',$continuepath,$filepath );
- }
- if (!fwrite($fh, $expout, strlen($expout) )) {
- print_error( 'cannotwrite','quiz',$continuepath,$filepath );
- }
- fclose($fh);
- return true;
+ $expout = $this->presave_process($expout);
+
+ // file storage
+ $fs = get_file_storage();
+ $user_context = get_context_instance(CONTEXT_USER, $USER->id);
+ $filename = $this->filename . $this->export_file_extension();
+ $record = array(
+ 'contextid'=>$user_context->id,
+ 'component'=>'user',
+ 'filearea'=>'private',
+ 'itemid'=>0,
+ 'filepath'=>'/',
+ 'filename'=>$filename
+ );
+ // check if file exists
+ if ($fs->file_exists($user_context->id, 'user', 'private', 0, '/', $filename)) {
+ print_error('fileexists');
+ }
+ $draftfile = $fs->create_file_from_string($record, $expout);
+ return $draftfile;
}
/**
diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index 5669543..91c71d6 100755
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -853,8 +853,10 @@ class qformat_xml extends qformat_default {
$expout .= " \n";
$expout .= $question_text;
$expout .= " \n";
- $expout .= " {$question->image}\n";
- $expout .= $this->writeimage($question->image);
+ if (!empty($question->image)) {
+ $expout .= " {$question->image}\n";
+ $expout .= $this->writeimage($question->image);
+ }
$expout .= " \n";
$expout .= $generalfeedback;
$expout .= " \n";