MDL-57455 mod_data: Implement tagging
[moodle.git] / mod / data / backup / moodle2 / backup_data_stepslib.php
index 5a7f0ea..6140961 100644 (file)
@@ -47,6 +47,9 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
             'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort',
             'defaultsortdir', 'editany', 'notification', 'timemodified', 'config', 'completionentries'));
 
+        $tags = new backup_nested_element('tags');
+        $tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
+
         $fields = new backup_nested_element('fields');
 
         $field = new backup_nested_element('field', array('id'), array(
@@ -84,6 +87,9 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
         $record->add_child($ratings);
         $ratings->add_child($rating);
 
+        $record->add_child($tags);
+        $tags->add_child($tag);
+
         // Define sources
         $data->set_source_table('data', array('id' => backup::VAR_ACTIVITYID));
 
@@ -104,6 +110,16 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
                                                       'component'  => backup_helper::is_sqlparam('mod_data'),
                                                       'ratingarea' => backup_helper::is_sqlparam('entry')));
             $rating->set_source_alias('rating', 'value');
+            $tag->set_source_sql('SELECT t.id, t.name, t.rawname
+                                    FROM {tag} t
+                                    JOIN {tag_instance} ti
+                                      ON ti.tagid = t.id
+                                   WHERE ti.itemtype = ?
+                                     AND ti.component = ?
+                                     AND ti.itemid = ?', array(
+                backup_helper::is_sqlparam('data_records'),
+                backup_helper::is_sqlparam('mod_data'),
+                backup::VAR_PARENTID));
         }
 
         // Define id annotations