From 4c2a04ee16ec0ca7a8abebb33757270a02345f74 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 30 Jun 2004 10:16:14 +0000 Subject: [PATCH] Added 'virtual' method for writequestion --- mod/quiz/format.php | 76 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/mod/quiz/format.php b/mod/quiz/format.php index 2af24e200c..e1cb9e3501 100644 --- a/mod/quiz/format.php +++ b/mod/quiz/format.php @@ -6,7 +6,7 @@ /// Doesn't do everything on it's own -- it needs to be extended. // //////////////////////////////////////////////////////////////////// -// Included by import.php +// Included by import.php and export.php class quiz_default_format { @@ -142,6 +142,80 @@ class quiz_default_format { return true; } +// Export functions + + + function exportpreprocess($category) { + /// Does any pre-processing that may be desired + + $this->category = $category; // Important + + return true; + } + + function exportprocess($filename) { + /// Exports a given category. There's probably little need to change this + + global $CFG; + + // create a directory for the exports (if not already existing) + $dirname = get_string("exportfilename","quiz"); + $courseid = $this->category->course; + $path = $CFG->dataroot.'/'.$courseid.'/'.$dirname; + if (!is_dir($path)) { + if (!mkdir($path, $CFG->directorypermissions)) { + error("Cannot create path: $path"); + } + } + + // get the questions (from database) in this category + // $questions = get_records("quiz_questions","category",$this->category->id); + $questions = get_questions_category( $this->category ); + + notify("Exporting ".count($questions)." questions."); + $count = 0; + + // results are first written into string (and then to a file) + // so create/initialize the string here + $expout = ""; + + // iterate through questions + foreach($questions as $question) { + $count++; + echo "

$count. ".stripslashes($question->questiontext)."

"; + $expout .= $this->writequestion( $question ); + } + + // write file + $filepath = $path."/".$filename; + if (!$fh=fopen($filepath,"w")) { + error("Cannot open for writing: $filepath"); + } + if (!fwrite($fh, $expout)) { + error("Cannot write exported questions to $filepath"); + } + fclose($fh); + + return true; + } + + function exportpostprocess() { + /// Does any post-processing that may be desired + /// Argument is a simple array of question ids that + /// have just been added. + + return true; + } + + function writequestion($question) { + /// Turns a question object into textual output in the given format + /// must be overidden + + echo "

This quiz format has not yet been completed!

"; + + return NULL; + } + } ?> -- 2.39.5