mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-29793 Advanced grading forms attached to activity modules can be restored now
This commit is contained in:
parent
9b553d472e
commit
37065c2e06
@ -150,6 +150,9 @@ abstract class restore_activity_task extends restore_task {
|
|||||||
// Grades (module-related, rest of gradebook is restored later if possible: cats, calculations...)
|
// Grades (module-related, rest of gradebook is restored later if possible: cats, calculations...)
|
||||||
$this->add_step(new restore_activity_grades_structure_step('activity_grades', 'grades.xml'));
|
$this->add_step(new restore_activity_grades_structure_step('activity_grades', 'grades.xml'));
|
||||||
|
|
||||||
|
// Advanced grading methods attached to the module
|
||||||
|
$this->add_step(new restore_activity_grading_structure_step('activity_grading', 'grading.xml'));
|
||||||
|
|
||||||
// Userscompletion (conditionally)
|
// Userscompletion (conditionally)
|
||||||
if ($this->get_setting_value('userscompletion')) {
|
if ($this->get_setting_value('userscompletion')) {
|
||||||
$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
|
$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
|
||||||
|
42
backup/moodle2/restore_gradingform_plugin.class.php
Normal file
42
backup/moodle2/restore_gradingform_plugin.class.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?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 restore_gradingform_plugin extends restore_plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method returning the mapping identifierto use for
|
||||||
|
* grading form instance's itemid field
|
||||||
|
*
|
||||||
|
* @param array $areaname the name of the area the form is defined for
|
||||||
|
* @return string the mapping identifier
|
||||||
|
*/
|
||||||
|
public static function itemid_mapping($areaname) {
|
||||||
|
return 'grading_item_'.$areaname;
|
||||||
|
}
|
||||||
|
}
|
@ -37,12 +37,14 @@ require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php');
|
|||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.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_qtype_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/backup_format_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_theme_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php');
|
||||||
require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
|
require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
|
||||||
|
@ -1868,6 +1868,119 @@ class restore_activity_logs_structure_step extends restore_course_logs_structure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the restore step for advanced grading methods attached to the activity module
|
||||||
|
*/
|
||||||
|
class restore_activity_grading_structure_step extends restore_structure_step {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares paths in the grading.xml file we are interested in
|
||||||
|
*/
|
||||||
|
protected function define_structure() {
|
||||||
|
|
||||||
|
$paths = array();
|
||||||
|
$userinfo = $this->get_setting_value('userinfo');
|
||||||
|
|
||||||
|
$paths[] = new restore_path_element('grading_area', '/areas/area');
|
||||||
|
|
||||||
|
$definition = new restore_path_element('grading_definition', '/areas/area/definitions/definition');
|
||||||
|
$paths[] = $definition;
|
||||||
|
$this->add_plugin_structure('gradingform', $definition);
|
||||||
|
|
||||||
|
if ($userinfo) {
|
||||||
|
$instance = new restore_path_element('grading_instance',
|
||||||
|
'/areas/area/definitions/definition/instances/instance');
|
||||||
|
$paths[] = $instance;
|
||||||
|
$this->add_plugin_structure('gradingform', $instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes one grading area element
|
||||||
|
*
|
||||||
|
* @param array $data element data
|
||||||
|
*/
|
||||||
|
protected function process_grading_area($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$task = $this->get_task();
|
||||||
|
$data = (object)$data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
$data->component = 'mod_'.$task->get_modulename();
|
||||||
|
$data->contextid = $task->get_contextid();
|
||||||
|
|
||||||
|
$newid = $DB->insert_record('grading_areas', $data);
|
||||||
|
$this->set_mapping('grading_area', $oldid, $newid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes one grading definition element
|
||||||
|
*
|
||||||
|
* @param array $data element data
|
||||||
|
*/
|
||||||
|
protected function process_grading_definition($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$task = $this->get_task();
|
||||||
|
$data = (object)$data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
$data->areaid = $this->get_new_parentid('grading_area');
|
||||||
|
$data->copiedfromid = null;
|
||||||
|
$data->timecreated = time();
|
||||||
|
$data->usercreated = $task->get_userid();
|
||||||
|
$data->timemodified = $data->timecreated;
|
||||||
|
$data->usermodified = $data->usercreated;
|
||||||
|
|
||||||
|
$newid = $DB->insert_record('grading_definitions', $data);
|
||||||
|
$this->set_mapping('grading_definition', $oldid, $newid, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes one grading form instance element
|
||||||
|
*
|
||||||
|
* @param array $data element data
|
||||||
|
*/
|
||||||
|
protected function process_grading_instance($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object)$data;
|
||||||
|
|
||||||
|
// new form definition id
|
||||||
|
$newformid = $this->get_new_parentid('grading_definition');
|
||||||
|
|
||||||
|
// get the name of the area we are restoring to
|
||||||
|
$sql = "SELECT ga.areaname
|
||||||
|
FROM {grading_definitions} gd
|
||||||
|
JOIN {grading_areas} ga ON gd.areaid = ga.id
|
||||||
|
WHERE gd.id = ?";
|
||||||
|
$areaname = $DB->get_field_sql($sql, array($newformid), MUST_EXIST);
|
||||||
|
|
||||||
|
// get the mapped itemid - the activity module is expected to define the mappings
|
||||||
|
// for each gradable area
|
||||||
|
$newitemid = $this->get_mappingid(restore_gradingform_plugin::itemid_mapping($areaname), $data->itemid);
|
||||||
|
|
||||||
|
$oldid = $data->id;
|
||||||
|
$data->formid = $newformid;
|
||||||
|
$data->raterid = $this->get_mappingid('user', $data->raterid);
|
||||||
|
$data->itemid = $newitemid;
|
||||||
|
|
||||||
|
$newid = $DB->insert_record('grading_instances', $data);
|
||||||
|
$this->set_mapping('grading_instance', $oldid, $newid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Final operations when the database records are inserted
|
||||||
|
*/
|
||||||
|
protected function after_execute() {
|
||||||
|
// Add files embedded into the definition description
|
||||||
|
$this->add_related_files('grading', 'description', 'grading_definition');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This structure step restores the grade items associated with one activity
|
* This structure step restores the grade items associated with one activity
|
||||||
* All the grade items are made child of the "course" grade item but the original
|
* All the grade items are made child of the "course" grade item but the original
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
<?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 restore 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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores the rubric specific data from grading.xml file
|
||||||
|
*/
|
||||||
|
class restore_gradingform_rubric_plugin extends restore_gradingform_plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares the rubric XML paths attached to the form definition element
|
||||||
|
*
|
||||||
|
* @return array of {@link restore_path_element}
|
||||||
|
*/
|
||||||
|
protected function define_definition_plugin_structure() {
|
||||||
|
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
$paths[] = new restore_path_element('gradingform_rubric_criterion',
|
||||||
|
$this->get_pathfor('/criteria/criterion'));
|
||||||
|
|
||||||
|
$paths[] = new restore_path_element('gradingform_rubric_level',
|
||||||
|
$this->get_pathfor('/criteria/criterion/levels/level'));
|
||||||
|
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares the rubric XML paths attached to the form instance element
|
||||||
|
*
|
||||||
|
* @return array of {@link restore_path_element}
|
||||||
|
*/
|
||||||
|
protected function define_instance_plugin_structure() {
|
||||||
|
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
$paths[] = new restore_path_element('gradinform_rubric_filling',
|
||||||
|
$this->get_pathfor('/fillings/filling'));
|
||||||
|
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes criterion element data
|
||||||
|
*
|
||||||
|
* Sets the mapping 'gradingform_rubric_criterion' to be used later by
|
||||||
|
* {@link self::process_gradinform_rubric_filling()}
|
||||||
|
*/
|
||||||
|
public function process_gradingform_rubric_criterion($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object)$data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
$data->formid = $this->get_new_parentid('grading_definition');
|
||||||
|
|
||||||
|
$newid = $DB->insert_record('gradingform_rubric_criteria', $data);
|
||||||
|
$this->set_mapping('gradingform_rubric_criterion', $oldid, $newid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes level element data
|
||||||
|
*
|
||||||
|
* Sets the mapping 'gradingform_rubric_level' to be used later by
|
||||||
|
* {@link self::process_gradinform_rubric_filling()}
|
||||||
|
*/
|
||||||
|
public function process_gradingform_rubric_level($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object)$data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
$data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');
|
||||||
|
|
||||||
|
$newid = $DB->insert_record('gradingform_rubric_levels', $data);
|
||||||
|
$this->set_mapping('gradingform_rubric_level', $oldid, $newid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes filling element data
|
||||||
|
*/
|
||||||
|
public function process_gradinform_rubric_filling($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object)$data;
|
||||||
|
$data->forminstanceid = $this->get_new_parentid('grading_instance');
|
||||||
|
$data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid);
|
||||||
|
$data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid);
|
||||||
|
|
||||||
|
$DB->insert_record('gradingform_rubric_fillings', $data);
|
||||||
|
}
|
||||||
|
}
|
@ -90,6 +90,7 @@ class restore_assignment_activity_structure_step extends restore_activity_struct
|
|||||||
|
|
||||||
$newitemid = $DB->insert_record('assignment_submissions', $data);
|
$newitemid = $DB->insert_record('assignment_submissions', $data);
|
||||||
$this->set_mapping('assignment_submission', $oldid, $newitemid, true); // Going to have files
|
$this->set_mapping('assignment_submission', $oldid, $newitemid, true); // Going to have files
|
||||||
|
$this->set_mapping(restore_gradingform_plugin::itemid_mapping('submission'), $oldid, $newitemid);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function after_execute() {
|
protected function after_execute() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user