Skip to content
Browse files

mod-lesson MDL-25632 Added support for displaying and progressing thr…

…ough a question page with no answers
  • Loading branch information...
1 parent 36a60f0 commit 1c510e2ee1012ec78ab8526dc8f30c4d30bbfbc8 Sam Hemelryk committed Dec 14, 2010
Showing with 35 additions and 3 deletions.
  1. +10 −1 mod/lesson/continue.php
  2. +3 −1 mod/lesson/locallib.php
  3. +7 −1 mod/lesson/view.php
  4. +15 −0 mod/lesson/view_form.php
View
11 mod/lesson/continue.php
@@ -67,7 +67,16 @@
// 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));
-$result = $page->record_attempt($context);
+// Check the page has answers [MDL-25632]
+if (count($page->answers) > 0) {
+ $result = $page->record_attempt($context);
+} else {
+ // The page has no answers so we will just progress to the next page in the
+ // sequence (as set by newpageid).
+ $result = new stdClass;
+ $result->newpageid = optional_param('newpageid', $page->nextpageid, PARAM_INT);
+ $result->nodefaultresponse = true;
+}
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
View
4 mod/lesson/locallib.php
@@ -1881,7 +1881,9 @@ public function properties() {
$this->answers = array();
$answers = $DB->get_records('lesson_answers', array('pageid'=>$this->properties->id, 'lessonid'=>$this->lesson->id), 'id');
if (!$answers) {
- debugging(get_string('cannotfindanswer', 'lesson'));
+ // It is possible that a lesson upgraded from Moodle 1.9 still
+ // contains questions without any answers [MDL-25632].
+ // debugging(get_string('cannotfindanswer', 'lesson'));
return array();
}
foreach ($answers as $answer) {
View
8 mod/lesson/view.php
@@ -359,11 +359,17 @@
} else {
$data = new stdClass;
$data->id = $PAGE->cm->id;
+ $data->pageid = $page->id;
+ $data->newpageid = LESSON_NEXTPAGE;
if ($nextpage = $lesson->get_next_page($page->nextpageid)) {
$data->newpageid = $nextpage->id;
}
- $mform = new lesson_page_without_answers();
+ $customdata = array(
+ 'title' => $page->title,
+ 'contents' => $page->get_contents()
+ );
+ $mform = new lesson_page_without_answers($CFG->wwwroot.'/mod/lesson/continue.php', $customdata);
$mform->set_data($data);
ob_start();
$mform->display();
View
15 mod/lesson/view_form.php
@@ -41,15 +41,30 @@
class lesson_page_without_answers extends moodleform {
public function definition() {
+ global $OUTPUT;
$mform = $this->_form;
+ $title = $this->_customdata['title'];
+ $contents = $this->_customdata['contents'];
+
+ if (!empty($title)) {
+ $mform->addElement('header', 'pageheader', $title);
+ }
+
+ if (!empty($contents)) {
+ $mform->addElement('html', $OUTPUT->box($contents, 'contents'));
+ }
+
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'pageid');
$mform->setType('pageid', PARAM_INT);
+ $mform->addElement('hidden', 'newpageid');
+ $mform->setType('newpageid', PARAM_INT);
+
$this->add_action_buttons(null, get_string("continue", "lesson"));
}

0 comments on commit 1c510e2

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