diff --git a/lib/questionlib.php b/lib/questionlib.php index 2a21f7bd9f7..2eb91c7faf3 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1287,4 +1287,45 @@ function question_used($id) { return $quizlist; } + +/** + * Get list of available import or export formats + * @param string $type 'import' if import list, otherwise export list assumed + * @return array sorted list of import/export formats available +**/ +function get_import_export_formats( $type ) { + + global $CFG; + $fileformats = get_list_of_plugins("mod/quiz/format"); + + $fileformatname=array(); + require_once( "format.php" ); + foreach ($fileformats as $key => $fileformat) { + $format_file = $CFG->dirroot . "/question/format/$fileformat/format.php"; + if (file_exists( $format_file ) ) { + require_once( $format_file ); + } + else { + continue; + } + $classname = "quiz_format_$fileformat"; + $format_class = new $classname(); + if ($type=='import') { + $provided = $format_class->provide_import(); + } + else { + $provided = $format_class->provide_export(); + } + if ($provided) { + $formatname = get_string($fileformat, 'quiz'); + if ($formatname == "[[$fileformat]]") { + $formatname = $fileformat; // Just use the raw folder name + } + $fileformatnames[$fileformat] = $formatname; + } + } + natcasesort($fileformatnames); + + return $fileformatnames; +} ?>