mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-57455 mod_data: Implement tagging
This commit is contained in:
parent
d8e9a23c48
commit
ca5f3e0a2e
10 changed files with 407 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -42,6 +42,7 @@ class restore_data_activity_structure_step extends restore_activity_structure_st
|
|||
$paths[] = new restore_path_element('data_record', '/activity/data/records/record');
|
||||
$paths[] = new restore_path_element('data_content', '/activity/data/records/record/contents/content');
|
||||
$paths[] = new restore_path_element('data_rating', '/activity/data/records/record/ratings/rating');
|
||||
$paths[] = new restore_path_element('data_tag', '/activity/data/records/record/tags/tag');
|
||||
}
|
||||
|
||||
// Return the paths wrapped into standard activity structure
|
||||
|
@ -121,6 +122,25 @@ class restore_data_activity_structure_step extends restore_activity_structure_st
|
|||
$this->set_mapping('data_content', $oldid, $newitemid, true); // files by this itemname
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tags to restored records.
|
||||
*
|
||||
* @param stdClass $data Tag
|
||||
*/
|
||||
protected function process_data_tag($data) {
|
||||
$data = (object)$data;
|
||||
|
||||
if (!core_tag_tag::is_enabled('mod_data', 'data_records')) { // Tags disabled in server, nothing to process.
|
||||
return;
|
||||
}
|
||||
|
||||
$tag = $data->rawname;
|
||||
$itemid = $this->get_new_parentid('data_record');
|
||||
|
||||
$context = context_module::instance($this->task->get_moduleid());
|
||||
core_tag_tag::add_item_tag('mod_data', 'data_records', $itemid, $context, $tag);
|
||||
}
|
||||
|
||||
protected function process_data_rating($data) {
|
||||
global $DB;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue