Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… always be strings
  • Loading branch information...
commit f62c457ece558d8cbaa5e29be60d7cf6105dca8a 1 parent 5fa7d72
Jean-Michel Vedrine authored
8  mod/lesson/format.php
@@ -387,14 +387,6 @@ function importprocess($filename, $lesson, $pageid) {
387 387
                     $newpage->contents = $question->questiontext;
388 388
                     $newpage->contentsformat = isset($question->questionformat) ? $question->questionformat : FORMAT_HTML;
389 389
 
390  
-                    // Sometimes, questiontext is not a simple text, but one array
391  
-                    // containing both text and format, so we need to support here
392  
-                    // that case with the following dirty patch. MDL-35147
393  
-                    if (is_array($question->questiontext)) {
394  
-                        $newpage->contents = isset($question->questiontext['text']) ? $question->questiontext['text'] : '';
395  
-                        $newpage->contentsformat = isset($question->questiontext['format']) ? $question->questiontext['format'] : FORMAT_HTML;
396  
-                    }
397  
-
398 390
                     // set up page links
399 391
                     if ($pageid) {
400 392
                         // the new page follows on from this page
17  question/format.php
@@ -413,20 +413,11 @@ public function importprocess($category) {
413 413
                     'maxfiles' => -1,
414 414
                     'maxbytes' => 0,
415 415
                 );
416  
-            if (is_array($question->questiontext)) {
417  
-                // Importing images from draftfile.
418  
-                $questiontext = $question->questiontext;
419  
-                $question->questiontext = $questiontext['text'];
420  
-            }
421  
-            if (is_array($question->generalfeedback)) {
422  
-                $generalfeedback = $question->generalfeedback;
423  
-                $question->generalfeedback = $generalfeedback['text'];
424  
-            }
425 416
 
426 417
             $question->id = $DB->insert_record('question', $question);
427 418
 
428  
-            if (!empty($questiontext['itemid'])) {
429  
-                $question->questiontext = file_save_draft_area_files($questiontext['itemid'],
  419
+            if (isset($question->questiontextitemid)) {
  420
+                $question->questiontext = file_save_draft_area_files($question->questiontextitemid,
430 421
                         $this->importcontext->id, 'question', 'questiontext', $question->id,
431 422
                         $fileoptions, $question->questiontext);
432 423
             } else if (isset($question->questiontextfiles)) {
@@ -435,8 +426,8 @@ public function importprocess($category) {
435 426
                             $this->importcontext, 'question', 'questiontext', $question->id, $file);
436 427
                 }
437 428
             }
438  
-            if (!empty($generalfeedback['itemid'])) {
439  
-                $question->generalfeedback = file_save_draft_area_files($generalfeedback['itemid'],
  429
+            if (isset($question->generalfeedbackitemid)) {
  430
+                $question->generalfeedback = file_save_draft_area_files($question->generalfeedbackitemid,
440 431
                         $this->importcontext->id, 'question', 'generalfeedback', $question->id,
441 432
                         $fileoptions, $question->generalfeedback);
442 433
             } else if (isset($question->generalfeedbackfiles)) {
12  question/format/blackboard_six/formatbase.php
@@ -148,16 +148,4 @@ public function text_field($text) {
148 148
     public function cleaned_text_field($text) {
149 149
         return $this->text_field($this->cleaninput($text));
150 150
     }
151  
-
152  
-    /**
153  
-     * Convert the question text to plain text.
154  
-     * We need to overwrite this function because questiontext is an array.
155  
-     */
156  
-    protected function format_question_text($question) {
157  
-        global $DB;
158  
-        $formatoptions = new stdClass();
159  
-        $formatoptions->noclean = true;
160  
-        return html_to_text(format_text($question->questiontext['text'],
161  
-                $question->questiontext['format'], $formatoptions), 0, false);
162  
-    }
163 151
 }
12  question/format/blackboard_six/formatpool.php
@@ -88,12 +88,16 @@ public function process_common($questiondata) {
88 88
                 array('#', 'BODY', 0, '#', 'TEXT', 0, '#'),
89 89
                 '', true, get_string('importnotext', 'qformat_blackboard_six'));
90 90
 
91  
-        $question->questiontext = $this->cleaned_text_field($text);
92  
-        $question->questiontextformat = FORMAT_HTML; // Needed because add_blank_combined_feedback uses it.
  91
+        $questiontext = $this->cleaned_text_field($text);
  92
+        $question->questiontext = $questiontext['text'];
  93
+        $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it.
  94
+        if (isset($questiontext['itemid'])) {
  95
+            $question->questiontextitemid = $questiontext['itemid'];
  96
+        }
93 97
 
94 98
         // Put name in question object. We must ensure it is not empty and it is less than 250 chars.
95 99
         $id = $this->getpath($questiondata, array('@', 'id'), '',  true);
96  
-        $question->name = $this->create_default_question_name($question->questiontext['text'],
  100
+        $question->name = $this->create_default_question_name($question->questiontext,
97 101
                 get_string('defaultname', 'qformat_blackboard_six' , $id));
98 102
 
99 103
         $question->generalfeedback = '';
@@ -453,7 +457,7 @@ public function process_matching($xml, &$questions) {
453 457
                 $subanswercount++;
454 458
             }
455 459
             if ($subquestioncount < 2 || $subanswercount < 3) {
456  
-                    $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext['text']));
  460
+                    $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
457 461
             } else {
458 462
                 $questions[] = $question;
459 463
             }
14  question/format/blackboard_six/formatqti.php
@@ -506,11 +506,13 @@ public function process_feedback($feedbackset, &$feedbacks) {
506 506
     public function process_common($quest) {
507 507
         $question = $this->defaultquestion();
508 508
         $text = $quest->QUESTION_BLOCK->text;
509  
-
510  
-        $question->questiontext = $this->cleaned_text_field($text);
511  
-        $question->questiontextformat = FORMAT_HTML; // Needed because add_blank_combined_feedback uses it.
512  
-
513  
-        $question->name = $this->create_default_question_name($question->questiontext['text'],
  509
+        $questiontext = $this->cleaned_text_field($text);
  510
+        $question->questiontext = $questiontext['text'];
  511
+        $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it.
  512
+        if (isset($questiontext['itemid'])) {
  513
+            $question->questiontextitemid = $questiontext['itemid'];
  514
+        }
  515
+        $question->name = $this->create_default_question_name($question->questiontext,
514 516
                 get_string('defaultname', 'qformat_blackboard_six' , $quest->id));
515 517
         $question->generalfeedback = '';
516 518
         $question->generalfeedbackformat = FORMAT_HTML;
@@ -863,7 +865,7 @@ public function process_matching($quest, &$questions) {
863 865
             $subanswercount++;
864 866
         }
865 867
         if ($subquestioncount < 2 || $subanswercount < 3) {
866  
-                $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext['text']));
  868
+                $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
867 869
         } else {
868 870
             $questions[] = $question;
869 871
         }
30  question/format/blackboard_six/tests/blackboardformatpool_test.php
@@ -58,10 +58,7 @@ public function test_import_match() {
58 58
         $expectedq = new stdClass();
59 59
         $expectedq->qtype = 'match';
60 60
         $expectedq->name = 'Classify the animals.';
61  
-        $expectedq->questiontext = array(
62  
-                'text' => '<i>Classify the animals.</i>',
63  
-                'format' => FORMAT_HTML,
64  
-            );
  61
+        $expectedq->questiontext = '<i>Classify the animals.</i>';
65 62
         $expectedq->questiontextformat = FORMAT_HTML;
66 63
         $expectedq->correctfeedback = array('text' => '',
67 64
                 'format' => FORMAT_HTML);
@@ -98,10 +95,7 @@ public function test_import_multichoice_single() {
98 95
         $expectedq->qtype = 'multichoice';
99 96
         $expectedq->single = 1;
100 97
         $expectedq->name = 'What\'s between orange and green in the spectrum?';
101  
-        $expectedq->questiontext = array(
102  
-                'text' =>'<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>',
103  
-                'format' => FORMAT_HTML,
104  
-            );
  98
+        $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
105 99
         $expectedq->questiontextformat = FORMAT_HTML;
106 100
         $expectedq->correctfeedback = array('text' => 'You gave the right answer.',
107 101
                 'format' => FORMAT_HTML);
@@ -161,10 +155,7 @@ public function test_import_multichoice_multi() {
161 155
         $expectedq->qtype = 'multichoice';
162 156
         $expectedq->single = 0;
163 157
         $expectedq->name = 'What\'s between orange and green in the spectrum?';
164  
-        $expectedq->questiontext = array(
165  
-                'text' => '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>',
166  
-                'format' => FORMAT_HTML,
167  
-            );
  158
+        $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
168 159
         $expectedq->questiontextformat = FORMAT_HTML;
169 160
         $expectedq->correctfeedback = array(
170 161
                 'text' => 'You gave the right answer.',
@@ -237,10 +228,7 @@ public function test_import_truefalse() {
237 228
         $expectedq = new stdClass();
238 229
         $expectedq->qtype = 'truefalse';
239 230
         $expectedq->name = '42 is the Absolute Answer to everything.';
240  
-        $expectedq->questiontext = array(
241  
-                'text' => '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>',
242  
-                'format' => FORMAT_HTML,
243  
-            );
  231
+        $expectedq->questiontext = '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>';
244 232
         $expectedq->questiontextformat = FORMAT_HTML;
245 233
         $expectedq->generalfeedback = '';
246 234
         $expectedq->generalfeedbackformat = FORMAT_HTML;
@@ -270,10 +258,7 @@ public function test_import_fill_in_the_blank() {
270 258
         $expectedq = new stdClass();
271 259
         $expectedq->qtype = 'shortanswer';
272 260
         $expectedq->name = 'Name an amphibian: __________.';
273  
-        $expectedq->questiontext = array(
274  
-                'text' => '<span style="font-size:12pt">Name an amphibian: __________.</span>',
275  
-                'format' => FORMAT_HTML,
276  
-            );
  261
+        $expectedq->questiontext = '<span style="font-size:12pt">Name an amphibian: __________.</span>';
277 262
         $expectedq->questiontextformat = FORMAT_HTML;
278 263
         $expectedq->generalfeedback = '';
279 264
         $expectedq->generalfeedbackformat = FORMAT_HTML;
@@ -308,10 +293,7 @@ public function test_import_essay() {
308 293
         $expectedq = new stdClass();
309 294
         $expectedq->qtype = 'essay';
310 295
         $expectedq->name = 'How are you?';
311  
-        $expectedq->questiontext = array(
312  
-                'text' => 'How are you?',
313  
-                'format' => FORMAT_HTML,
314  
-            );
  296
+        $expectedq->questiontext = 'How are you?';
315 297
         $expectedq->questiontextformat = FORMAT_HTML;
316 298
         $expectedq->generalfeedback = '';
317 299
         $expectedq->generalfeedbackformat = FORMAT_HTML;
30  question/format/blackboard_six/tests/blackboardsixformatqti_test.php
@@ -55,10 +55,7 @@ public function test_import_match() {
55 55
         $expectedq = new stdClass();
56 56
         $expectedq->qtype = 'match';
57 57
         $expectedq->name = 'Classify the animals.';
58  
-        $expectedq->questiontext = array(
59  
-                'text' => 'Classify the animals.',
60  
-                'format' => FORMAT_HTML,
61  
-            );
  58
+        $expectedq->questiontext = 'Classify the animals.';
62 59
         $expectedq->questiontextformat = FORMAT_HTML;
63 60
         $expectedq->correctfeedback = array('text' => '',
64 61
                 'format' => FORMAT_HTML, 'files' => array());
@@ -94,10 +91,7 @@ public function test_import_multichoice_single() {
94 91
         $expectedq->qtype = 'multichoice';
95 92
         $expectedq->single = 1;
96 93
         $expectedq->name = 'What\'s between orange and green in the spectrum?';
97  
-        $expectedq->questiontext = array(
98  
-                'text' => '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>',
99  
-                'format' => FORMAT_HTML,
100  
-            );
  94
+        $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
101 95
         $expectedq->questiontextformat = FORMAT_HTML;
102 96
         $expectedq->correctfeedback = array('text' => '',
103 97
                 'format' => FORMAT_HTML, 'files' => array());
@@ -157,10 +151,7 @@ public function test_import_multichoice_multi() {
157 151
         $expectedq->qtype = 'multichoice';
158 152
         $expectedq->single = 0;
159 153
         $expectedq->name = 'What\'s between orange and green in the spectrum?';
160  
-        $expectedq->questiontext = array(
161  
-                'text' => '<i>What\'s between orange and green in the spectrum?</i>',
162  
-                'format' => FORMAT_HTML,
163  
-            );
  154
+        $expectedq->questiontext = '<i>What\'s between orange and green in the spectrum?</i>';
164 155
         $expectedq->questiontextformat = FORMAT_HTML;
165 156
         $expectedq->correctfeedback = array(
166 157
                 'text' => '',
@@ -236,10 +227,7 @@ public function test_import_truefalse() {
236 227
         $expectedq = new stdClass();
237 228
         $expectedq->qtype = 'truefalse';
238 229
         $expectedq->name = '42 is the Absolute Answer to everything.';
239  
-        $expectedq->questiontext = array(
240  
-                'text' => '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>',
241  
-                'format' => FORMAT_HTML,
242  
-            );
  230
+        $expectedq->questiontext = '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>';
243 231
         $expectedq->questiontextformat = FORMAT_HTML;
244 232
         $expectedq->generalfeedback = '';
245 233
         $expectedq->generalfeedbackformat = FORMAT_HTML;
@@ -270,10 +258,7 @@ public function test_import_fill_in_the_blank() {
270 258
         $expectedq = new stdClass();
271 259
         $expectedq->qtype = 'shortanswer';
272 260
         $expectedq->name = 'Name an amphibian: __________.';
273  
-        $expectedq->questiontext = array(
274  
-                'text' => '<span style="font-size:12pt">Name an amphibian: __________.</span>',
275  
-                'format' => FORMAT_HTML,
276  
-            );
  261
+        $expectedq->questiontext = '<span style="font-size:12pt">Name an amphibian: __________.</span>';
277 262
         $expectedq->questiontextformat = FORMAT_HTML;
278 263
         $expectedq->generalfeedback = '';
279 264
         $expectedq->generalfeedbackformat = FORMAT_HTML;
@@ -308,10 +293,7 @@ public function test_import_essay() {
308 293
         $expectedq = new stdClass();
309 294
         $expectedq->qtype = 'essay';
310 295
         $expectedq->name = 'How are you?';
311  
-        $expectedq->questiontext = array(
312  
-                'text' => 'How are you?',
313  
-                'format' => FORMAT_HTML
314  
-            );
  296
+        $expectedq->questiontext = 'How are you?';
315 297
         $expectedq->questiontextformat = FORMAT_HTML;
316 298
         $expectedq->generalfeedback = '';
317 299
         $expectedq->generalfeedbackformat = FORMAT_HTML;

0 notes on commit f62c457

Please sign in to comment.
Something went wrong with that request. Please try again.