Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-22688, fixed branch table page type and added contentsformat fiel…
…d to lesson_pages table
  • Loading branch information
Dongsheng Cai committed Jun 29, 2010
1 parent 8397492 commit b738d41
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
5 changes: 3 additions & 2 deletions mod/lesson/db/install.xml
@@ -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"
>
Expand Down Expand Up @@ -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"/>
Expand Down
15 changes: 15 additions & 0 deletions mod/lesson/db/upgrade.php
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/edit.php
Expand Up @@ -69,4 +69,4 @@
}
}

echo $lessonoutput->footer();
echo $lessonoutput->footer();
2 changes: 1 addition & 1 deletion mod/lesson/editpage.php
Expand Up @@ -101,4 +101,4 @@
$lessonoutput = $PAGE->get_renderer('mod_lesson');
echo $lessonoutput->header($lesson, $cm);
$mform->display();
echo $lessonoutput->footer();
echo $lessonoutput->footer();
13 changes: 10 additions & 3 deletions mod/lesson/lib.php
Expand Up @@ -2007,7 +2007,8 @@ final public function get_answers() {
$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);
Expand Down Expand Up @@ -2233,14 +2234,20 @@ public function callback_on_view($canmanage) {
* @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);

Expand Down
7 changes: 6 additions & 1 deletion mod/lesson/pagetypes/branchtable.php
Expand Up @@ -270,6 +270,7 @@ public function custom_definition() {

$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);
Expand All @@ -285,6 +286,10 @@ public function custom_definition() {
$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) {
Expand All @@ -294,4 +299,4 @@ public function custom_definition() {
}
}
}
}
}
2 changes: 1 addition & 1 deletion mod/lesson/version.php
Expand Up @@ -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)

Expand Down
9 changes: 4 additions & 5 deletions mod/lesson/view.php
Expand Up @@ -354,14 +354,13 @@
}
$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();
Expand Down

0 comments on commit b738d41

Please sign in to comment.