Skip to content

Commit

Permalink
MDL-28115 lesson module: fixed undefined variable for multiple answer…
Browse files Browse the repository at this point in the history
…, disabled numberical input text during review and fixed bug for essay answer during review process.
  • Loading branch information
Rossiani Wijaya committed Jun 30, 2011
1 parent 54ae8ed commit 54fd7cd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
14 changes: 10 additions & 4 deletions mod/lesson/pagetypes/essay.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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"));
Expand Down
29 changes: 24 additions & 5 deletions mod/lesson/pagetypes/multichoice.php
Expand Up @@ -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;
Expand All @@ -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"));
}
}

}
19 changes: 16 additions & 3 deletions mod/lesson/pagetypes/numerical.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 54fd7cd

Please sign in to comment.