Merge branch 'MDL-35103' of git://github.com/jmvedrine/moodle

This commit is contained in:
Dan Poltawski 2014-02-18 13:39:08 +08:00
commit d08598bc8b
6 changed files with 76 additions and 46 deletions

View File

@ -29,6 +29,13 @@ require_once($CFG->dirroot . '/question/format/blackboard_six/formatbase.php');
require_once($CFG->dirroot . '/question/format/blackboard_six/formatqti.php');
require_once($CFG->dirroot . '/question/format/blackboard_six/formatpool.php');
/**
* Class to represent a Blackboard file.
*
* @package qformat_blackboard_six
* @copyright 2005 Michael Penney
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_blackboard_six_file {
/** @var int type of file being imported, one of the constants FILETYPE_QTI or FILETYPE_POOL. */
public $filetype;
@ -38,12 +45,25 @@ class qformat_blackboard_six_file {
public $filebase = '';
}
/**
* Blackboard Six QTI file importer class.
*
* @package qformat_blackboard_six
* @copyright 2005 Michael Penney
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_blackboard_six extends qformat_blackboard_six_base {
/** @var int Blackboard assessment qti files were always imported by the blackboard_six plugin. */
const FILETYPE_QTI = 1;
/** @var int Blackboard question pool files were previously handled by the blackboard plugin. */
const FILETYPE_POOL = 2;
/**
* Return the content of a file given by its path in the tempdir directory.
*
* @param string $path path to the file inside tempdir
* @return mixed contents array or false on failure
*/
public function get_filecontent($path) {
$fullpath = $this->tempdir . '/' . $path;
if (is_file($fullpath) && is_readable($fullpath)) {
@ -56,7 +76,8 @@ class qformat_blackboard_six extends qformat_blackboard_six_base {
* Return content of all files containing questions,
* as an array one element for each file found,
* For each file, the corresponding element is an array of lines.
* @param string filename name of file
*
* @param string $filename name of file
* @return mixed contents array or false on failure
*/
public function readdata($filename) {
@ -163,6 +184,7 @@ class qformat_blackboard_six extends qformat_blackboard_six_base {
* Each object is the content of a .dat questions file.
* This *could* burn memory - but it won't happen that much
* so fingers crossed!
*
* @param array $lines array of qformat_blackboard_six_file objects for each input file.
* @return array (of objects) question objects.
*/

View File

@ -27,13 +27,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Base class question import format for zip files with images
*
* @package qformat_blackboard_six
* @copyright 2012 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_blackboard_six_base extends qformat_based_on_xml {
/** @var string path to path to root of image tree in unzipped archive. */
public $filebase = '';
/** @var string path to the temporary directory. */
public $tempdir = '';
/**
* This plugin provide import
* @return bool true
@ -84,9 +87,9 @@ class qformat_blackboard_six_base extends qformat_based_on_xml {
/**
* Store an image file in a draft filearea
* @param array $text, if itemid element don't exists it will be created
* @param string tempdir path to root of image tree
* @param string filepathinsidetempdir path to image in the tree
* @param string filename image's name
* @param string $tempdir path to root of image tree
* @param string $filepathinsidetempdir path to image in the tree
* @param string $filename image's name
* @return string new name of the image as it was stored
*/
protected function store_file_for_text_field(&$text, $tempdir, $filepathinsidetempdir, $filename) {
@ -116,7 +119,7 @@ class qformat_blackboard_six_base extends qformat_based_on_xml {
* store all images in a draft filearea,
* and return an array with all urls in text recoded,
* format set to FORMAT_HTML, and itemid set to filearea itemid
* @param string text text to parse and recode
* @param string $text text to parse and recode
* @return array with keys text, format, itemid.
*/
public function text_field($text) {
@ -143,7 +146,7 @@ class qformat_blackboard_six_base extends qformat_based_on_xml {
/**
* Same as text_field but text is cleaned.
* @param string text text to parse and recode
* @param string $text text to parse and recode
* @return array with keys text, format, itemid.
*/
public function cleaned_text_field($text) {

View File

@ -27,22 +27,26 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/xmlize.php');
/**
* Blackboard pool question importer.
* Blackboard pool question importer class.
*
* @package qformat_blackboard_six
* @copyright 2003 Scott Elliott
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
// Is the current question's question text escaped HTML (true for most if not all Blackboard files).
/**
* @var bool Is the current question's question text escaped HTML
* (true for most if not all Blackboard files).
*/
public $ishtml = true;
/**
* Parse the xml document into an array of questions
* this *could* burn memory - but it won't happen that much
*
* This *could* burn memory - but it won't happen that much
* so fingers crossed!
* @param array of lines from the input file.
* @param stdClass $context
*
* @param array $text array of lines from the input file.
* @return array (of objects) questions objects.
*/
protected function readquestions($text) {
@ -72,6 +76,7 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Do question import processing common to every qtype.
*
* @param array $questiondata the xml tree related to the current question
* @return object initialized question object.
*/
@ -128,8 +133,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process Essay Questions
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_essay($xml, &$questions) {
@ -149,8 +154,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
$question->answer = '';
$answer = $this->getpath($thisquestion,
array('#', 'ANSWER', 0, '#', 'TEXT', 0, '#'), '', true);
$question->graderinfo = $this->cleaned_text_field($answer);
$question->responsetemplate = $this->text_field('');
$question->graderinfo = $this->cleaned_text_field($answer);
$question->responsetemplate = $this->text_field('');
$question->feedback = '';
$question->responseformat = 'editor';
$question->responserequired = 1;
@ -165,8 +170,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process True / False Questions
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_tf($xml, &$questions) {
@ -214,8 +219,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process Multiple Choice Questions with single answer
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_mc($xml, &$questions) {
@ -250,7 +255,7 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
foreach ($choices as $choice) {
$choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true);
// Put this choice in the question object.
$question->answer[] = $this->cleaned_text_field($choicetext);
$question->answer[] = $this->cleaned_text_field($choicetext);
$choiceid = $this->getpath($choice, array('@', 'id'), '', true);
// If choice is the right answer, give 100% mark, otherwise give 0%.
@ -260,7 +265,7 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
$question->fraction[] = 0;
}
// There is never feedback specific to each choice.
$question->feedback[] = $this->text_field('');
$question->feedback[] = $this->text_field('');
}
$questions[] = $question;
}
@ -268,8 +273,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process Multiple Choice Questions With Multiple Answers
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_ma($xml, &$questions) {
if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLEANSWER'), false, false)) {
@ -307,12 +312,12 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
'', true);
}
}
$fraction = 1/count($correctanswerids);
$fraction = 1 / count($correctanswerids);
foreach ($choices as $choice) {
$choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true);
// Put this choice in the question object.
$question->answer[] = $this->cleaned_text_field($choicetext);
$question->answer[] = $this->cleaned_text_field($choicetext);
$choiceid = $this->getpath($choice, array('@', 'id'), '', true);
@ -324,7 +329,7 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
$question->fraction[] = 0;
}
// There is never feedback specific to each choice.
$question->feedback[] = $this->text_field('');
$question->feedback[] = $this->text_field('');
}
$questions[] = $question;
}
@ -332,8 +337,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process Fill in the Blank Questions
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_fib($xml, &$questions) {
if ($this->getpath($xml, array('POOL', '#', 'QUESTION_FILLINBLANK'), false, false)) {
@ -373,8 +378,8 @@ class qformat_blackboard_six_pool extends qformat_blackboard_six_base {
/**
* Process Matching Questions
* @param array xml the xml tree
* @param array questions the questions already parsed
* @param array $xml the xml tree
* @param array $questions the questions already parsed
*/
public function process_matching($xml, &$questions) {
if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MATCH'), false, false)) {

View File

@ -37,8 +37,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse the xml document into an array of questions
* this *could* burn memory - but it won't happen that much
* so fingers crossed!
* @param array of lines from the input file.
* @param stdClass $context
* @param array $text array of lines from the input file.
* @return array (of objects) questions objects.
*/
protected function readquestions($text) {
@ -207,7 +206,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
$answerset = array();
foreach ($matchinganswerset as $answer) {
$bbanswer = new stdClass;
$bbanswer->text = $this->getpath($answer,
$bbanswer->text = $this->getpath($answer,
array('#', 'flow', 0, '#', 'material', 0, '#', 'mat_extension',
0, '#', 'mat_formattedtext', 0, '#'),
false, false);
@ -252,6 +251,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Helper function to process an XML block into an object.
* Can call himself recursively if necessary to parse this branch of the XML tree.
* @param array $curblock XML block to parse
* @param object $block block already parsed so far
* @return object $block parsed
*/
public function process_block($curblock, $block) {
@ -529,7 +529,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse a truefalse rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done
*/
protected function process_tf($quest, &$questions) {
$question = $this->process_common($quest);
@ -570,7 +570,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse a fillintheblank rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done.
*/
protected function process_fblank($quest, &$questions) {
$question = $this->process_common($quest);
@ -636,7 +636,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse a multichoice single answer rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done.
*/
protected function process_mc($quest, &$questions) {
$question = $this->process_common($quest);
@ -707,7 +707,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse a multichoice multianswer rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done.
*/
public function process_ma($quest, &$questions) {
$question = $this->process_common($quest);
@ -732,7 +732,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
}
$correctanswercount = count($correctanswers);
$fraction = 1/$correctanswercount;
$fraction = 1 / $correctanswercount;
$choiceset = $quest->RESPONSE_BLOCK->choices;
$i = 0;
foreach ($choiceset as $choice) {
@ -757,7 +757,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse an essay rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done.
*/
public function process_essay($quest, &$questions) {
@ -782,9 +782,9 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
$question->responsefieldlines = 15;
$question->attachments = 0;
$question->attachmentsrequired = 0;
$question->responsetemplate = $this->text_field('');
$question->responsetemplate = $this->text_field('');
$questions[]=$question;
$questions[] = $question;
}
/**
@ -792,7 +792,7 @@ class qformat_blackboard_six_qti extends qformat_blackboard_six_base {
* Parse a matching rawquestion and add the result
* to the array of questions already parsed.
* @param object $quest rawquestion
* @param $questions array of Moodle questions already done.
* @param array $questions array of Moodle questions already done.
*/
public function process_matching($quest, &$questions) {

View File

@ -44,7 +44,7 @@ class qformat_blackboard_six_pool_test extends question_testcase {
$xmlfile = new qformat_blackboard_six_file();
$xmlfile->filetype = 2;
$xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_pool.dat');
return array(0=>$xmlfile);
return array(0 => $xmlfile);
}
public function test_import_match() {

View File

@ -44,7 +44,7 @@ class qformat_blackboard_six_qti_test extends question_testcase {
$xmlfile = new qformat_blackboard_six_file();
$xmlfile->filetype = 1;
$xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_qti.dat');
return array(0=>$xmlfile);
return array(0 => $xmlfile);
}
public function test_import_match() {
$xml = $this->make_test_xml();