From f1c8bb26d77fa8aab9b112ef26f4ad4f6ff7f941 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 29 Sep 2010 23:11:47 +0000 Subject: [PATCH] MDL-19936 workshopform_numerrors: restore implemented --- ...workshopform_numerrors_subplugin.class.php | 7 +- ...workshopform_numerrors_subplugin.class.php | 176 ++++++++++++++++++ 2 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php diff --git a/mod/workshop/form/numerrors/backup/moodle2/backup_workshopform_numerrors_subplugin.class.php b/mod/workshop/form/numerrors/backup/moodle2/backup_workshopform_numerrors_subplugin.class.php index a355339eb86..78cf7324d50 100644 --- a/mod/workshop/form/numerrors/backup/moodle2/backup_workshopform_numerrors_subplugin.class.php +++ b/mod/workshop/form/numerrors/backup/moodle2/backup_workshopform_numerrors_subplugin.class.php @@ -16,11 +16,12 @@ // along with Moodle. If not, see . /** - * @package workshopform_numerrors - * @subpackage backup-moodle2 - * @copyright 2010 David Mudrak + * @package workshopform + * @subpackage numerrors + * @copyright 2010 onwards David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + defined('MOODLE_INTERNAL') || die(); /** diff --git a/mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php b/mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php new file mode 100644 index 00000000000..115f44b600b --- /dev/null +++ b/mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php @@ -0,0 +1,176 @@ +. + +/** + * @package workshopform + * @subpackage numerrors + * @copyright 2010 onwards David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * restore subplugin class that provides the necessary information + * needed to restore one workshopform_numerrors subplugin. + */ +class restore_workshopform_numerrors_subplugin extends restore_subplugin { + + //////////////////////////////////////////////////////////////////////////// + // mappings of XML paths to the processable methods + //////////////////////////////////////////////////////////////////////////// + + /** + * Returns the paths to be handled by the subplugin at workshop level + */ + protected function define_workshop_subplugin_structure() { + + $paths = array(); + + $elename = $this->get_namefor('map'); + $elepath = $this->get_pathfor('/workshopform_numerrors_map'); // we used get_recommended_name() so this works + $paths[] = new restore_path_element($elename, $elepath); + + $elename = $this->get_namefor('dimension'); + $elepath = $this->get_pathfor('/workshopform_numerrors_dimension'); // we used get_recommended_name() so this works + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; // And we return the interesting paths + } + + /** + * Returns the paths to be handled by the subplugin at referenceassessment level + */ + protected function define_referenceassessment_subplugin_structure() { + + $paths = array(); + + $elename = $this->get_namefor('referencegrade'); + $elepath = $this->get_pathfor('/workshopform_numerrors_referencegrade'); // we used get_recommended_name() so this works + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; // And we return the interesting paths + } + + /** + * Returns the paths to be handled by the subplugin at exampleassessment level + */ + protected function define_exampleassessment_subplugin_structure() { + + $paths = array(); + + $elename = $this->get_namefor('examplegrade'); + $elepath = $this->get_pathfor('/workshopform_numerrors_examplegrade'); // we used get_recommended_name() so this works + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; // And we return the interesting paths + } + + /** + * Returns the paths to be handled by the subplugin at assessment level + */ + protected function define_assessment_subplugin_structure() { + + $paths = array(); + + $elename = $this->get_namefor('grade'); + $elepath = $this->get_pathfor('/workshopform_numerrors_grade'); // we used get_recommended_name() so this works + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; // And we return the interesting paths + } + + //////////////////////////////////////////////////////////////////////////// + // defined path elements are dispatched to the following methods + //////////////////////////////////////////////////////////////////////////// + + /** + * Processes the workshopform_numerrors_map element + */ + public function process_workshopform_numerrors_map($data) { + global $DB; + + $data = (object)$data; + $data->workshopid = $this->get_new_parentid('workshop'); + $DB->insert_record('workshopform_numerrors_map', $data); + } + + /** + * Processes the workshopform_numerrors_dimension element + */ + public function process_workshopform_numerrors_dimension($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + + $data->workshopid = $this->get_new_parentid('workshop'); + + $newitemid = $DB->insert_record('workshopform_numerrors', $data); + $this->set_mapping('workshopform_numerrors', $oldid, $newitemid, true); + + // Process files for this workshopform_numerrors->id only + $this->add_related_files('workshopform_numerrors', 'description', 'workshopform_numerrors', null, $oldid); + } + + /** + * Processes the workshopform_numerrors_referencegrade element + */ + public function process_workshopform_numerrors_referencegrade($data) { + $this->process_dimension_grades_structure('workshop_referenceassessment', $data); + } + + /** + * Processes the workshopform_numerrors_examplegrade element + */ + public function process_workshopform_numerrors_examplegrade($data) { + $this->process_dimension_grades_structure('workshop_exampleassessment', $data); + } + + /** + * Processes the workshopform_numerrors_grade element + */ + public function process_workshopform_numerrors_grade($data) { + $this->process_dimension_grades_structure('workshop_assessment', $data); + } + + //////////////////////////////////////////////////////////////////////////// + // internal private methods + //////////////////////////////////////////////////////////////////////////// + + /** + * Process the dimension grades linked with the given type of assessment + * + * Populates the workshop_grades table with new records mapped to the restored + * instances of assessments. + * + * @param mixed $elementname the name of the assessment element + * @param array $data parsed xml data + */ + private function process_dimension_grades_structure($elementname, $data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + + $data->assessmentid = $this->get_new_parentid($elementname); + $data->strategy = 'numerrors'; + $data->dimensionid = $this->get_mappingid('workshopform_numerrors', $data->dimensionid); + + $DB->insert_record('workshop_grades', $data); + } +}