Browse files

MDL-28364 handle question formats that support multiple file types

  • Loading branch information...
1 parent 62b0af5 commit 0ead433d2059393c1efb96c40f4b795369c681b4 @jonof jonof committed Feb 27, 2012
Showing with 23 additions and 1 deletion.
  1. +14 −0 question/format.php
  2. +8 −0 question/format/blackboard_six/format.php
  3. +1 −1 question/import_form.php
View
14 question/format.php
@@ -102,6 +102,20 @@ public function mime_type() {
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
View
8 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
View
2 question/import_form.php
@@ -129,7 +129,7 @@ protected function validate_uploaded_file($data, $errors) {
$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();

0 comments on commit 0ead433

Please sign in to comment.