📄 format.php
字号:
<?php // $Id: format.php,v 1.14.2.4 2009/03/23 09:47:45 mudrd8mz Exp $/////////////////////////////////////////////////////////////////////////////// Blackboard 6.x Format////// This Moodle class provides all functions necessary to import and export//////////////////////////////////////////////////////////////////////////////////// Based on default.php, included by ../import.php/** * @package questionbank * @subpackage importexport */require_once ("$CFG->libdir/xmlize.php");class qformat_blackboard_6 extends qformat_default { function provide_import() { return true; } //Function to check and create the needed dir to unzip file to function check_and_create_import_dir($unique_code) { global $CFG; $status = $this->check_dir_exists($CFG->dataroot."/temp",true); if ($status) { $status = $this->check_dir_exists($CFG->dataroot."/temp/bbquiz_import",true); } if ($status) { $status = $this->check_dir_exists($CFG->dataroot."/temp/bbquiz_import/".$unique_code,true); } return $status; } function clean_temp_dir($dir='') { // for now we will just say everything happened okay note // that a mess may be piling up in $CFG->dataroot/temp/bbquiz_import // TODO return true at top of the function renders all the following code useless return true; if ($dir == '') { $dir = $this->temp_dir; } $slash = "/"; // Create arrays to store files and directories $dir_files = array(); $dir_subdirs = array(); // Make sure we can delete it chmod($dir, 0777); if ((($handle = opendir($dir))) == FALSE) { // The directory could not be opened return false; } // Loop through all directory entries, and construct two temporary arrays containing files and sub directories while(false !== ($entry = readdir($handle))) { if (is_dir($dir. $slash .$entry) && $entry != ".." && $entry != ".") { $dir_subdirs[] = $dir. $slash .$entry; } else if ($entry != ".." && $entry != ".") { $dir_files[] = $dir. $slash .$entry; } } // Delete all files in the curent directory return false and halt if a file cannot be removed for($i=0; $i<count($dir_files); $i++) { chmod($dir_files[$i], 0777); if (((unlink($dir_files[$i]))) == FALSE) { return false; } } // Empty sub directories and then remove the directory for($i=0; $i<count($dir_subdirs); $i++) { chmod($dir_subdirs[$i], 0777); if ($this->clean_temp_dir($dir_subdirs[$i]) == FALSE) { return false; } else { if (rmdir($dir_subdirs[$i]) == FALSE) { return false; } } } // Close directory closedir($handle); if (rmdir($this->temp_dir) == FALSE) { return false; } // Success, every thing is gone return true return true; } //Function to check if a directory exists and, optionally, create it function check_dir_exists($dir,$create=false) { global $CFG; $status = true; if(!is_dir($dir)) { if (!$create) { $status = false; } else { umask(0000); $status = mkdir ($dir,$CFG->directorypermissions); } } return $status; } function importpostprocess() { /// Does any post-processing that may be desired /// Argument is a simple array of question ids that /// have just been added. // need to clean up temporary directory return $this->clean_temp_dir(); } function copy_file_to_course($filename) { global $CFG, $COURSE; $filename = str_replace('\\','/',$filename); $fullpath = $this->temp_dir.'/res00001/'.$filename; $basename = basename($filename); $copy_to = $CFG->dataroot.'/'.$COURSE->id.'/bb_import'; if ($this->check_dir_exists($copy_to,true)) { if(is_readable($fullpath)) { $copy_to.= '/'.$basename; if (!copy($fullpath, $copy_to)) { return false; } else { return $copy_to; } } } else { return false; } } 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; $this->temp_dir = $temp_dir; if ($this->check_and_create_import_dir($unique_code)) { if(is_readable($filename)) { if (!copy($filename, "$temp_dir/bboard.zip")) { error("Could not copy backup file"); } if(unzip_file("$temp_dir/bboard.zip", '', false)) { // assuming that the information is in res0001.dat // after looking at 6 examples this was always the case $q_file = "$temp_dir/res00001.dat"; if (is_file($q_file)) { if (is_readable($q_file)) { $filearray = file($q_file); /// Check for Macintosh OS line returns (ie file on one line), and fix if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { return explode("\r", $filearray[0]); } else { return $filearray; } } } else { error("Could not find question data file in zip"); } } else { print "filename: $filename<br />tempdir: $temp_dir <br />"; error("Could not unzip file."); } } else { error ("Could not read uploaded file"); } } else { error("Could not create temporary directory"); } } function save_question_options($question) { return true; } function readquestions ($lines) { /// Parses an array of lines into an array of questions, /// where each item is a question object as defined by /// readquestion(). $text = implode($lines, " "); $xml = xmlize($text, 0); $raw_questions = $xml['questestinterop']['#']['assessment'][0]['#']['section'][0]['#']['item']; $questions = array(); foreach($raw_questions as $quest) { $question = $this->create_raw_question($quest); switch($question->qtype) { case "Matching": $this->process_matching($question, $questions); break; case "Multiple Choice": $this->process_mc($question, $questions); break; case "Essay": $this->process_essay($question, $questions); break; case "Multiple Answer": $this->process_ma($question, $questions); break; case "True/False": $this->process_tf($question, $questions); break; case 'Fill in the Blank': $this->process_fblank($question, $questions); break; case 'Short Response': $this->process_essay($question, $questions); break; default: print "Unknown or unhandled question type: \"$question->qtype\"<br />"; break; } } return $questions; }// creates a cleaner object to deal with for processing into moodle// the object created is NOT a moodle question objectfunction create_raw_question($quest) { $question = new StdClass; $question->qtype = $quest['#']['itemmetadata'][0]['#']['bbmd_questiontype'][0]['#']; $question->id = $quest['#']['itemmetadata'][0]['#']['bbmd_asi_object_id'][0]['#']; $presentation->blocks = $quest['#']['presentation'][0]['#']['flow'][0]['#']['flow']; foreach($presentation->blocks as $pblock) { $block = NULL; $block->type = $pblock['@']['class']; switch($block->type) { case 'QUESTION_BLOCK': $sub_blocks = $pblock['#']['flow']; foreach($sub_blocks as $sblock) { //echo "Calling process_block from line 263<br>"; $this->process_block($sblock, $block); } break; case 'RESPONSE_BLOCK': $choices = NULL; switch($question->qtype) { case 'Matching': $bb_subquestions = $pblock['#']['flow']; $sub_questions = array(); foreach($bb_subquestions as $bb_subquestion) { $sub_question = NULL; $sub_question->ident = $bb_subquestion['#']['response_lid'][0]['@']['ident']; $this->process_block($bb_subquestion['#']['flow'][0], $sub_question); $bb_choices = $bb_subquestion['#']['response_lid'][0]['#']['render_choice'][0]['#']['flow_label'][0]['#']['response_label']; $choices = array(); $this->process_choices($bb_choices, $choices); $sub_question->choices = $choices; if (!isset($block->subquestions)) { $block->subquestions = array(); } $block->subquestions[] = $sub_question; } break; case 'Multiple Answer': $bb_choices = $pblock['#']['response_lid'][0]['#']['render_choice'][0]['#']['flow_label']; $choices = array(); $this->process_choices($bb_choices, $choices); $block->choices = $choices; break; case 'Essay':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -