From 7da7bfa17dcbd47b9e12da539aa9ea088cb62028 Mon Sep 17 00:00:00 2001 From: Jonathon Fowler Date: Mon, 27 Feb 2012 15:25:40 +1000 Subject: [PATCH] MDL-28364 handle question formats that support multiple file types --- question/format.php | 14 ++++++++++++++ question/format/blackboard_six/format.php | 8 ++++++++ question/import_form.php | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/question/format.php b/question/format.php index 081b68b36a3..a9471af5fd3 100644 --- a/question/format.php +++ b/question/format.php @@ -102,6 +102,20 @@ class qformat_default { public function export_file_extension() { return '.txt'; } + + /** + * Check if the given file is capable of being imported by this plugin. + * + * Note that expensive or detailed integrity checks on the file should + * not be performed by this method. Simple file type or magic-number tests + * would be suitable. + * + * @param stored_file $file the file to check + * @return bool whether this plugin can import the file + */ + public function can_import_file($file) { + return ($file->get_mimetype() == $this->mime_type()); + } // Accessor methods diff --git a/question/format/blackboard_six/format.php b/question/format/blackboard_six/format.php index 484a31d24ff..ed9f73d77fe 100644 --- a/question/format/blackboard_six/format.php +++ b/question/format/blackboard_six/format.php @@ -39,6 +39,14 @@ class qformat_blackboard_six extends qformat_default { function provide_import() { return true; } + + public function can_import_file($file) { + $mimetypes = array( + mimeinfo('type', '.dat'), + mimeinfo('type', '.zip') + ); + return in_array($file->get_mimetype(), $mimetypes); + } //Function to check and create the needed dir to unzip file to diff --git a/question/import_form.php b/question/import_form.php index 571e8cb008a..719317d9822 100644 --- a/question/import_form.php +++ b/question/import_form.php @@ -133,7 +133,7 @@ class question_import_form extends moodleform { $qformat = new $classname(); $file = reset($files); - if ($file->get_mimetype() != $qformat->mime_type()) { + if (!$qformat->can_import_file($file)) { $a = new stdClass(); $a->actualtype = $file->get_mimetype(); $a->expectedtype = $qformat->mime_type(); -- 2.17.1