From c119057ae08bdf096c56fef100d30d9218d87048 Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 20 Apr 2009 18:28:49 +0000 Subject: [PATCH] MDL-18910 normalised module intro and introformat --- mod/assignment/backuplib.php | 4 ++-- mod/assignment/db/install.xml | 14 +++++++------- mod/assignment/db/upgrade.php | 26 ++++++++++++++++++++++++++ mod/assignment/grade.php | 2 +- mod/assignment/lib.php | 10 +++++----- mod/assignment/mod_form.php | 8 ++++---- mod/assignment/restorelib.php | 12 ++++++------ mod/assignment/type/online/all.php | 2 +- mod/assignment/version.php | 4 ++-- 9 files changed, 54 insertions(+), 28 deletions(-) diff --git a/mod/assignment/backuplib.php b/mod/assignment/backuplib.php index ce963d6e46..06f24a94f5 100644 --- a/mod/assignment/backuplib.php +++ b/mod/assignment/backuplib.php @@ -55,8 +55,8 @@ fwrite ($bf,full_tag("ID",4,false,$assignment->id)); fwrite ($bf,full_tag("MODTYPE",4,false,"assignment")); fwrite ($bf,full_tag("NAME",4,false,$assignment->name)); - fwrite ($bf,full_tag("DESCRIPTION",4,false,$assignment->description)); - fwrite ($bf,full_tag("FORMAT",4,false,$assignment->format)); + fwrite ($bf,full_tag("DESCRIPTION",4,false,$assignment->intro)); + fwrite ($bf,full_tag("FORMAT",4,false,$assignment->introformat)); fwrite ($bf,full_tag("RESUBMIT",4,false,$assignment->resubmit)); fwrite ($bf,full_tag("PREVENTLATE",4,false,$assignment->preventlate)); fwrite ($bf,full_tag("EMAILTEACHERS",4,false,$assignment->emailteachers)); diff --git a/mod/assignment/db/install.xml b/mod/assignment/db/install.xml index 467ec70abb..327007c1dc 100644 --- a/mod/assignment/db/install.xml +++ b/mod/assignment/db/install.xml @@ -1,5 +1,5 @@ - @@ -8,10 +8,10 @@ - - - - + + + + @@ -27,7 +27,7 @@ - + @@ -61,4 +61,4 @@ - + \ No newline at end of file diff --git a/mod/assignment/db/upgrade.php b/mod/assignment/db/upgrade.php index 81fedf5f4a..6d01ab6ac0 100644 --- a/mod/assignment/db/upgrade.php +++ b/mod/assignment/db/upgrade.php @@ -132,6 +132,32 @@ function xmldb_assignment_upgrade($oldversion) { upgrade_mod_savepoint($result, 2008081900, 'assignment'); } + if ($result && $oldversion < 2009042000) { + + /// Rename field description on table assignment to intro + $table = new xmldb_table('assignment'); + $field = new xmldb_field('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'name'); + + /// Launch rename field description + $dbman->rename_field($table, $field, 'intro'); + + /// assignment savepoint reached + upgrade_mod_savepoint($result, 2009042000, 'assignment'); + } + + if ($result && $oldversion < 2009042001) { + + /// Rename field format on table assignment to introformat + $table = new xmldb_table('assignment'); + $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'description'); + + /// Launch rename field format + $dbman->rename_field($table, $field, 'introformat'); + + /// assignment savepoint reached + upgrade_mod_savepoint($result, 2009042001, 'assignment'); + } + return $result; } diff --git a/mod/assignment/grade.php b/mod/assignment/grade.php index 4bb2cb313b..ccc0655696 100644 --- a/mod/assignment/grade.php +++ b/mod/assignment/grade.php @@ -16,7 +16,7 @@ print_error('coursemisconf', 'assignment'); } - require_login($course->id, false, $cm); + require_login($course, false, $cm); if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) { redirect('submissions.php?id='.$cm->id); diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 8d5c2ff430..28a143d57c 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -162,7 +162,7 @@ class assignment_base { print_simple_box_start('center', '', '', 0, 'generalbox', 'intro'); $formatoptions = new stdClass; $formatoptions->noclean = true; - echo format_text($this->assignment->description, $this->assignment->format, $formatoptions); + echo format_text($this->assignment->intro, $this->assignment->introformat, $formatoptions); print_simple_box_end(); } @@ -358,7 +358,7 @@ class assignment_base { if ($assignment->timedue) { $event = new object(); $event->name = $assignment->name; - $event->description = $assignment->description; + $event->description = $assignment->intro; $event->courseid = $assignment->course; $event->groupid = 0; $event->userid = 0; @@ -447,14 +447,14 @@ class assignment_base { if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { $event->name = $assignment->name; - $event->description = $assignment->description; + $event->description = $assignment->intro; $event->timestart = $assignment->timedue; update_event($event); } else { $event = new object(); $event->name = $assignment->name; - $event->description = $assignment->description; + $event->description = $assignment->intro; $event->courseid = $assignment->course; $event->groupid = 0; $event->userid = 0; @@ -2431,7 +2431,7 @@ function assignment_refresh_events($courseid = 0) { foreach ($assignments as $assignment) { $event = NULL; $event->name = $assignment->name; - $event->description = $assignment->description; + $event->description = $assignment->intro; $event->timestart = $assignment->timedue; if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index 3d84e3acb9..be17f2b437 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -39,10 +39,10 @@ class mod_assignment_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); - $mform->addElement('htmleditor', 'description', get_string('description', 'assignment')); - $mform->setType('description', PARAM_RAW); - $mform->setHelpButton('description', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); - $mform->addRule('description', get_string('required'), 'required', null, 'client'); + $mform->addElement('htmleditor', 'intro', get_string('description', 'assignment')); + $mform->setType('intro', PARAM_RAW); + $mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); + $mform->addRule('intro', get_string('required'), 'required', null, 'client'); $mform->addElement('modgrade', 'grade', get_string('grade')); $mform->setDefault('grade', 100); diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php index 3939800778..370d6ab95d 100644 --- a/mod/assignment/restorelib.php +++ b/mod/assignment/restorelib.php @@ -44,8 +44,8 @@ //Now, build the ASSIGNMENT record structure $assignment->course = $restore->course_id; $assignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); - $assignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']); - $assignment->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']); + $assignment->intro = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']); + $assignment->introformat = backup_todb($info['MOD']['#']['FORMAT']['0']['#']); $assignment->resubmit = backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']); $assignment->preventlate = backup_todb($info['MOD']['#']['PREVENTLATE']['0']['#']); $assignment->emailteachers = backup_todb($info['MOD']['#']['EMAILTEACHERS']['0']['#']); @@ -372,7 +372,7 @@ $status = true; //Convert assignment->description - if ($records = $DB->get_records_sql ("SELECT a.id, a.description, a.format + if ($records = $DB->get_records_sql ("SELECT a.id, a.intro, a.introformat FROM {assignment} a, {backup_ids} b WHERE a.course = ? AND a.format = ".FORMAT_WIKI. " AND @@ -381,11 +381,11 @@ b.new_id = a.id", array($restore->course_id, $restore->backup_unique_code))) { foreach ($records as $record) { //Rebuild wiki links - $record->description = restore_decode_wiki_content($record->description, $restore); + $record->intro = restore_decode_wiki_content($record->intro, $restore); //Convert to Markdown $wtm = new WikiToMarkdown(); - $record->description = $wtm->convert($record->description, $restore->course_id); - $record->format = FORMAT_MARKDOWN; + $record->intro = $wtm->convert($record->intro, $restore->course_id); + $record->introformat = FORMAT_MARKDOWN; $status = $DB->update_record('assignment', $record); //Do some output $i++; diff --git a/mod/assignment/type/online/all.php b/mod/assignment/type/online/all.php index 5394de8428..8e1500a860 100644 --- a/mod/assignment/type/online/all.php +++ b/mod/assignment/type/online/all.php @@ -121,7 +121,7 @@ $view->name = $assignment->name; $view->submitted = $submitted; - $view->description = format_text( $assignment->description, $assignment->format, $formatoptions ); + $view->description = format_text( $assignment->intro, $assignment->introformat, $formatoptions ); $view->editlink = $editlink; $view->submissiontext = $submissiontext; $view->submissiondate = $submissiondate; diff --git a/mod/assignment/version.php b/mod/assignment/version.php index 258e0a7dc4..b00df242e4 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2008081900; -$module->requires = 2008080701; // Requires this Moodle version +$module->version = 2009042001; +$module->requires = 2009041700; // Requires this Moodle version $module->cron = 60; ?> -- 2.39.5