Skip to content
Browse files

MDL-28115 lesson module: fixed undefined variable for multiple answer…

…, disabled numberical input text during review and fixed bug for essay answer during review process.
  • Loading branch information...
1 parent 494f645 commit 814bce6575695abb5078f5d62b568dbd5f8bb95d @rwijaya rwijaya committed Jun 30, 2011
Showing with 50 additions and 12 deletions.
  1. +10 −4 mod/lesson/pagetypes/essay.php
  2. +24 −5 mod/lesson/pagetypes/multichoice.php
  3. +16 −3 mod/lesson/pagetypes/numerical.php
View
14 mod/lesson/pagetypes/essay.php
@@ -95,7 +95,12 @@ public function check_answer() {
redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id, 'pageid'=>$this->properties->id)));
}
- $studentanswer = $data->answer['text'];
+ if (is_array($data->answer)) {
+ $studentanswer = $data->answer['text'];
+ } else {
+ $studentanswer = $data->answer;
+ }
+
if (trim($studentanswer) === '') {
$result->noanswer = true;
return $result;
@@ -261,8 +266,9 @@ public function definition() {
if (isset($USER->modattempts[$lessonid]->useranswer) && !empty($USER->modattempts[$lessonid]->useranswer)) {
$attrs = array('disabled' => 'disabled');
$hasattempt = true;
- $useranswer = unserialize($USER->modattempts[$lessonid]->useranswer);
- $useranswer = htmlspecialchars_decode($useranswer->answer, ENT_QUOTES);
+ $useranswertemp = unserialize($USER->modattempts[$lessonid]->useranswer);
+ $useranswer = htmlspecialchars_decode($useranswertemp->answer, ENT_QUOTES);
+ $useranswerraw = $useranswertemp->answer;
}
}
@@ -282,7 +288,7 @@ public function definition() {
if ($hasattempt) {
$mform->addElement('hidden', 'answer', $useranswerraw);
- $mform->setType('answer', PARAM_CLEANHTML);
+ $mform->setType('answer', PARAM_RAW);
$mform->addElement('html', $OUTPUT->container(get_string('youranswer', 'lesson'), 'youranswer'));
$mform->addElement('html', $OUTPUT->container($useranswer, 'reviewessay'));
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
View
29 mod/lesson/pagetypes/multichoice.php
@@ -542,6 +542,15 @@ public function definition() {
$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
+ $hasattempt = false;
+ $disabled = '';
+ $useranswers = array();
+ if (isset($USER->modattempts[$lessonid]) && !empty($USER->modattempts[$lessonid])) {
+ $hasattempt = true;
+ $disabled = array('disabled' => 'disabled');
+ $useranswers = explode(',', $USER->modattempts[$lessonid]->useranswer);
+ }
+
$options = new stdClass;
$options->para = false;
$options->noclean = true;
@@ -554,16 +563,26 @@ public function definition() {
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
- // NOTE: our silly checkbox supports only value '1' - we can not use it like the radiobox above!!!!!!
- $mform->addElement('checkbox','answer['.$answer->id.']',null,format_text($answer->answer, $answer->answerformat, $options));
- $mform->setType('answer['.$answer->id.']', PARAM_INT);
- if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
+ $answerid = 'answer['.$answer->id.']';
+ if ($hasattempt && in_array($answer->id, $useranswers)) {
+ $answerid = 'answer_'.$answer->id;
+ $mform->addElement('hidden', 'answer['.$answer->id.']', $answer->answer);
+ $mform->setType('answer['.$answer->id.']', PARAM_TEXT);
+ $mform->setDefault($answerid, true);
$mform->setDefault('answer['.$answer->id.']', true);
}
+ // NOTE: our silly checkbox supports only value '1' - we can not use it like the radiobox above!!!!!!
+ $mform->addElement('checkbox', $answerid, null, format_text($answer->answer, $answer->answerformat, $options), $disabled);
+ $mform->setType($answerid, PARAM_INT);
+
$mform->addElement('html', '</div>');
}
- $this->add_action_buttons(null, get_string("pleasecheckoneormoreanswers", "lesson"));
+ if ($hasattempt) {
+ $this->add_action_buttons(null, get_string("nextpage", "lesson"));
+ } else {
+ $this->add_action_buttons(null, get_string("submit", "lesson"));
+ }
}
}
View
19 mod/lesson/pagetypes/numerical.php
@@ -50,7 +50,7 @@ public function get_idstring() {
}
public function display($renderer, $attempt) {
global $USER, $CFG, $PAGE;
- $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
+ $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents(), 'lessonid'=>$this->lesson->id));
$data = new stdClass;
$data->id = $PAGE->cm->id;
$data->pageid = $this->properties->id;
@@ -268,6 +268,15 @@ public function definition() {
$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
+ $hasattempt = false;
+ $attrs = array('size'=>'50', 'maxlength'=>'200');
+ if (isset($this->_customdata['lessonid'])) {
+ $lessonid = $this->_customdata['lessonid'];
+ if (isset($USER->modattempts[$lessonid]->useranswer)) {
+ $attrs['readonly'] = 'readonly';
+ $hasattempt = true;
+ }
+ }
$options = new stdClass;
$options->para = false;
$options->noclean = true;
@@ -278,10 +287,14 @@ public function definition() {
$mform->addElement('hidden', 'pageid');
$mform->setType('pageid', PARAM_INT);
- $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), array('size'=>'50', 'maxlength'=>'200'));
+ $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), $attrs);
$mform->setType('answer', PARAM_FLOAT);
- $this->add_action_buttons(null, get_string("pleaseenteryouranswerinthebox", "lesson"));
+ if ($hasattempt) {
+ $this->add_action_buttons(null, get_string("nextpage", "lesson"));
+ } else {
+ $this->add_action_buttons(null, get_string("submit", "lesson"));
+ }
}
}

0 comments on commit 814bce6

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