MDL-6367:

Backporting quiz import/export for plugins
This commit is contained in:
thepurpleblob
2007-08-09 08:43:23 +00:00
parent 9b2aa32147
commit 82cb7fe78c
2 changed files with 84 additions and 67 deletions
+64 -10
View File
@@ -1,13 +1,13 @@
<?php // $Id$
////////////////////////////////////////////////////////////////////
/// format.php - Default format class for file imports/exports. //
/// //
/// Doesn't do everything on it's own -- it needs to be extended. //
////////////////////////////////////////////////////////////////////
// Included by import.php and export.php
/**
* Base class for question import and export formats.
*
* @author Martin Dougiamas, Howard Miller, and many others.
* {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @subpackage importexport
*/
class qformat_default {
var $displayerrors = true;
@@ -112,6 +112,33 @@ class qformat_default {
$this->importerrors++;
}
/**
* Import for questiontype plugins
* Do not override.
* @param data mixed The segment of data containing the question
* @param question object processed (so far) by standard import code if appropriate
* @param extra mixed any additional format specific data that may be passed by the format
* @return object question object suitable for save_options() or false if cannot handle
*/
function try_importing_using_qtypes( $data, $question=null, $extra=null ) {
global $QTYPES;
// work out what format we are using
$formatname = substr( get_class( $this ), strlen('qformat_'));
$methodname = "import_from_$formatname";
// loop through installed questiontypes checking for
// function to handle this question
foreach ($QTYPES as $qtype) {
if (method_exists( $qtype, $methodname)) {
if ($question = $qtype->$methodname( $data, $question, $this, $extra )) {
return $question;
}
}
}
return false;
}
/**
* Perform any required pre-processing
* @return boolean success
@@ -193,7 +220,7 @@ class qformat_default {
}
}
if (!$answersvalid) {
notify( get_string('matcherror','quiz') );
notify(get_string('matcherror', 'quiz'));
continue;
}
else {
@@ -312,6 +339,7 @@ class qformat_default {
$question->correctfeedback = '';
$question->partiallycorrectfeedback = '';
$question->incorrectfeedback = '';
$question->answernumbering = 'abc';
$question->penalty = 0.1;
// this option in case the questiontypes class wants
@@ -393,6 +421,32 @@ class qformat_default {
* EXPORT FUNCTIONS
*******************/
/**
* Provide export functionality for plugin questiontypes
* Do not override
* @param name questiontype name
* @param question object data to export
* @param extra mixed any addition format specific data needed
* @return string the data to append to export or false if error (or unhandled)
*/
function try_exporting_using_qtypes( $name, $question, $extra=null ) {
global $QTYPES;
// work out the name of format in use
$formatname = substr( get_class( $this ), strlen( 'qformat_' ));
$methodname = "export_to_$formatname";
if (array_key_exists( $name, $QTYPES )) {
$qtype = $QTYPES[ $name ];
if (method_exists( $qtype, $methodname )) {
if ($data = $qtype->$methodname( $question, $this, $extra )) {
return $data;
}
}
}
return false;
}
/**
* Return the files extension appropriate for this type
* override if you don't want .txt