/// 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 {
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 "<hr><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
+ $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 "<p>This quiz format has not yet been completed!</p>";
+
+ return NULL;
+ }
+
}
?>