Skip to content

Commit

Permalink
MDL-27955 lesson module: fixed error for reviewing lesson and update …
Browse files Browse the repository at this point in the history
…string to continue or finish reviewing
  • Loading branch information
Rossiani Wijaya committed Jun 29, 2011
1 parent 57a4bd0 commit abd5c24
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 48 deletions.
17 changes: 12 additions & 5 deletions mod/lesson/continue.php
Expand Up @@ -67,6 +67,13 @@

// record answer (if necessary) and show response (if none say if answer is correct or not)
$page = $lesson->load_page(required_param('pageid', PARAM_INT));

$userhasgrade = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
$reviewmode = false;
if ($userhasgrade && !$lesson->retake) {
$reviewmode = true;
}

// Check the page has answers [MDL-25632]
if (count($page->answers) > 0) {
$result = $page->record_attempt($context);
Expand All @@ -80,7 +87,7 @@

if (isset($USER->modattempts[$lesson->id])) {
// make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
if ($USER->modattempts[$lesson->id] == $page->id && $page->nextpageid == 0) { // remember, this session variable holds the pageid of the last page that the user saw
if ($USER->modattempts[$lesson->id]->pageid == $page->id && $page->nextpageid == 0) { // remember, this session variable holds the pageid of the last page that the user saw
$result->newpageid = LESSON_EOL;
} else {
$nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
Expand Down Expand Up @@ -153,11 +160,11 @@
}
}
// Report attempts remaining
if ($result->attemptsremaining != 0 && !$lesson->review) {
if ($result->attemptsremaining != 0 && !$lesson->review && !$reviewmode) {
$lesson->add_message(get_string('attemptsremaining', 'lesson', $result->attemptsremaining));
}
// Report if max attempts reached
if ($result->maxattemptsreached != 0 && !$lesson->review) {
if ($result->maxattemptsreached != 0 && !$lesson->review && !$reviewmode) {
$lesson->add_message('('.get_string("maximumnumberofattemptsreached", "lesson").')');
}

Expand All @@ -172,7 +179,7 @@
echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
}
// This calculates and prints the ongoing score message
if ($lesson->ongoing) {
if ($lesson->ongoing && !$reviewmode) {
echo $lessonoutput->ongoing_score($lesson);
}
echo $result->feedback;
Expand All @@ -190,7 +197,7 @@
}

// Review button back
if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion) {
if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode) {
$url = $CFG->wwwroot.'/mod/lesson/view.php';
$content = html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id));
$content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>$page->id));
Expand Down
2 changes: 2 additions & 0 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -108,6 +108,7 @@
$string['confirmdeletionofthispage'] = 'Confirm deletion of this page';
$string['congratulations'] = 'Congratulations - end of lesson reached';
$string['continue'] = 'Continue';
$string['continuetoanswer'] = 'Continue to change answers.';
$string['continuetonextpage'] = 'Continue to next page.';
$string['correctanswerjump'] = 'Correct answer jump';
$string['correctanswerscore'] = 'Correct answer score';
Expand Down Expand Up @@ -380,6 +381,7 @@
$string['studentname'] = '{$a} Name';
$string['studentoneminwarning'] = 'Warning: You have 1 minute or less to finish the lesson.';
$string['studentresponse'] = '{$a}\'s response';
$string['submit'] = 'Submit';
$string['submitname'] = 'Submit name';
$string['teacherjumpwarning'] = 'An {$a->cluster} jump or an {$a->unseen} jump is being used in this lesson. The next page jump will be used instead. Login as a student to test these jumps.';
$string['teacherongoingwarning'] = 'Ongoing score is only displayed for student. Login as a student to test ongoing score';
Expand Down
6 changes: 4 additions & 2 deletions mod/lesson/locallib.php
Expand Up @@ -1961,13 +1961,15 @@ final public function record_attempt($context) {
$attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high
}

