mod-lesson MDL-25632 Added support for displaying and progressing through a question...
authorSam Hemelryk <sam@moodle.com>
Tue, 14 Dec 2010 07:06:08 +0000 (15:06 +0800)
committerSam Hemelryk <sam@moodle.com>
Wed, 15 Dec 2010 05:12:33 +0000 (13:12 +0800)
mod/lesson/continue.php
mod/lesson/locallib.php
mod/lesson/view.php
mod/lesson/view_form.php

index b9e3634..49528e7 100644 (file)
@@ -67,7 +67,16 @@ if (!$canmanage) {
 
 // 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
index 4ca3623..a9123ac 100644 (file)
@@ -1881,7 +1881,9 @@ abstract class lesson_page extends lesson_base {
             $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) {
index 9889dc9..34b96a5 100644 (file)
@@ -359,11 +359,17 @@ if ($pageid != LESSON_EOL) {
     } 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();
index df8b7e1..f7c108a 100644 (file)
@@ -41,15 +41,30 @@ require_once($CFG->libdir.'/formslib.php');
 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"));
 
     }