Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-29569: lesson_mod: in matching type questions, fixed and set defa…

…ult value for scoring and fixed jump page setting when response text is set to empty
  • Loading branch information...
commit 4d5dc3104b1bd0642ac1df573367d43f5cca2a11 1 parent 3d765bc
rwijaya rwijaya authored

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

  1. +42 42 mod/lesson/pagetypes/matching.php
84 mod/lesson/pagetypes/matching.php
@@ -120,13 +120,14 @@ public function create_answers($properties) {
120 120 $answer->responseformat = $properties->response_editor[$i]['format'];
121 121 }
122 122
  123 + if (isset($properties->jumpto[$i])) {
  124 + $answer->jumpto = $properties->jumpto[$i];
  125 + }
  126 + if ($this->lesson->custom && isset($properties->score[$i])) {
  127 + $answer->score = $properties->score[$i];
  128 + }
  129 +
123 130 if (isset($answer->answer) && $answer->answer != '') {
124   - if (isset($properties->jumpto[$i])) {
125   - $answer->jumpto = $properties->jumpto[$i];
126   - }
127   - if ($this->lesson->custom && isset($properties->score[$i])) {
128   - $answer->score = $properties->score[$i];
129   - }
130 131 $answer->id = $DB->insert_record("lesson_answers", $answer);
131 132 $answers[$answer->id] = new lesson_page_answer($answer);
132 133 } else if ($i < 2) {
@@ -232,6 +233,32 @@ public function display_answers(html_table $table) {
232 233 $cells[] = format_text($answer->answer, $answer->answerformat, $options);
233 234 $table->data[] = new html_table_row($cells);
234 235 }
  236 +
  237 + if ($n == 0) {
  238 + $cells = array();
  239 + $cells[] = '<span class="label">'.get_string("correctanswerscore", "lesson")."</span>: ";
  240 + $cells[] = $answer->score;
  241 + $table->data[] = new html_table_row($cells);
  242 +
  243 + $cells = array();
  244 + $cells[] = '<span class="label">'.get_string("correctanswerjump", "lesson")."</span>: ";
  245 + $cells[] = $this->get_jump_name($answer->jumpto);
  246 + $table->data[] = new html_table_row($cells);
  247 + } elseif ($n == 1) {
  248 + $cells = array();
  249 + $cells[] = '<span class="label">'.get_string("wronganswerscore", "lesson")."</span>: ";
  250 + $cells[] = $answer->score;
  251 + $table->data[] = new html_table_row($cells);
  252 +
  253 + $cells = array();
  254 + $cells[] = '<span class="label">'.get_string("wronganswerjump", "lesson")."</span>: ";
  255 + $cells[] = $this->get_jump_name($answer->jumpto);
  256 + $table->data[] = new html_table_row($cells);
  257 + }
  258 +
  259 + if ($n === 0){
  260 + $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
  261 + }
235 262 $n++;
236 263 $i--;
237 264 } else {
@@ -254,33 +281,6 @@ public function display_answers(html_table $table) {
254 281 $cells[] = format_text($answer->response, $answer->responseformat, $options);
255 282 $table->data[] = new html_table_row($cells);
256 283 }
257   -
258   - if ($i == 1) {
259   - $cells = array();
260   - $cells[] = '<span class="label">'.get_string("correctanswerscore", "lesson")." $i</span>: ";
261   - $cells[] = $answer->score;
262   - $table->data[] = new html_table_row($cells);
263   -
264   - $cells = array();
265   - $cells[] = '<span class="label">'.get_string("correctanswerjump", "lesson")." $i</span>: ";
266   - $cells[] = $this->get_jump_name($answer->jumpto);
267   - $table->data[] = new html_table_row($cells);
268   - } elseif ($i == 2) {
269   - $cells = array();
270   - $cells[] = '<span class="label">'.get_string("wronganswerscore", "lesson")." $i</span>: ";
271   - $cells[] = $answer->score;
272   - $table->data[] = new html_table_row($cells);
273   -
274   - $cells = array();
275   - $cells[] = '<span class="label">'.get_string("wronganswerjump", "lesson")." $i</span>: ";
276   - $cells[] = $this->get_jump_name($answer->jumpto);
277   - $table->data[] = new html_table_row($cells);
278   - }
279   -
280   - if ($i === 1){
281   - $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
282   - }
283   -
284 284 $i++;
285 285 }
286 286 return $table;
@@ -320,20 +320,20 @@ public function update($properties) {
320 320 $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
321 321 }
322 322
  323 + if (isset($properties->jumpto[$i])) {
  324 + $this->answers[$i]->jumpto = $properties->jumpto[$i];
  325 + }
  326 + if ($this->lesson->custom && isset($properties->score[$i])) {
  327 + $this->answers[$i]->score = $properties->score[$i];
  328 + }
  329 +
323 330 // we don't need to check for isset here because properties called it's own isset method.
324 331 if ($this->answers[$i]->answer != '') {
325   - if (isset($properties->jumpto[$i])) {
326   - $this->answers[$i]->jumpto = $properties->jumpto[$i];
327   - }
328   - if ($this->lesson->custom && isset($properties->score[$i])) {
329   - $this->answers[$i]->score = $properties->score[$i];
330   - }
331 332 if (!isset($this->answers[$i]->id)) {
332 333 $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
333 334 } else {
334 335 $DB->update_record("lesson_answers", $this->answers[$i]->properties());
335 336 }
336   -
337 337 } else if ($i < 2) {
338 338 if (!isset($this->answers[$i]->id)) {
339 339 $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
@@ -460,12 +460,12 @@ public function custom_definition() {
460 460 $this->_form->addElement('header', 'correctresponse', get_string('correctresponse', 'lesson'));
461 461 $this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
462 462 $this->add_jumpto(0, get_string('correctanswerjump','lesson'), LESSON_NEXTPAGE);
463   - $this->add_score(0, get_string("correctanswerscore", "lesson"));
  463 + $this->add_score(0, get_string("correctanswerscore", "lesson"), 1);
464 464
465 465 $this->_form->addElement('header', 'wrongresponse', get_string('wrongresponse', 'lesson'));
466 466 $this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
467 467 $this->add_jumpto(1, get_string('wronganswerjump','lesson'), LESSON_THISPAGE);
468   - $this->add_score(1, get_string("wronganswerscore", "lesson"));
  468 + $this->add_score(1, get_string("wronganswerscore", "lesson"), 0);
469 469
470 470 for ($i = 2; $i < $this->_customdata['lesson']->maxanswers+2; $i++) {
471 471 $this->_form->addElement('header', 'matchingpair'.($i-1), get_string('matchingpair', 'lesson', $i-1));

0 comments on commit 4d5dc31

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