Permalink
Browse files

Merge branch 'MDL-27955_m20' of git://github.com/rwijaya/moodle into …

…MOODLE_20_STABLE
  • Loading branch information...
stronk7 committed Jun 29, 2011
2 parents fb654f6 + 494f645 commit 8277c39c763a5b6c988e2a5aeb6981b73c74978a
View
@@ -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);
@@ -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));
@@ -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").')');
}
@@ -172,25 +179,25 @@
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;
// User is modifying attempts - save button and some instructions
if (isset($USER->modattempts[$lesson->id])) {
$url = $CFG->wwwroot.'/mod/lesson/view.php';
- $content = $OUTPUT->box(get_string("savechangesandeol", "lesson"), 'center');
+ $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
$content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
- $content .= $OUTPUT->box(get_string("continuetoanswer", "lesson"), 'center');
+ $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
$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'=>LESSON_EOL));
- $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('savechanges', 'lesson')));
+ $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('finish', 'lesson')));
echo html_writer::tag('form', "<div>$content</div>", array('method'=>'post', 'action'=>$url));
}
// 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));
@@ -109,6 +109,7 @@
$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';
$string['correctresponse'] = 'Correct response';
@@ -166,11 +167,13 @@
$string['essays'] = 'Essays';
$string['essayscore'] = 'Essay score';
$string['fileformat'] = 'File format';
+$string['finish'] = 'Finish';
$string['firstanswershould'] = 'First answer should jump to the "Correct" page';
$string['firstwrong'] = 'Unfortunately you cannot earn this one point, because your response was not correct. Would you like to keep guessing, just for the sheer joy of learning (but for no point credit)?';
$string['flowcontrol'] = 'Flow control';
$string['full'] = 'Expanded';
$string['general'] = 'General';
+$string['gotoendoflesson'] = 'Go to the end of the lesson';
$string['grade'] = 'Grade';
$string['gradebetterthan'] = 'Grade better than (&#37;)';
$string['gradebetterthanerror'] = 'Earn a grade better than {$a} percent';
@@ -377,6 +380,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';
View
@@ -1961,13 +1961,15 @@ public function properties() {
$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
@@ -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();
@@ -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'));
@@ -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"));
+ }
}
-
}
@@ -61,7 +61,13 @@ public function display($renderer, $attempt) {
protected function make_answer_form($attempt=null) {
global $USER, $CFG;
// don't shuffle answers (could be an option??)
- $answers = array_slice($this->get_answers(), 2);
+ $getanswers = array_slice($this->get_answers(), 2);
+
+ $answers = array();
+ foreach ($getanswers as $getanswer) {
+ $answers[$getanswer->id] = $getanswer;
+ }
+
$responses = array();
foreach ($answers as $answer) {
// get all the response
@@ -487,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;
@@ -501,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($USER->modattempts[$lessonid])) {
- $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"));
+ }
}
}
@@ -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;
@@ -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) {
- $mform->setDefault('answerid', true);
+ 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"));
+ }
}
}
@@ -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;
@@ -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'));
@@ -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"));
+ }
}
}
@@ -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;
@@ -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', true);
+ $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"));
+ }
+
}
}
View
@@ -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;}
Oops, something went wrong.

0 comments on commit 8277c39

Please sign in to comment.