]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16198
authorthepurpleblob <thepurpleblob>
Thu, 28 Aug 2008 13:49:25 +0000 (13:49 +0000)
committerthepurpleblob <thepurpleblob>
Thu, 28 Aug 2008 13:49:25 +0000 (13:49 +0000)
Blackboard V6+ can now handle the .dat file directly as an option to the .zip file
Some changes needed to recover the original filename.

Merged from STABLE_19

question/format.php
question/format/blackboard_six/format.php
question/import.php
question/import_form.php

index 5448a6bbe51e4749ae66ea2e88e2f563698950d9..b5066ce8defecb82929cc5ac00436868d6eb0e00 100644 (file)
@@ -15,6 +15,7 @@ class qformat_default {
     var $questions = array();
     var $course = NULL;
     var $filename = '';
+    var $realfilename = '';
     var $matchgrades = 'error';
     var $catfromfile = 0;
     var $contextfromfile = 0;
@@ -87,6 +88,15 @@ class qformat_default {
     function setFilename( $filename ) {
         $this->filename = $filename;
     }
+    
+    /** 
+     * set the "real" filename
+     * (this is what the user typed, regardless of wha happened next)
+     * @param string realfilename name of file as typed by user
+     */
+    function setRealfilename( $realfilename ) {
+       $this->realfilename = $realfilename;
+    }   
 
     /**
      * set matchgrades
index 14be8c3a11bd0589221a04d3a7ac15488bdea98a..0ae5c5b02e23d84e31d2a84c53641c0ebcbdbf32 100644 (file)
@@ -152,6 +152,16 @@ class qformat_blackboard_six extends qformat_default {
     function readdata($filename) {
     /// Returns complete file with an array, one item per line
         global $CFG;
+  
+        // if the extension is .dat we just return that,
+        // if .zip we unzip the file and get the data
+        $ext = substr($this->realfilename, strpos($this->realfilename,'.'), strlen($this->realfilename)-1);      
+        if ($ext=='.dat') {
+            if (!is_readable($filename)) {
+                error("File is not readable"); 
+            }          
+            return file($filename);
+        }        
         
         $unique_code = time();
         $temp_dir = $CFG->dataroot."/temp/bbquiz_import/".$unique_code;
index 9eedd4d1d3fe5c528bcc4ba2661de901d5255ff2..67c265a58cbe7b55cb78d03ae934a898f08b7a8c 100644 (file)
@@ -92,6 +92,7 @@
         // or one from the filesarea.
         if (!empty($form->choosefile)) {
             $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}";
+            $realfilename = $form->choosefile;
             if (file_exists($importfile)) {
                 $fileisgood = true;
             } else {
             }
         } else {
             // must be upload file
+            $realfilename = $import_form->get_importfile_realname();
             if (!$importfile = $import_form->get_importfile_name()) {
                 print_error('uploadproblem', 'moodle');
             }else {
             $qformat->setContexts($contexts->having_one_edit_tab_cap('import'));
             $qformat->setCourse($COURSE);
             $qformat->setFilename($importfile);
+            $qformat->setRealfilename($realfilename);
             $qformat->setMatchgrades($form->matchgrades);
             $qformat->setCatfromfile(!empty($form->catfromfile));
             $qformat->setContextfromfile(!empty($form->contextfromfile));
index f20dcd4897c3b0bc439c7c6517ce5373b51e8f7c..309e688da704645c11ced2f6c366541a9aa71853 100644 (file)
@@ -83,5 +83,15 @@ class question_import_form extends moodleform {
             return  NULL;
         }
     }
+    
+    function get_importfile_name(){
+        if ($this->is_submitted() and $this->is_validated()) {
+            // return the temporary filename to process
+            // TODO change this to use the files API properly.
+            return $_FILES['newfile']['name'];
+        }else{
+            return  NULL;
+        }
+    }
 }
 ?>