From 9b553d472ebffeeecc992b9425910142462e8767 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 8 Nov 2011 16:25:58 +0100 Subject: [PATCH] MDL-29793 Advanced grading forms attached to activity modules are included in the backup now --- backup/moodle2/backup_activity_task.class.php | 3 + .../backup_gradingform_plugin.class.php | 32 +++++ backup/moodle2/backup_plan_builder.class.php | 1 + backup/moodle2/backup_stepslib.php | 71 +++++++++++ ...backup_gradingform_rubric_plugin.class.php | 117 ++++++++++++++++++ 5 files changed, 224 insertions(+) create mode 100644 backup/moodle2/backup_gradingform_plugin.class.php create mode 100644 grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php diff --git a/backup/moodle2/backup_activity_task.class.php b/backup/moodle2/backup_activity_task.class.php index f9a14d4b6c0..f3a22b70b79 100644 --- a/backup/moodle2/backup_activity_task.class.php +++ b/backup/moodle2/backup_activity_task.class.php @@ -148,6 +148,9 @@ abstract class backup_activity_task extends backup_task { // Generate the grades file $this->add_step(new backup_activity_grades_structure_step('activity_grades', 'grades.xml')); + // Generate the grading file (conditionally) + $this->add_step(new backup_activity_grading_structure_step('activity_grading', 'grading.xml')); + // Annotate the scales used in already annotated outcomes $this->add_step(new backup_annotate_scales_from_outcomes('annotate_scales')); diff --git a/backup/moodle2/backup_gradingform_plugin.class.php b/backup/moodle2/backup_gradingform_plugin.class.php new file mode 100644 index 00000000000..a06412a5466 --- /dev/null +++ b/backup/moodle2/backup_gradingform_plugin.class.php @@ -0,0 +1,32 @@ +. + +/** + * @package core + * @subpackage backup-moodle2 + * @copyright 2011 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Base class for all advanced grading form plugins + */ +abstract class backup_gradingform_plugin extends backup_plugin { + +} diff --git a/backup/moodle2/backup_plan_builder.class.php b/backup/moodle2/backup_plan_builder.class.php index 3f661835b1e..d2b7d62f2bb 100644 --- a/backup/moodle2/backup_plan_builder.class.php +++ b/backup/moodle2/backup_plan_builder.class.php @@ -34,6 +34,7 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_default_block_task.class.ph require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php'); +require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php'); diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 987bb9fa197..8e47dbabc7d 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -1780,6 +1780,77 @@ class backup_annotate_all_user_files extends backup_execution_step { } } + +/** + * Defines the backup step for advanced grading methods attached to the activity module + */ +class backup_activity_grading_structure_step extends backup_structure_step { + + /** + * Include the grading.xml only if the module supports advanced grading + */ + protected function execute_condition() { + return plugin_supports('mod', $this->get_task()->get_modulename(), FEATURE_ADVANCED_GRADING, false); + } + + /** + * Declares the gradable areas structures and data sources + */ + protected function define_structure() { + + // To know if we are including userinfo + $userinfo = $this->get_setting_value('userinfo'); + + // Define the elements + + $areas = new backup_nested_element('areas'); + + $area = new backup_nested_element('area', array('id'), array( + 'areaname', 'activemethod')); + + $definitions = new backup_nested_element('definitions'); + + $definition = new backup_nested_element('definition', array('id'), array( + 'method', 'name', 'description', 'descriptionformat', 'status', + 'timecreated', 'timemodified', 'options')); + + $instances = new backup_nested_element('instances'); + + $instance = new backup_nested_element('instance', array('id'), array( + 'raterid', 'itemid', 'rawgrade', 'status', 'feedback', + 'feedbackformat', 'timemodified')); + + // Build the tree including the method specific structures + // (beware - the order of how gradingform plugins structures are attached is important) + $areas->add_child($area); + $area->add_child($definitions); + $definitions->add_child($definition); + $this->add_plugin_structure('gradingform', $definition, true); + $definition->add_child($instances); + $instances->add_child($instance); + $this->add_plugin_structure('gradingform', $instance, false); + + // Define data sources + + $area->set_source_table('grading_areas', array('contextid' => backup::VAR_CONTEXTID, + 'component' => array('sqlparam' => 'mod_'.$this->get_task()->get_modulename()))); + + $definition->set_source_table('grading_definitions', array('areaid' => backup::VAR_PARENTID)); + + if ($userinfo) { + $instance->set_source_table('grading_instances', array('formid' => backup::VAR_PARENTID)); + } + + // Annotate references + $definition->annotate_files('grading', 'description', 'id'); + $instance->annotate_ids('user', 'raterid'); + + // Return the root element + return $areas; + } +} + + /** * structure step in charge of constructing the grades.xml file for all the grade items * and letters related to one activity diff --git a/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php new file mode 100644 index 00000000000..92db764bd2e --- /dev/null +++ b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php @@ -0,0 +1,117 @@ +. + +/** + * Support for backup API + * + * @package gradingform + * @subpackage rubric + * @copyright 2011 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Defines rubric backup structures + */ +class backup_gradingform_rubric_plugin extends backup_gradingform_plugin { + + /** + * Declares rubric structures to append to the grading form definition + */ + protected function define_definition_plugin_structure() { + + // Append data only if the grand-parent element has 'method' set to 'rubric' + $plugin = $this->get_plugin_element(null, '../../method', 'rubric'); + + // Create a visible container for our data + $pluginwrapper = new backup_nested_element($this->get_recommended_name()); + + // Connect our visible container to the parent + $plugin->add_child($pluginwrapper); + + // Define our elements + + $criteria = new backup_nested_element('criteria'); + + $criterion = new backup_nested_element('criterion', array('id'), array( + 'sortorder', 'description', 'descriptionformat')); + + $levels = new backup_nested_element('levels'); + + $level = new backup_nested_element('level', array('id'), array( + 'score', 'definition', 'definitionformat')); + + // Build elements hierarchy + + $pluginwrapper->add_child($criteria); + $criteria->add_child($criterion); + $criterion->add_child($levels); + $levels->add_child($level); + + // Set sources to populate the data + + $criterion->set_source_table('gradingform_rubric_criteria', + array('formid' => backup::VAR_PARENTID)); + + $level->set_source_table('gradingform_rubric_levels', + array('criterionid' => backup::VAR_PARENTID)); + + // no need to annotate ids or files yet (one day when criterion definition supports + // embedded files, they must be annotated here) + + return $plugin; + } + + /** + * Declares rubric structures to append to the grading form instances + */ + protected function define_instance_plugin_structure() { + + // Append data only if the ancestor 'definition' element has 'method' set to 'rubric' + $plugin = $this->get_plugin_element(null, '../../../../method', 'rubric'); + + // Create a visible container for our data + $pluginwrapper = new backup_nested_element($this->get_recommended_name()); + + // Connect our visible container to the parent + $plugin->add_child($pluginwrapper); + + // Define our elements + + $fillings = new backup_nested_element('fillings'); + + $filling = new backup_nested_element('filling', array('id'), array( + 'criterionid', 'levelid', 'remark', 'remarkformat')); + + // Build elements hierarchy + + $pluginwrapper->add_child($fillings); + $fillings->add_child($filling); + + // Set sources to populate the data + + $filling->set_source_table('gradingform_rubric_fillings', + array('forminstanceid' => backup::VAR_PARENTID)); + + // no need to annotate ids or files yet (one day when remark field supports + // embedded fileds, they must be annotated here) + + return $plugin; + } +} -- 2.39.2