From d3ce7c2cc76b6812a4e3d1cfa7b1bf3a082d9beb Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Mon, 3 May 2010 23:18:33 +0000 Subject: [PATCH] MDL-22151 backup - glossary implemented --- .../backup_glossary_activity_task.class.php | 67 +++++++++ .../moodle2/backup_glossary_stepslib.php | 128 ++++++++++++++++++ mod/glossary/lib.php | 1 + 3 files changed, 196 insertions(+) create mode 100644 mod/glossary/backup/moodle2/backup_glossary_activity_task.class.php create mode 100644 mod/glossary/backup/moodle2/backup_glossary_stepslib.php diff --git a/mod/glossary/backup/moodle2/backup_glossary_activity_task.class.php b/mod/glossary/backup/moodle2/backup_glossary_activity_task.class.php new file mode 100644 index 00000000000..b57fbb8593a --- /dev/null +++ b/mod/glossary/backup/moodle2/backup_glossary_activity_task.class.php @@ -0,0 +1,67 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once($CFG->dirroot . '/mod/glossary/backup/moodle2/backup_glossary_stepslib.php'); // Because it exists (must) + +/** + * glossary backup task that provides all the settings and steps to perform one + * complete backup of the activity + */ +class backup_glossary_activity_task extends backup_activity_task { + + /** + * Define (add) particular settings this activity can have + */ + protected function define_my_settings() { + // No particular settings for this activity + } + + /** + * Define (add) particular steps this activity can have + */ + protected function define_my_steps() { + // Choice only has one structure step + $this->add_step(new backup_glossary_activity_structure_step('glossary_structure', 'glossary.xml')); + } + + /** + * Code the transformations to perform in the activity in + * order to get transportable (encoded) links + */ + static public function encode_content_links($content) { + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + // Link to the list of glossaries + $search="/(".$base."\/mod\/glossary\/index.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@GLOSSARYINDEX*$2@$', $content); + + // Link to glossary view by moduleid + $search="/(".$base."\/mod\/glossary\/view.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@GLOSSARYVIEWBYID*$2@$', $content); + + return $content; + } +} diff --git a/mod/glossary/backup/moodle2/backup_glossary_stepslib.php b/mod/glossary/backup/moodle2/backup_glossary_stepslib.php new file mode 100644 index 00000000000..ac9652c3055 --- /dev/null +++ b/mod/glossary/backup/moodle2/backup_glossary_stepslib.php @@ -0,0 +1,128 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Define all the backup steps that will be used by the backup_glossary_activity_task + */ + +/** + * Define the complete glossary structure for backup, with file and id annotations + */ +class backup_glossary_activity_structure_step extends backup_activity_structure_step { + + protected function define_structure() { + + // To know if we are including userinfo + $userinfo = $this->get_setting_value('userinfo'); + + // Define each element separated + $glossary = new backup_nested_element('glossary', array('id'), array( + 'name', 'intro', 'allowduplicatedentries', 'displayformat', + 'mainglossary', 'showspecial', 'showalphabet', 'showall', + 'allowcomments', 'allowprintview', 'usedynalink', 'defaultapproval', + 'globalglossary', 'entbypage', 'editalways', 'rsstype', + 'rssarticles', 'assessed', 'assesstimestart', 'assesstimefinish', + 'scale', 'timecreated', 'timemodified')); + + $entries = new backup_nested_element('entries'); + + $entry = new backup_nested_element('entry', array('id'), array( + 'userid', 'concept', 'definition', 'definitionformat', + 'definitiontrust', 'attachment', 'timecreated', 'timemodified', + 'teacherentry', 'sourceglossaryid', 'usedynalink', 'casesensitive', + 'fullmatch', 'approved')); + + $aliases = new backup_nested_element('aliases'); + + $alias = new backup_nested_element('alias', array('id'), array( + 'alias_text')); + + $ratings = new backup_nested_element('ratings'); + + $rating = new backup_nested_element('rating', array('id'), array( + 'scaleid', 'value', 'userid', 'timecreated', 'timemodified')); + + $categories = new backup_nested_element('categories'); + + $category = new backup_nested_element('category', array('id'), array( + 'name', 'usedynalink')); + + $categoryentries = new backup_nested_element('category_entries'); + + $categoryentry = new backup_nested_element('category_entry', array('id'), array( + 'entryid')); + + // Build the tree + $glossary->add_child($entries); + $entries->add_child($entry); + + $entry->add_child($aliases); + $aliases->add_child($alias); + + $entry->add_child($ratings); + $ratings->add_child($rating); + + $glossary->add_child($categories); + $categories->add_child($category); + + $category->add_child($categoryentries); + $categoryentries->add_child($categoryentry); + + // Define sources + $glossary->set_source_table('glossary', array('id' => backup::VAR_ACTIVITYID)); + + $category->set_source_table('glossary_categories', array('glossaryid' => backup::VAR_PARENTID)); + + // All the rest of elements only happen if we are including user info + if ($userinfo) { + $entry->set_source_table('glossary_entries', array('glossaryid' => backup::VAR_PARENTID)); + + $alias->set_source_table('glossary_alias', array('entryid' => backup::VAR_PARENTID)); + $alias->set_source_alias('alias', 'alias_text'); + + $rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID, + 'itemid' => backup::VAR_PARENTID)); + $rating->set_source_alias('rating', 'value'); + + $categoryentry->set_source_table('glossary_entries_categories', array('categoryid' => backup::VAR_PARENTID)); + } + + // Define id annotations + $glossary->annotate_ids('scale', 'scale'); + + $entry->annotate_ids('user', 'userid'); + + $rating->annotate_ids('scale', 'scaleid'); + + $rating->annotate_ids('user', 'userid'); + + // Define file annotations + $glossary->annotate_files(array('glossary_intro'), null); // This file area hasn't itemid + + $entry->annotate_files(array('glossary_entry', 'glossary_attachment'), 'id'); + + // Return the root element (glossary), wrapped into standard activity structure + return $this->prepare_activity_structure($glossary); + } +} diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index c9af965cff6..9643e17e4b8 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -2560,6 +2560,7 @@ function glossary_supports($feature) { case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; case FEATURE_RATE: return true; + case FEATURE_BACKUP_MOODLE2: return true; default: return null; }