MDL-47494 ddimageortext: NOBUG refactored backup and restore code so it can be reused by ddwordtoimage

This commit is contained in:
Jamie Pratt
2011-09-01 18:32:12 +07:00
parent dd6550e23b
commit a116cdfa3d
2 changed files with 22 additions and 19 deletions
@@ -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");
}
}
@@ -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;
}