From b738d41b80f0673fba427d0452579bfd652734d3 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Tue, 29 Jun 2010 03:23:38 +0000 Subject: [PATCH] MDL-22688, fixed branch table page type and added contentsformat field to lesson_pages table --- mod/lesson/db/install.xml | 5 +++-- mod/lesson/db/upgrade.php | 15 +++++++++++++++ mod/lesson/edit.php | 2 +- mod/lesson/editpage.php | 2 +- mod/lesson/lib.php | 13 ++++++++++--- mod/lesson/pagetypes/branchtable.php | 7 ++++++- mod/lesson/version.php | 2 +- mod/lesson/view.php | 9 ++++----- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/mod/lesson/db/install.xml b/mod/lesson/db/install.xml index e8fe5983801..8f884ef5bb0 100644 --- a/mod/lesson/db/install.xml +++ b/mod/lesson/db/install.xml @@ -1,5 +1,5 @@ - @@ -67,7 +67,8 @@ - + + diff --git a/mod/lesson/db/upgrade.php b/mod/lesson/db/upgrade.php index 2b825cf5282..3c98111bf6e 100644 --- a/mod/lesson/db/upgrade.php +++ b/mod/lesson/db/upgrade.php @@ -156,6 +156,21 @@ function xmldb_lesson_upgrade($oldversion) { $dbman->drop_table($table); upgrade_mod_savepoint($result, 2009120800, 'lesson'); } + if ($result && $oldversion < 2009120801) { + + /// Define field contentsformat to be added to lesson_pages + $table = new xmldb_table('lesson_pages'); + $field = new xmldb_field('contentsformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'contents'); + + /// Conditionally launch add field contentsformat + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// lesson savepoint reached + upgrade_mod_savepoint($result, 2009120801, 'lesson'); + } + return $result; } diff --git a/mod/lesson/edit.php b/mod/lesson/edit.php index 54d52d20352..968ce8d6ba1 100644 --- a/mod/lesson/edit.php +++ b/mod/lesson/edit.php @@ -69,4 +69,4 @@ if (!$lesson->has_pages()) { } } -echo $lessonoutput->footer(); \ No newline at end of file +echo $lessonoutput->footer(); diff --git a/mod/lesson/editpage.php b/mod/lesson/editpage.php index 8692d2166a2..3df3c784472 100644 --- a/mod/lesson/editpage.php +++ b/mod/lesson/editpage.php @@ -101,4 +101,4 @@ if ($data = $mform->get_data()) { $lessonoutput = $PAGE->get_renderer('mod_lesson'); echo $lessonoutput->header($lesson, $cm); $mform->display(); -echo $lessonoutput->footer(); \ No newline at end of file +echo $lessonoutput->footer(); diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 5075b3767a7..b38a2228008 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -2007,7 +2007,8 @@ 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) { - print_error('cannotfindanswer', 'lesson'); + debugging(get_string('cannotfindanswer', 'lesson')); + return array(); } foreach ($answers as $answer) { $this->answers[count($this->answers)] = new lesson_page_answer($answer); @@ -2233,14 +2234,20 @@ abstract class lesson_page extends lesson_base { * @param object $properties * @return bool */ - public function update($properties,$context, $maxbytes) { - global $DB; + public function update($properties, $context = null, $maxbytes = null) { + global $DB, $PAGE; $answers = $this->get_answers(); $properties->id = $this->properties->id; $properties->lessonid = $this->lesson->id; if (empty($properties->qoption)) { $properties->qoption = '0'; } + if (empty($context)) { + $context = $PAGE->context; + } + if ($maxbytes === null) { + $maxbytes =get_max_upload_file_size(); + } $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$maxbytes), $context, 'lesson_page_contents', $properties->id); $DB->update_record("lesson_pages", $properties); diff --git a/mod/lesson/pagetypes/branchtable.php b/mod/lesson/pagetypes/branchtable.php index c39d03e9204..ccd4fad7cf1 100644 --- a/mod/lesson/pagetypes/branchtable.php +++ b/mod/lesson/pagetypes/branchtable.php @@ -270,6 +270,7 @@ class lesson_add_page_form_branchtable extends lesson_add_page_form_base { $mform->addElement('text', 'title', get_string("pagetitle", "lesson"), array('size'=>70)); $mform->setType('title', PARAM_TEXT); + $mform->addRule('title', null, 'required', null, 'server'); $this->editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes); $mform->addElement('editor', 'contents_editor', get_string("pagecontents", "lesson"), null, $this->editoroptions); @@ -285,6 +286,10 @@ class lesson_add_page_form_branchtable extends lesson_add_page_form_base { $mform->addElement('header', 'headeranswer'.$i, get_string('branch', 'lesson').' '.($i+1)); $mform->addElement('textarea', 'answer['.$i.']', get_string("description", "lesson"), array('rows'=>10, 'cols'=>70, 'width'=>630, 'height'=>300)); $mform->setType('answer['.$i.']', PARAM_CLEANHTML); + if ($i == 0) { + // we should have one required branch + $mform->addRule('answer['.$i.']', null, 'required', null, 'server'); + } $mform->addElement('select', 'jumpto['.$i.']', get_string("jump", "lesson"), $jumptooptions); if ($i === 0) { @@ -294,4 +299,4 @@ class lesson_add_page_form_branchtable extends lesson_add_page_form_base { } } } -} \ No newline at end of file +} diff --git a/mod/lesson/version.php b/mod/lesson/version.php index 57a8ec790b3..73de706a740 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -24,7 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late **/ -$module->version = 2009120800; // The current module version (Date: YYYYMMDDXX) +$module->version = 2009120801; // The current module version (Date: YYYYMMDDXX) $module->requires = 2008072401; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 5512812f683..18054a2afcf 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -354,14 +354,13 @@ if ($pageid != LESSON_EOL) { } $lessoncontent = $lessonoutput->display_page($lesson, $page, $attempt); } else { - - $nextpage = $lesson->get_next_page($page->nextpageid); - $data = new stdClass; $data->id = $PAGE->cm->id; - $data->newpageid = $nextpage->id; + if ($nextpage = $lesson->get_next_page($page->nextpageid)) { + $data->newpageid = $nextpage->id; + } - $mform = lesson_page_without_answers(); + $mform = new lesson_page_without_answers(); $mform->set_data($data); ob_start(); $mform->display();