$DB->insert_record("lesson_attempts", $attempt);
if ($this->lesson->retake || (!$this->lesson->retake && $nretakes == 0)) {
$DB->insert_record("lesson_attempts", $attempt);
}
// "number of attempts remaining" message if $this->lesson->maxattempts > 1
// displaying of message(s) is at the end of page for more ergonomic display
if (!$result->correctanswer && ($result->newpageid == 0)) {
// wrong answer and student is stuck on this page - check how many attempts
// the student has had at this page/question
$nattempts = $DB->count_records("lesson_attempts", array("pageid"=>$this->properties->id, "userid"=>$USER->id, "retry" => $nretakes));
$nattempts = $DB->count_records("lesson_attempts", array("pageid"=>$this->properties->id, "userid"=>$USER->id, "retry" => $attempt->retry));
// retreive the number of attempts left counter for displaying at bottom of feedback page
if ($nattempts >= $this->lesson->maxattempts) {
if ($this->lesson->maxattempts > 1) { // don't bother with message if only one attempt
Expand Down
34 changes: 27 additions & 7 deletions mod/lesson/pagetypes/essay.php
Expand Up @@ -51,14 +51,14 @@ public function get_idstring() {
public function display($renderer, $attempt) {
global $PAGE, $CFG, $USER;

$mform = new lesson_display_answer_form_essay($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
$mform = new lesson_display_answer_form_essay($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;
if (isset($USER->modattempts[$this->lesson->id])) {
$essayinfo = unserialize($attempt->useranswer);
$data->answer = array('text'=>$essayinfo->answer, 'format'=>FORMAT_HTML);
$data->answer = $essayinfo->answer;
}
$mform->set_data($data);
return $mform->display();
Expand Down Expand Up @@ -252,6 +252,20 @@ public function definition() {
$mform = $this->_form;
$contents = $this->_customdata['contents'];

$hasattempt = false;
$attrs = '';
$useranswer = '';
$useranswerraw = '';
if (isset($this->_customdata['lessonid'])) {
$lessonid = $this->_customdata['lessonid'];
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);
}
}

$mform->addElement('header', 'pageheader');

$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
Expand All @@ -266,10 +280,16 @@ public function definition() {
$mform->addElement('hidden', 'pageid');
$mform->setType('pageid', PARAM_INT);

$mform->addElement('editor', 'answer', get_string('youranswer', 'lesson'), null, null);
$mform->setType('answer', PARAM_RAW);

$this->add_action_buttons(null, get_string("pleaseenteryouranswerinthebox", "lesson"));
if ($hasattempt) {
$mform->addElement('hidden', 'answer', $useranswerraw);
$mform->setType('answer', PARAM_CLEANHTML);
$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"));
} else {
$mform->addElement('editor', 'answer', get_string('youranswer', 'lesson'), null, null);
$mform->setType('answer', PARAM_RAW);
$this->add_action_buttons(null, get_string("submit", "lesson"));
}
}

}
31 changes: 23 additions & 8 deletions mod/lesson/pagetypes/matching.php
Expand Up @@ -63,7 +63,6 @@ protected function make_answer_form($attempt=null) {
// don't shuffle answers (could be an option??)
$getanswers = array_slice($this->get_answers(), 2);

//reassing array keys for answers
$answers = array();
foreach ($getanswers as $getanswer) {
$answers[$getanswer->id] = $getanswer;
Expand Down Expand Up @@ -494,6 +493,13 @@ public function definition() {

$mform->addElement('html', $OUTPUT->container($contents, 'contents'));

$hasattempt = false;
$disabled = '';
if (isset($useranswers) && !empty($useranswers)) {
$hasattempt = true;
$disabled = array('disabled' => 'disabled');
}

$options = new stdClass;
$options->para = false;
$options->noclean = true;
Expand All @@ -508,19 +514,28 @@ public function definition() {
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
if ($answer->response != NULL) {
$mform->addElement('select', 'response['.$answer->id.']', format_text($answer->answer,$answer->answerformat,$options), $responseoptions);
$mform->setType('response['.$answer->id.']', PARAM_TEXT);
if (isset($useranswers) && !empty($useranswers)) {
$mform->setDefault('response['.$answer->id.']', htmlspecialchars(trim($answers[$useranswers[$i]]->response))); //TODO: this is suspicious
$responseid = 'response['.$answer->id.']';
if ($hasattempt) {
$responseid = 'response_'.$answer->id;
$mform->addElement('hidden', 'response['.$answer->id.']', htmlspecialchars(trim($answers[$useranswers[$i]]->response)));
$mform->setType('response['.$answer->id.']', PARAM_TEXT);
}
$mform->addElement('select', $responseid, format_text($answer->answer,$answer->answerformat,$options), $responseoptions, $disabled);
$mform->setType($responseid, PARAM_TEXT);
if ($hasattempt) {
$mform->setDefault($responseid, htmlspecialchars(trim($answers[$useranswers[$i]]->response))); //TODO: this is suspicious
} else {
$mform->setDefault('response['.$answer->id.']', 'answeroption');
$mform->setDefault($responseid, 'answeroption');
}
}
$mform->addElement('html', '</div>');
$i++;
}

$this->add_action_buttons(null, get_string("pleasematchtheabovepairs", "lesson"));
if ($hasattempt) {
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
} else {
$this->add_action_buttons(null, get_string("submit", "lesson"));
}
}

}
17 changes: 14 additions & 3 deletions mod/lesson/pagetypes/multichoice.php
Expand Up @@ -490,6 +490,13 @@ public function definition() {

$mform->addElement('html', $OUTPUT->container($contents, 'contents'));

$hasattempt = false;
$disabled = '';
if (isset($USER->modattempts[$lessonid]) && !empty($USER->modattempts[$lessonid])) {
$hasattempt = true;
$disabled = array('disabled' => 'disabled');
}

$options = new stdClass;
$options->para = false;
$options->noclean = true;
Expand All @@ -503,16 +510,20 @@ public function definition() {
$i = 0;
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
$mform->addElement('radio','answerid',null,format_text($answer->answer, $answer->answerformat, $options),$answer->id);
$mform->addElement('radio','answerid',null,format_text($answer->answer, $answer->answerformat, $options),$answer->id, $disabled);
$mform->setType('answer'.$i, PARAM_INT);
if (isset($USER->modattempts[$lessonid]) && $answer->id == $USER->modattempts[$lessonid]->answerid) {
if ($hasattempt && $answer->id == $USER->modattempts[$lessonid]->answerid) {
$mform->setDefault('answerid', $USER->modattempts[$lessonid]->answerid);
}
$mform->addElement('html', '</div>');
$i++;
}

$this->add_action_buttons(null, get_string("pleasecheckoneanswer", "lesson"));
if ($hasattempt) {
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
} else {
$this->add_action_buttons(null, get_string("submit", "lesson"));
}
}

}
Expand Down
22 changes: 18 additions & 4 deletions mod/lesson/pagetypes/shortanswer.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 @@ -328,10 +328,20 @@ public function custom_definition() {
class lesson_display_answer_form_shortanswer extends moodleform {

public function definition() {
global $OUTPUT;
global $OUTPUT, $USER;
$mform = $this->_form;
$contents = $this->_customdata['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;
}
}

$mform->addElement('header', 'pageheader');

$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
Expand All @@ -346,10 +356,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_TEXT);

$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"));
}
}

}
29 changes: 24 additions & 5 deletions mod/lesson/pagetypes/truefalse.php
Expand Up @@ -303,6 +303,13 @@ public function definition() {

$mform->addElement('html', $OUTPUT->container($contents, 'contents'));

$hasattempt = false;
$disabled = '';
if (isset($USER->modattempts[$lessonid]) && !empty($USER->modattempts[$lessonid])) {
$hasattempt = true;
$disabled = array('disabled' => 'disabled');
}

$options = new stdClass();
$options->para = false;
$options->noclean = true;
Expand All @@ -316,16 +323,28 @@ public function definition() {
$i = 0;
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
$mform->addElement('radio', 'answerid', null, format_text($answer->answer, $answer->answerformat, $options), $answer->id);
$mform->setType('answerid', PARAM_INT);
if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
$mform->setDefault('answerid', $attempt->answerid);
$ansid = 'answerid';
if ($hasattempt) {
$ansid = 'answer_id';
}

$mform->addElement('radio', $ansid, null, format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled);
$mform->setType($ansid, PARAM_INT);
if ($hasattempt && $answer->id == $USER->modattempts[$lessonid]->answerid) {
$mform->setDefault($ansid, $attempt->answerid);
$mform->addElement('hidden', 'answerid', $answer->id);
$mform->setType('answerid', PARAM_INT);
}
$mform->addElement('html', '</div>');
$i++;
}

$this->add_action_buttons(null, get_string("pleasecheckoneanswer", "lesson"));
if ($hasattempt) {
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
} else {
$this->add_action_buttons(null, get_string("submit", "lesson"));
}

}

}
3 changes: 2 additions & 1 deletion mod/lesson/styles.css
Expand Up @@ -28,4 +28,5 @@
/**
* Style for view.php
**/
#page-mod-lesson-view .password-form .submitbutton {display: inline;}
#page-mod-lesson-view .password-form .submitbutton {display: inline;}
.path-mod-lesson .reviewessay {width:40%; border:1px solid #DDDDDD; background-color: #EEEEEE;}

0 comments on commit abd5c24

Please sign in to comment.