Skip to content

Commit

Permalink
MDL-25492 Blackboard V6+ question import is broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Michel Vedrine committed Aug 24, 2012
1 parent bac15e5 commit cc0188c
Show file tree
Hide file tree
Showing 14 changed files with 3,593 additions and 981 deletions.
68 changes: 66 additions & 2 deletions question/format.php
Expand Up @@ -408,20 +408,44 @@ public function importprocess($category) {
$question->timecreated = time();
$question->modifiedby = $USER->id;
$question->timemodified = time();
$fileoptions = array(
'subdirs' => false,
'maxfiles' => -1,
'maxbytes' => 0,
);
if (is_array($question->questiontext)) {
// Importing images from draftfile.
$questiontext = $question->questiontext;
$question->questiontext = $questiontext['text'];
}
if (is_array($question->generalfeedback)) {
$generalfeedback = $question->generalfeedback;
$question->generalfeedback = $generalfeedback['text'];
}

$question->id = $DB->insert_record('question', $question);
if (isset($question->questiontextfiles)) {

if (!empty($questiontext['itemid'])) {
$question->questiontext = file_save_draft_area_files($questiontext['itemid'],
$this->importcontext->id, 'question', 'questiontext', $question->id,
$fileoptions, $question->questiontext);
} else if (isset($question->questiontextfiles)) {
foreach ($question->questiontextfiles as $file) {
question_bank::get_qtype($question->qtype)->import_file(
$this->importcontext, 'question', 'questiontext', $question->id, $file);
}
}
if (isset($question->generalfeedbackfiles)) {
if (!empty($generalfeedback['itemid'])) {
$question->generalfeedback = file_save_draft_area_files($generalfeedback['itemid'],
$this->importcontext->id, 'question', 'generalfeedback', $question->id,
$fileoptions, $question->generalfeedback);
} else if (isset($question->generalfeedbackfiles)) {
foreach ($question->generalfeedbackfiles as $file) {
question_bank::get_qtype($question->qtype)->import_file(
$this->importcontext, 'question', 'generalfeedback', $question->id, $file);
}
}
$DB->update_record('question', $question);

$this->questionids[] = $question->id;

Expand Down Expand Up @@ -636,6 +660,24 @@ protected function defaultquestion() {
return $question;
}

/**
* Add a blank combined feedback to a question object.
* @param object question
* @return object question
*/
protected function add_blank_combined_feedback($question) {
$question->correctfeedback['text'] = '';
$question->correctfeedback['format'] = $question->questiontextformat;
$question->correctfeedback['files'] = array();
$question->partiallycorrectfeedback['text'] = '';
$question->partiallycorrectfeedback['format'] = $question->questiontextformat;
$question->partiallycorrectfeedback['files'] = array();
$question->incorrectfeedback['text'] = '';
$question->incorrectfeedback['format'] = $question->questiontextformat;
$question->incorrectfeedback['files'] = array();
return $question;
}

/**
* Given the data known to define a question in
* this format, this function converts it into a question
Expand Down Expand Up @@ -901,6 +943,28 @@ protected function format_question_text($question) {

class qformat_based_on_xml extends qformat_default {

/**
* A lot of imported files contain unwanted entities.
* This method tries to clean up all known problems.
* @param string str string to correct
* @return string the corrected string
*/
public function cleaninput($str) {

$html_code_list = array(
"'" => "'",
"’" => "'",
"“" => "\"",
"”" => "\"",
"–" => "-",
"—" => "-",
);
$str = strtr($str, $html_code_list);
// Use textlib entities_to_utf8 function to convert only numerical entities.
$str = textlib::entities_to_utf8($str, false);
return $str;
}

/**
* Return the array moodle is expecting
* for an HTML text. No processing is done on $text.
Expand Down
27 changes: 0 additions & 27 deletions question/format/blackboard/format.php
Expand Up @@ -59,33 +59,6 @@ public function mime_type() {
return mimeinfo('type', '.dat');
}

/**
* Some softwares put entities in exported files.
* This method try to clean up known problems.
* @param string str string to correct
* @return string the corrected string
*/
public function cleaninput($str) {
if (!$this->ishtml) {
return $str;
}
$html_code_list = array(
"'" => "'",
"’" => "'",
"[" => "[",
"“" => "\"",
"”" => "\"",
"]" => "]",
"'" => "'",
"–" => "-",
"—" => "-",
);
$str = strtr($str, $html_code_list);
// Use textlib entities_to_utf8 function to convert only numerical entities.
$str = textlib::entities_to_utf8($str, false);
return $str;
}

/**
* Parse the array of lines into an array of questions
* this *could* burn memory - but it won't happen that much
Expand Down

0 comments on commit cc0188c

Please sign in to comment.