Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-34483 qformat_examview: changes required to make it basically work.

  • Loading branch information...
commit 53f2f306dd14bf994f98f6a8bfdc6e4ccba3eee1 1 parent 6975216
Jean-Michel Vedrine jmvedrine authored timhunt committed

Showing 1 changed file with 41 additions and 11 deletions. Show diff stats Hide diff stats

  1. +41 11 question/format/examview/format.php
52 question/format/examview/format.php
@@ -58,6 +58,10 @@ function provide_import() {
58 58 return true;
59 59 }
60 60
  61 + public function mime_type() {
  62 + return 'application/xml';
  63 + }
  64 +
61 65 /**
62 66 * unxmlise reconstructs part of the xml data structure in order
63 67 * to identify the actual data therein
@@ -84,6 +88,26 @@ function unxmlise( $xml ) {
84 88 $text = strip_tags($text);
85 89 return $text;
86 90 }
  91 + protected function text_field($text) {
  92 + return array(
  93 + 'text' => htmlspecialchars(trim($text), ENT_NOQUOTES),
  94 + 'format' => FORMAT_HTML,
  95 + 'files' => array(),
  96 + );
  97 + }
  98 +
  99 + protected function add_blank_combined_feedback($question) {
  100 + $question->correctfeedback['text'] = '';
  101 + $question->correctfeedback['format'] = $question->questiontextformat;
  102 + $question->correctfeedback['files'] = array();
  103 + $question->partiallycorrectfeedback['text'] = '';
  104 + $question->partiallycorrectfeedback['format'] = $question->questiontextformat;
  105 + $question->partiallycorrectfeedback['files'] = array();
  106 + $question->incorrectfeedback['text'] = '';
  107 + $question->incorrectfeedback['format'] = $question->questiontextformat;
  108 + $question->incorrectfeedback['files'] = array();
  109 + return $question;
  110 + }
87 111
88 112 function parse_matching_groups($matching_groups)
89 113 {
@@ -115,7 +139,7 @@ function parse_ma($qrec, $groupname)
115 139 $phrase = trim($this->unxmlise($qrec['text']['0']['#']));
116 140 $answer = trim($this->unxmlise($qrec['answer']['0']['#']));
117 141 $answer = strip_tags( $answer );
118   - $match_group->subquestions[] = $phrase;
  142 + $match_group->subquestions[] = $this->text_field($phrase);
119 143 $match_group->subanswers[] = $match_group->subchoices[$answer];
120 144 $this->matching_questions[$groupname] = $match_group;
121 145 return NULL;
@@ -130,8 +154,11 @@ function process_matches(&$questions)
130 154 $question = $this->defaultquestion();
131 155 $htmltext = s($match_group->questiontext);
132 156 $question->questiontext = $htmltext;
133   - $question->name = $question->questiontext;
  157 + $question->questiontextformat = FORMAT_HTML;
  158 + $question->questiontextfiles = array();
  159 + $question->name = shorten_text( $question->questiontext, 250 );
134 160 $question->qtype = MATCH;
  161 + $question = $this->add_blank_combined_feedback($question);
135 162 $question->subquestions = array();
136 163 $question->subanswers = array();
137 164 foreach($match_group->subquestions as $key => $value) {
@@ -192,6 +219,8 @@ function readquestion($qrec)
192 219 // Only one answer is allowed
193 220 $htmltext = $this->unxmlise($qrec['#']['text'][0]['#']);
194 221 $question->questiontext = $htmltext;
  222 + $question->questiontextformat = FORMAT_HTML;
  223 + $question->questiontextfiles = array();
195 224 $question->name = shorten_text( $question->questiontext, 250 );
196 225
197 226 switch ($question->qtype) {
@@ -232,30 +261,31 @@ function parse_tf_yn($qrec, $question)
232 261 $question->answer = $choices[$answer];
233 262 $question->correctanswer = $question->answer;
234 263 if ($question->answer == 1) {
235   - $question->feedbacktrue = 'Correct';
236   - $question->feedbackfalse = 'Incorrect';
  264 + $question->feedbacktrue = $this->text_field('Correct');
  265 + $question->feedbackfalse = $this->text_field('Incorrect');
237 266 } else {
238   - $question->feedbacktrue = 'Incorrect';
239   - $question->feedbackfalse = 'Correct';
  267 + $question->feedbacktrue = $this->text_field('Incorrect');
  268 + $question->feedbackfalse = $this->text_field('Correct');
240 269 }
241 270 return $question;
242 271 }
243 272
244 273 function parse_mc($qrec, $question)
245 274 {
  275 + $question = $this->add_blank_combined_feedback($question);
246 276 $answer = 'choice-'.strtolower(trim($qrec['answer'][0]['#']));
247 277
248 278 $choices = $qrec['choices'][0]['#'];
249 279 foreach($choices as $key => $value) {
250 280 if (strpos(trim($key),'choice-') !== FALSE) {
251 281
252   - $question->answer[$key] = s($this->unxmlise($value[0]['#']));
  282 + $question->answer[$key] = $this->text_field(s($this->unxmlise($value[0]['#'])));
253 283 if (strcmp($key, $answer) == 0) {
254 284 $question->fraction[$key] = 1;
255   - $question->feedback[$key] = 'Correct';
  285 + $question->feedback[$key] = $this->text_field('Correct');
256 286 } else {
257 287 $question->fraction[$key] = 0;
258   - $question->feedback[$key] = 'Incorrect';
  288 + $question->feedback[$key] = $this->text_field('Incorrect');
259 289 }
260 290 }
261 291 }
@@ -274,7 +304,7 @@ function parse_co($qrec, $question)
274 304 if (strlen($value) > 0) {
275 305 $question->answer[$key] = $value;
276 306 $question->fraction[$key] = 1;
277   - $question->feedback[$key] = "Correct";
  307 + $question->feedback[$key] = $this->text_field("Correct");
278 308 }
279 309 }
280 310 return $question;
@@ -299,7 +329,7 @@ function parse_nr($qrec, $question)
299 329 $errormargin = 0;
300 330 $question->answer[$key] = $value;
301 331 $question->fraction[$key] = 1;
302   - $question->feedback[$key] = "Correct";
  332 + $question->feedback[$key] = $this->text_field("Correct");
303 333 $question->min[$key] = $question->answer[$key] - $errormargin;
304 334 $question->max[$key] = $question->answer[$key] + $errormargin;
305 335 }

0 comments on commit 53f2f30

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