Permalink
Browse files

MDL-36243 question->questiontext and question->generalfeedback should…

… always be strings
  • Loading branch information...
Jean-Michel Vedrine
Jean-Michel Vedrine committed Oct 28, 2012
1 parent c274d5e commit 29d1e1ff761cfbdae1f6e485b3e396c06d01bf24
View
@@ -387,14 +387,6 @@ function importprocess($filename, $lesson, $pageid) {
$newpage->contents = $question->questiontext;
$newpage->contentsformat = isset($question->questionformat) ? $question->questionformat : FORMAT_HTML;
- // Sometimes, questiontext is not a simple text, but one array
- // containing both text and format, so we need to support here
- // that case with the following dirty patch. MDL-35147
- if (is_array($question->questiontext)) {
- $newpage->contents = isset($question->questiontext['text']) ? $question->questiontext['text'] : '';
- $newpage->contentsformat = isset($question->questiontext['format']) ? $question->questiontext['format'] : FORMAT_HTML;
- }
-
// set up page links
if ($pageid) {
// the new page follows on from this page
View
@@ -413,20 +413,11 @@ public function importprocess($category) {
'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 (!empty($questiontext['itemid'])) {
- $question->questiontext = file_save_draft_area_files($questiontext['itemid'],
+ if (isset($question->questiontextitemid)) {
+ $question->questiontext = file_save_draft_area_files($question->questiontextitemid,
$this->importcontext->id, 'question', 'questiontext', $question->id,
$fileoptions, $question->questiontext);
} else if (isset($question->questiontextfiles)) {
@@ -435,8 +426,8 @@ public function importprocess($category) {
$this->importcontext, 'question', 'questiontext', $question->id, $file);
}
}
- if (!empty($generalfeedback['itemid'])) {
- $question->generalfeedback = file_save_draft_area_files($generalfeedback['itemid'],
+ if (isset($question->generalfeedbackitemid)) {
+ $question->generalfeedback = file_save_draft_area_files($question->generalfeedbackitemid,
$this->importcontext->id, 'question', 'generalfeedback', $question->id,
$fileoptions, $question->generalfeedback);
} else if (isset($question->generalfeedbackfiles)) {
@@ -148,16 +148,4 @@ public function text_field($text) {
public function cleaned_text_field($text) {
return $this->text_field($this->cleaninput($text));
}
-
- /**
- * Convert the question text to plain text.
- * We need to overwrite this function because questiontext is an array.
- */
- protected function format_question_text($question) {
- global $DB;
- $formatoptions = new stdClass();
- $formatoptions->noclean = true;
- return html_to_text(format_text($question->questiontext['text'],
- $question->questiontext['format'], $formatoptions), 0, false);
- }
}
@@ -88,12 +88,16 @@ public function process_common($questiondata) {
array('#', 'BODY', 0, '#', 'TEXT', 0, '#'),
'', true, get_string('importnotext', 'qformat_blackboard_six'));
- $question->questiontext = $this->cleaned_text_field($text);
- $question->questiontextformat = FORMAT_HTML; // Needed because add_blank_combined_feedback uses it.
+ $questiontext = $this->cleaned_text_field($text);
+ $question->questiontext = $questiontext['text'];
+ $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it.
+ if (isset($questiontext['itemid'])) {
+ $question->questiontextitemid = $questiontext['itemid'];
+ }
// Put name in question object. We must ensure it is not empty and it is less than 250 chars.
$id = $this->getpath($questiondata, array('@', 'id'), '', true);
- $question->name = $this->create_default_question_name($question->questiontext['text'],
+ $question->name = $this->create_default_question_name($question->questiontext,
get_string('defaultname', 'qformat_blackboard_six' , $id));
$question->generalfeedback = '';
@@ -453,7 +457,7 @@ public function process_matching($xml, &$questions) {
$subanswercount++;
}
if ($subquestioncount < 2 || $subanswercount < 3) {
- $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext['text']));
+ $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
} else {
$questions[] = $question;
}
@@ -506,11 +506,13 @@ public function process_feedback($feedbackset, &$feedbacks) {
public function process_common($quest) {
$question = $this->defaultquestion();
$text = $quest->QUESTION_BLOCK->text;
-
- $question->questiontext = $this->cleaned_text_field($text);
- $question->questiontextformat = FORMAT_HTML; // Needed because add_blank_combined_feedback uses it.
-
- $question->name = $this->create_default_question_name($question->questiontext['text'],
+ $questiontext = $this->cleaned_text_field($text);
+ $question->questiontext = $questiontext['text'];
+ $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it.
+ if (isset($questiontext['itemid'])) {
+ $question->questiontextitemid = $questiontext['itemid'];
+ }
+ $question->name = $this->create_default_question_name($question->questiontext,
get_string('defaultname', 'qformat_blackboard_six' , $quest->id));
$question->generalfeedback = '';
$question->generalfeedbackformat = FORMAT_HTML;
@@ -863,7 +865,7 @@ public function process_matching($quest, &$questions) {
$subanswercount++;
}
if ($subquestioncount < 2 || $subanswercount < 3) {
- $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext['text']));
+ $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
} else {
$questions[] = $question;
}

0 comments on commit 29d1e1f

Please sign in to comment.