From a8801a8bea76b8741209d2185be5bc20e7b5de7c Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 20 Apr 2009 18:45:31 +0000 Subject: [PATCH] MDL-18910 normalised module intro and introformat --- mod/choice/backuplib.php | 4 ++-- mod/choice/db/install.xml | 17 ++++++++++------- mod/choice/db/upgrade.php | 26 ++++++++++++++++++++++++++ mod/choice/mod_form.php | 10 +++++----- mod/choice/restorelib.php | 12 ++++++------ mod/choice/version.php | 4 ++-- mod/choice/view.php | 5 +++-- 7 files changed, 54 insertions(+), 24 deletions(-) diff --git a/mod/choice/backuplib.php b/mod/choice/backuplib.php index 2b1439894d..ec2d7b7760 100644 --- a/mod/choice/backuplib.php +++ b/mod/choice/backuplib.php @@ -60,8 +60,8 @@ fwrite ($bf,full_tag("ID",4,false,$choice->id)); fwrite ($bf,full_tag("MODTYPE",4,false,"choice")); fwrite ($bf,full_tag("NAME",4,false,$choice->name)); - fwrite ($bf,full_tag("TEXT",4,false,$choice->text)); - fwrite ($bf,full_tag("FORMAT",4,false,$choice->format)); + fwrite ($bf,full_tag("TEXT",4,false,$choice->intro)); + fwrite ($bf,full_tag("FORMAT",4,false,$choice->introformat)); fwrite ($bf,full_tag("PUBLISH",4,false,$choice->publish)); fwrite ($bf,full_tag("SHOWRESULTS",4,false,$choice->showresults)); fwrite ($bf,full_tag("DISPLAY",4,false,$choice->display)); diff --git a/mod/choice/db/install.xml b/mod/choice/db/install.xml index f0d47f28d0..b6f1889f34 100644 --- a/mod/choice/db/install.xml +++ b/mod/choice/db/install.xml @@ -1,14 +1,17 @@ - + - - - - + + + + @@ -19,7 +22,7 @@ - + @@ -56,4 +59,4 @@
-
+
\ No newline at end of file diff --git a/mod/choice/db/upgrade.php b/mod/choice/db/upgrade.php index e57af61959..de45eccfcc 100644 --- a/mod/choice/db/upgrade.php +++ b/mod/choice/db/upgrade.php @@ -28,6 +28,32 @@ function xmldb_choice_upgrade($oldversion) { //===== 1.9.0 upgrade line ======// + if ($result && $oldversion < 2009042000) { + + /// Rename field text on table choice to NEWNAMEGOESHERE + $table = new xmldb_table('choice'); + $field = new xmldb_field('text', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'name'); + + /// Launch rename field text + $dbman->rename_field($table, $field, 'intro'); + + /// choice savepoint reached + upgrade_mod_savepoint($result, 2009042000, 'choice'); + } + + if ($result && $oldversion < 2009042001) { + + /// Rename field format on table choice to NEWNAMEGOESHERE + $table = new xmldb_table('choice'); + $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'text'); + + /// Launch rename field format + $dbman->rename_field($table, $field, 'introformat'); + + /// choice savepoint reached + upgrade_mod_savepoint($result, 2009042001, 'choice'); + } + return $result; } diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index bf19b4f78e..d54ef3e9b2 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -19,12 +19,12 @@ class mod_choice_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); - $mform->addElement('htmleditor', 'text', get_string('choicetext', 'choice')); - $mform->setType('text', PARAM_RAW); - $mform->addRule('text', null, 'required', null, 'client'); - $mform->setHelpButton('text', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); + $mform->addElement('htmleditor', 'intro', get_string('choicetext', 'choice')); + $mform->setType('intro', PARAM_RAW); + $mform->addRule('intro', null, 'required', null, 'client'); + $mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); - $mform->addElement('format', 'format', get_string('format')); + $mform->addElement('format', 'introformat', get_string('format')); //------------------------------------------------------------------------------- $repeatarray=array(); diff --git a/mod/choice/restorelib.php b/mod/choice/restorelib.php index f137efc74f..3249c097e1 100644 --- a/mod/choice/restorelib.php +++ b/mod/choice/restorelib.php @@ -49,8 +49,8 @@ //Now, build the CHOICE record structure $choice->course = $restore->course_id; $choice->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); - $choice->text = backup_todb($info['MOD']['#']['TEXT']['0']['#']); - $choice->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']); + $choice->intro = backup_todb($info['MOD']['#']['TEXT']['0']['#']); + $choice->introformat = backup_todb($info['MOD']['#']['FORMAT']['0']['#']); $choice->publish = backup_todb($info['MOD']['#']['PUBLISH']['0']['#']); $choice->showresults = isset($info['MOD']['#']['SHOWRESULTS']['0']['#'])?backup_todb($info['MOD']['#']['SHOWRESULTS']['0']['#']):''; $choice->display = backup_todb($info['MOD']['#']['DISPLAY']['0']['#']); @@ -376,7 +376,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) { $status = true; //Convert choice->text - if ($records = $DB->get_records_sql("SELECT c.id, c.text, c.format + if ($records = $DB->get_records_sql("SELECT c.id, c.intro, c.introformat FROM {choice} c, {backup_ids} b WHERE c.course = ? AND c.format = ".FORMAT_WIKI. " AND @@ -385,11 +385,11 @@ function choice_options_restore_mods($choiceid,$info,$restore) { b.new_id = c.id", array($restore->course_id, $restore->backup_unique_code))) { foreach ($records as $record) { //Rebuild wiki links - $record->text = restore_decode_wiki_content($record->text, $restore); + $record->intro = restore_decode_wiki_content($record->intro, $restore); //Convert to Markdown $wtm = new WikiToMarkdown(); - $record->text = $wtm->convert($record->text, $restore->course_id); - $record->format = FORMAT_MARKDOWN; + $record->intro = $wtm->convert($record->intro, $restore->course_id); + $record->introformat = FORMAT_MARKDOWN; $status = $DB->update_record('choice', $record); //Do some output $i++; diff --git a/mod/choice/version.php b/mod/choice/version.php index 51a67c370c..dfebaf1e04 100644 --- a/mod/choice/version.php +++ b/mod/choice/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007101509; -$module->requires = 2007101509; // Requires this Moodle version +$module->version = 2009042001; +$module->requires = 2009041700; // Requires this Moodle version $module->cron = 0; ?> diff --git a/mod/choice/view.php b/mod/choice/view.php index 3c8b4decf1..e93feb7b5b 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -78,8 +78,9 @@ echo '
'; - if ($choice->text) { - print_box(format_text($choice->text, $choice->format), 'generalbox', 'intro'); + if ($choice->intro) { + $options = (object)array('noclean'=>true); + print_box(format_text($choice->intro, $choice->introformat, $options), 'generalbox', 'intro'); } $current = false; // Initialise for later -- 2.39.5