MDL-29793 Advanced grading forms attached to activity modules are included in the...
authorDavid Mudrak <david@moodle.com>
Tue, 8 Nov 2011 15:25:58 +0000 (16:25 +0100)
committerDavid Mudrak <david@moodle.com>
Tue, 8 Nov 2011 15:25:58 +0000 (16:25 +0100)
backup/moodle2/backup_activity_task.class.php
backup/moodle2/backup_gradingform_plugin.class.php [new file with mode: 0644]
backup/moodle2/backup_plan_builder.class.php
backup/moodle2/backup_stepslib.php
grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php [new file with mode: 0644]

index f9a14d4..f3a22b7 100644 (file)
@@ -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 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'));
 
         // 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 (file)
index 0000000..a06412a
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package    core
+ * @subpackage backup-moodle2
+ * @copyright  2011 David Mudrak <david@moodle.com>
+ * @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 {
+
+}
index 3f66183..d2b7d62 100644 (file)
@@ -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_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');
 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');
index 987bb9f..8e47dba 100644 (file)
@@ -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
 /**
  * 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 (file)
index 0000000..92db764
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Support for backup API
+ *
+ * @package    gradingform
+ * @subpackage rubric
+ * @copyright  2011 David Mudrak <david@moodle.com>
+ * @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;
+    }
+}