From a116cdfa3de63617b44a61e2fea7b311fc65d5ec Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Thu, 1 Sep 2011 18:08:21 +0700 Subject: [PATCH] MDL-47494 ddimageortext: NOBUG refactored backup and restore code so it can be reused by ddwordtoimage --- ...ckup_qtype_ddimagetoimage_plugin.class.php | 16 ++++++------ ...tore_qtype_ddimagetoimage_plugin.class.php | 25 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php b/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php index de8d93da728..1c6a0944db9 100644 --- a/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php +++ b/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php @@ -31,23 +31,25 @@ defined('MOODLE_INTERNAL') || die(); */ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { + protected $qtype = "ddimagetoimage"; + /** * Returns the qtype information to attach to question element */ protected function define_question_plugin_structure() { - $plugin = $this->get_plugin_element(null, '../../qtype', 'ddimagetoimage'); + $plugin = $this->get_plugin_element(null, '../../qtype', $this->qtype); $pluginwrapper = new backup_nested_element($this->get_recommended_name()); $plugin->add_child($pluginwrapper); - $ddimagetoimages = new backup_nested_element('ddimagetoimage', array('id'), array( + $dds = new backup_nested_element($this->qtype, array('id'), array( 'shuffleanswers', 'correctfeedback', 'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', 'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect')); - $pluginwrapper->add_child($ddimagetoimages); + $pluginwrapper->add_child($dds); $drags = new backup_nested_element('drags'); $drag = new backup_nested_element('drag', array('id'), @@ -57,7 +59,7 @@ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { $drop = new backup_nested_element('drop', array('id'), array('no', 'xleft', 'ytop', 'choice', 'label')); - $ddimagetoimages->set_source_table('qtype_ddimagetoimage', + $dds->set_source_table("qtype_{$this->qtype}", array('questionid' => backup::VAR_PARENTID)); $pluginwrapper->add_child($drags); @@ -65,10 +67,10 @@ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { $pluginwrapper->add_child($drops); $drops->add_child($drop); - $drag->set_source_table('qtype_ddimagetoimage_drags', + $drag->set_source_table("qtype_{$this->qtype}_drags", array('questionid' => backup::VAR_PARENTID)); - $drop->set_source_table('qtype_ddimagetoimage_drops', + $drop->set_source_table("qtype_{$this->qtype}_drops", array('questionid' => backup::VAR_PARENTID)); return $plugin; @@ -87,6 +89,6 @@ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { 'incorrectfeedback' => 'question_created', 'bgimage' => 'question_created', - 'dragimage' => 'qtype_ddimagetoimage_drags'); + 'dragimage' => "qtype_{$this->qtype}_drags"); } } diff --git a/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php b/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php index 7d54ed41861..27433c399ba 100644 --- a/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php +++ b/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php @@ -32,6 +32,8 @@ defined('MOODLE_INTERNAL') || die(); */ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { + protected $qtype = "ddimagetoimage"; + /** * Returns the paths to be handled by the plugin at question level */ @@ -40,8 +42,8 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { $paths = array(); // Add own qtype stuff - $elename = 'ddimagetoimage'; - $elepath = $this->get_pathfor('/ddimagetoimage'); + $elename = dds; + $elepath = $this->get_pathfor('/'.$this->qtype); $paths[] = new restore_path_element($elename, $elepath); $elename = 'drag'; @@ -56,9 +58,9 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { } /** - * Process the qtype/ddimagetoimage element + * Process the qtype/{qtypename} element */ - public function process_ddimagetoimage($data) { + public function process_dds($data) { global $DB; $data = (object)$data; @@ -75,9 +77,9 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { // Adjust some columns $data->questionid = $newquestionid; // Insert record - $newitemid = $DB->insert_record('qtype_ddimagetoimage', $data); + $newitemid = $DB->insert_record('qtype_'.$this->qtype, $data); // Create mapping (needed for decoding links) - $this->set_mapping('qtype_ddimagetoimage', $oldid, $newitemid); + $this->set_mapping('qtype_'.$this->qtype, $oldid, $newitemid); } } @@ -98,9 +100,9 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { if ($questioncreated) { $data->questionid = $newquestionid; // Insert record - $newitemid = $DB->insert_record('qtype_ddimagetoimage_drags', $data); + $newitemid = $DB->insert_record("qtype_{$this->qtype}_drags", $data); // Create mapping (there are files and states based on this) - $this->set_mapping('qtype_ddimagetoimage_drags', $oldid, $newitemid); + $this->set_mapping("qtype_{$this->qtype}_drags", $oldid, $newitemid); } } @@ -122,10 +124,9 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { if ($questioncreated) { $data->questionid = $newquestionid; // Insert record - $newitemid = $DB->insert_record('qtype_ddimagetoimage_drops', $data); + $newitemid = $DB->insert_record("qtype_{$this->qtype}_drops", $data); // Create mapping (there are files and states based on this) - $this->set_mapping('qtype_ddimagetoimage_drops', $oldid, $newitemid); - + $this->set_mapping("qtype_{$this->qtype}_drops", $oldid, $newitemid); } } /** @@ -137,7 +138,7 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); $contents[] = - new restore_decode_content('qtype_ddimagetoimage', $fields, 'question_ddimagetoimage'); + new restore_decode_content('qtype_'.$this->qtype, $fields, 'qtype_'.$this->qtype); return $contents; }