Skip to content

Commit

Permalink
MDL-29569: lesson_mod: in matching type questions, fixed and set defa…
Browse files Browse the repository at this point in the history
…ult value for scoring and fixed jump page setting when response text is set to empty
  • Loading branch information
Rossiani Wijaya committed Oct 25, 2011
1 parent 3d765bc commit 4d5dc31
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions mod/lesson/pagetypes/matching.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] = '<span class="label">'.get_string("correctanswerscore", "lesson")."</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);

$cells = array();
$cells[] = '<span class="label">'.get_string("correctanswerjump", "lesson")."</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
$table->data[] = new html_table_row($cells);
} elseif ($n == 1) {
$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerscore", "lesson")."</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);

$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerjump", "lesson")."</span>: ";
$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 {
Expand All @@ -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[] = '<span class="label">'.get_string("correctanswerscore", "lesson")." $i</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);

$cells = array();
$cells[] = '<span class="label">'.get_string("correctanswerjump", "lesson")." $i</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
$table->data[] = new html_table_row($cells);
} elseif ($i == 2) {
$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerscore", "lesson")." $i</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);

$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerjump", "lesson")." $i</span>: ";
$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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 4d5dc31

Please sign in to comment.