Skip to content

Commit

Permalink
MDL-16198
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thepurpleblob committed Aug 28, 2008
1 parent 6707109 commit 73b7b19
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,15 @@ function setContexts($contexts) {
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
Expand Down
10 changes: 10 additions & 0 deletions question/format/blackboard_six/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ function copy_file_to_course($filename) {
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;
Expand Down
3 changes: 3 additions & 0 deletions question/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@
// 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 {
print_error('uploadproblem', 'moodle', $form->choosefile);
}
} else {
// must be upload file
$realfilename = $import_form->get_importfile_realname();
if (!$importfile = $import_form->get_importfile_name()) {
print_error('uploadproblem', 'moodle');
}else {
Expand All @@ -124,6 +126,7 @@
$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));
Expand Down
10 changes: 10 additions & 0 deletions question/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,15 @@ function get_importfile_name(){
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;
}
}
}
?>

0 comments on commit 73b7b19

Please sign in to comment.