From 4d5dc3104b1bd0642ac1df573367d43f5cca2a11 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Tue, 25 Oct 2011 12:12:54 +0800 Subject: [PATCH] MDL-29569: lesson_mod: in matching type questions, fixed and set default value for scoring and fixed jump page setting when response text is set to empty --- mod/lesson/pagetypes/matching.php | 84 +++++++++++++++---------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php index 25812d7bfb874..2ba1aa57adddf 100644 --- a/mod/lesson/pagetypes/matching.php +++ b/mod/lesson/pagetypes/matching.php @@ -120,13 +120,14 @@ public function create_answers($properties) { $answer->responseformat = $properties->response_editor[$i]['format']; } + if (isset($properties->jumpto[$i])) { + $answer->jumpto = $properties->jumpto[$i]; + } + if ($this->lesson->custom && isset($properties->score[$i])) { + $answer->score = $properties->score[$i]; + } + if (isset($answer->answer) && $answer->answer != '') { - if (isset($properties->jumpto[$i])) { - $answer->jumpto = $properties->jumpto[$i]; - } - if ($this->lesson->custom && isset($properties->score[$i])) { - $answer->score = $properties->score[$i]; - } $answer->id = $DB->insert_record("lesson_answers", $answer); $answers[$answer->id] = new lesson_page_answer($answer); } else if ($i < 2) { @@ -232,6 +233,32 @@ public function display_answers(html_table $table) { $cells[] = format_text($answer->answer, $answer->answerformat, $options); $table->data[] = new html_table_row($cells); } + + if ($n == 0) { + $cells = array(); + $cells[] = ''.get_string("correctanswerscore", "lesson").": "; + $cells[] = $answer->score; + $table->data[] = new html_table_row($cells); + + $cells = array(); + $cells[] = ''.get_string("correctanswerjump", "lesson").": "; + $cells[] = $this->get_jump_name($answer->jumpto); + $table->data[] = new html_table_row($cells); + } elseif ($n == 1) { + $cells = array(); + $cells[] = ''.get_string("wronganswerscore", "lesson").": "; + $cells[] = $answer->score; + $table->data[] = new html_table_row($cells); + + $cells = array(); + $cells[] = ''.get_string("wronganswerjump", "lesson").": "; + $cells[] = $this->get_jump_name($answer->jumpto); + $table->data[] = new html_table_row($cells); + } + + if ($n === 0){ + $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;'; + } $n++; $i--; } else { @@ -254,33 +281,6 @@ public function display_answers(html_table $table) { $cells[] = format_text($answer->response, $answer->responseformat, $options); $table->data[] = new html_table_row($cells); } - - if ($i == 1) { - $cells = array(); - $cells[] = ''.get_string("correctanswerscore", "lesson")." $i: "; - $cells[] = $answer->score; - $table->data[] = new html_table_row($cells); - - $cells = array(); - $cells[] = ''.get_string("correctanswerjump", "lesson")." $i: "; - $cells[] = $this->get_jump_name($answer->jumpto); - $table->data[] = new html_table_row($cells); - } elseif ($i == 2) { - $cells = array(); - $cells[] = ''.get_string("wronganswerscore", "lesson")." $i: "; - $cells[] = $answer->score; - $table->data[] = new html_table_row($cells); - - $cells = array(); - $cells[] = ''.get_string("wronganswerjump", "lesson")." $i: "; - $cells[] = $this->get_jump_name($answer->jumpto); - $table->data[] = new html_table_row($cells); - } - - if ($i === 1){ - $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;'; - } - $i++; } return $table; @@ -320,20 +320,20 @@ public function update($properties) { $this->answers[$i]->responseformat = $properties->response_editor[$i]['format']; } + if (isset($properties->jumpto[$i])) { + $this->answers[$i]->jumpto = $properties->jumpto[$i]; + } + if ($this->lesson->custom && isset($properties->score[$i])) { + $this->answers[$i]->score = $properties->score[$i]; + } + // we don't need to check for isset here because properties called it's own isset method. if ($this->answers[$i]->answer != '') { - if (isset($properties->jumpto[$i])) { - $this->answers[$i]->jumpto = $properties->jumpto[$i]; - } - if ($this->lesson->custom && isset($properties->score[$i])) { - $this->answers[$i]->score = $properties->score[$i]; - } if (!isset($this->answers[$i]->id)) { $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]); } else { $DB->update_record("lesson_answers", $this->answers[$i]->properties()); } - } else if ($i < 2) { if (!isset($this->answers[$i]->id)) { $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]); @@ -460,12 +460,12 @@ public function custom_definition() { $this->_form->addElement('header', 'correctresponse', get_string('correctresponse', 'lesson')); $this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true)); $this->add_jumpto(0, get_string('correctanswerjump','lesson'), LESSON_NEXTPAGE); - $this->add_score(0, get_string("correctanswerscore", "lesson")); + $this->add_score(0, get_string("correctanswerscore", "lesson"), 1); $this->_form->addElement('header', 'wrongresponse', get_string('wrongresponse', 'lesson')); $this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true)); $this->add_jumpto(1, get_string('wronganswerjump','lesson'), LESSON_THISPAGE); - $this->add_score(1, get_string("wronganswerscore", "lesson")); + $this->add_score(1, get_string("wronganswerscore", "lesson"), 0); for ($i = 2; $i < $this->_customdata['lesson']->maxanswers+2; $i++) { $this->_form->addElement('header', 'matchingpair'.($i-1), get_string('matchingpair', 'lesson', $i-1));