MDL-22688, fixed branch table page type and added contentsformat field to lesson_pages table

This commit is contained in:
Dongsheng Cai 2010-06-29 03:23:38 +00:00
parent 8397492bd0
commit b738d41b80
8 changed files with 41 additions and 14 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/lesson/db" VERSION="20091208" COMMENT="XMLDB file for Moodle mod/lesson"
<XMLDB PATH="mod/lesson/db" VERSION="20100629" COMMENT="XMLDB file for Moodle mod/lesson"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@ -67,7 +67,8 @@
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="display" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="title"/>
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="contents"/>
<FIELD NAME="contents" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="title"/>
<FIELD NAME="contents" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="title" NEXT="contentsformat"/>
<FIELD NAME="contentsformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="contents"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="lessonid"/>

View File

@ -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;
}

View File

@ -69,4 +69,4 @@ if (!$lesson->has_pages()) {
}
}
echo $lessonoutput->footer();
echo $lessonoutput->footer();

View File

@ -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();
echo $lessonoutput->footer();

View File

@ -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);

View File

@ -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 {
}
}
}
}
}

View File

@ -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)

View File

@ -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();