Skip to content

Commit

Permalink
MDL-22414 Added scales conversion handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jun 8, 2011
1 parent fe50f53 commit e29746c
Showing 1 changed file with 82 additions and 3 deletions.
85 changes: 82 additions & 3 deletions backup/converter/moodle1/handlerlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function get_handlers(moodle1_converter $converter) {
new moodle1_course_outline_handler($converter),
new moodle1_roles_definition_handler($converter),
new moodle1_question_bank_handler($converter),
new moodle1_scales_handler($converter),
);

$handlers = array_merge($handlers, self::get_plugin_handlers('mod', $converter));
Expand Down Expand Up @@ -316,7 +317,9 @@ public function on_root_element_end() {
$backupinfo = $this->converter->get_stash('backup_info');
$originalcourseinfo = $this->converter->get_stash('original_course_info');

// start writing to the main XML file data
////////////////////////////////////////////////////////////////////////
// write moodle_backup.xml
////////////////////////////////////////////////////////////////////////
$this->open_xml_writer('moodle_backup.xml');

$this->xmlwriter->begin_tag('moodle_backup');
Expand Down Expand Up @@ -472,7 +475,9 @@ public function on_root_element_end() {

$this->close_xml_writer();

////////////////////////////////////////////////////////////////////////
// write files.xml
////////////////////////////////////////////////////////////////////////
$this->open_xml_writer('files.xml');
$this->xmlwriter->begin_tag('files');
foreach ($this->converter->get_stash_itemids('files') as $fileid) {
Expand All @@ -481,7 +486,20 @@ public function on_root_element_end() {
$this->xmlwriter->end_tag('files');
$this->close_xml_writer('files.xml');

// generate course/inforef.xml
////////////////////////////////////////////////////////////////////////
// write scales.xml
////////////////////////////////////////////////////////////////////////
$this->open_xml_writer('scales.xml');
$this->xmlwriter->begin_tag('scales_definition');
foreach ($this->converter->get_stash_itemids('scales') as $scaleid) {
$this->write_xml('scale', $this->converter->get_stash('scales', $scaleid), array('/scale/id'));
}
$this->xmlwriter->end_tag('scales_definition');
$this->close_xml_writer('scales.xml');

////////////////////////////////////////////////////////////////////////
// write course/inforef.xml
////////////////////////////////////////////////////////////////////////
$this->open_xml_writer('course/inforef.xml');
$this->xmlwriter->begin_tag('inforef');

Expand Down Expand Up @@ -519,7 +537,6 @@ public function on_root_element_end() {
// apparently this must be called after the handler had a chance to create the file.
$this->make_sure_xml_exists('questions.xml', 'question_categories');
$this->make_sure_xml_exists('groups.xml', 'groups');
$this->make_sure_xml_exists('scales.xml', 'scales_definition');
$this->make_sure_xml_exists('outcomes.xml', 'outcomes_definition');
$this->make_sure_xml_exists('users.xml', 'users');
$this->make_sure_xml_exists('course/roles.xml', 'roles',
Expand Down Expand Up @@ -1281,6 +1298,68 @@ protected function get_qtype_handler($qtype) {
}


/**
* Handles the conversion of the scales included in the moodle.xml file
*/
class moodle1_scales_handler extends moodle1_handler {

/** @var moodle1_file_manager instance used to convert question images */
protected $fileman = null;

/**
* Registers path that are not qtype-specific
*/
public function get_paths() {
return array(
new convert_path('scales', '/MOODLE_BACKUP/COURSE/SCALES'),
new convert_path(
'scale', '/MOODLE_BACKUP/COURSE/SCALES/SCALE',
array(
'renamefields' => array(
'scaletext' => 'scale',
),
'addfields' => array(
'descriptionformat' => 0,
)
)
),
);
}

/**
* Prepare the file manager for the files embedded in the scale description field
*/
public function on_scales_start() {
$syscontextid = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'scale');
}

/**
* This is executed every time we have one <SCALE> data available
*
* @param array $data
* @param array $raw
* @return array
*/
public function process_scale(array $data, array $raw) {
global $CFG;

// replay upgrade step 2009110400
if ($CFG->texteditors !== 'textarea') {
$data['description'] = text_to_html($data['description'], false, false, true);
$data['descriptionformat'] = FORMAT_HTML;
}

// convert course files embedded into the scale description field
$this->fileman->itemid = $data['id'];
$data['description'] = moodle1_converter::migrate_referenced_files($data['description'], $this->fileman);

// stash the scale
$this->converter->set_stash('scales', $data, $data['id']);
}
}


/**
* Shared base class for activity modules, blocks and qtype handlers
*/
Expand Down

0 comments on commit e29746c

Please sign in to comment.