Permalink
Browse files

MDL-25492 Blackboard V6+ question import is broken.

  • Loading branch information...
1 parent d71c486 commit 7ace84e069346041ff4f47321b3f63b751f05f93 Jean-Michel Vedrine committed Aug 11, 2012
View
@@ -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;
@@ -637,6 +661,24 @@ protected function defaultquestion() {
}
/**
+ * 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
* object suitable for processing and insertion into Moodle.
@@ -902,6 +944,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.
* qformat classes that want to process $text
@@ -60,33 +60,6 @@ public function mime_type() {
}
/**
- * 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
* so fingers crossed!
Oops, something went wrong.

0 comments on commit 7ace84e

Please sign in to comment.