|
| 1 | +<?php |
| 2 | + |
| 3 | +defined('MOODLE_INTERNAL') || die(); |
| 4 | + |
| 5 | +/** |
| 6 | + * Journal conversion handler |
| 7 | + */ |
| 8 | +class moodle1_mod_journal_handler extends moodle1_mod_handler { |
| 9 | + |
| 10 | + /** |
| 11 | + * Declare the paths in moodle.xml we are able to convert |
| 12 | + * |
| 13 | + * The method returns list of {@link convert_path} instances. |
| 14 | + * For each path returned, the corresponding conversion method must be |
| 15 | + * defined. |
| 16 | + * |
| 17 | + * @return array of {@link convert_path} instances |
| 18 | + */ |
| 19 | + public function get_paths() { |
| 20 | + return array( |
| 21 | + new convert_path( |
| 22 | + 'journal', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL', |
| 23 | + array( |
| 24 | + 'renamefields' => array( |
| 25 | + 'assessed' => 'grade' |
| 26 | + ) |
| 27 | + ) |
| 28 | + ), |
| 29 | + new convert_path('entries', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES'), |
| 30 | + new convert_path('entry', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES/ENTRY'), |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function process_journal($data) { |
| 35 | + |
| 36 | + // get the course module id and context id |
| 37 | + $instanceid = $data['id']; |
| 38 | + $cminfo = $this->get_cminfo($instanceid); |
| 39 | + $moduleid = $cminfo['id']; |
| 40 | + $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); |
| 41 | + |
| 42 | + // we now have all information needed to start writing into the file |
| 43 | + $this->open_xml_writer("activities/journal_{$moduleid}/journal.xml"); |
| 44 | + $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, |
| 45 | + 'modulename' => 'journal', 'contextid' => $contextid)); |
| 46 | + $this->xmlwriter->begin_tag('journal', array('id' => $instanceid)); |
| 47 | + |
| 48 | + unset($data['id']); |
| 49 | + foreach ($data as $field => $value) { |
| 50 | + $this->xmlwriter->full_tag($field, $value); |
| 51 | + } |
| 52 | + |
| 53 | + return $data; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * This is executed when the parser reaches the <ENTRIES> opening element |
| 58 | + */ |
| 59 | + public function on_entries_start() { |
| 60 | + $this->xmlwriter->begin_tag('entries'); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES/ENTRY |
| 65 | + * data available |
| 66 | + */ |
| 67 | + public function process_entry($data) { |
| 68 | + $this->write_xml('entry', $data, array('/entry/id')); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * This is executed when the parser reaches the closing </ENTRIES> element |
| 73 | + */ |
| 74 | + public function on_entries_end() { |
| 75 | + $this->xmlwriter->end_tag('entries'); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * This is executed when we reach the closing </MOD> tag of our 'journal' path |
| 80 | + */ |
| 81 | + public function on_journal_end() { |
| 82 | + |
| 83 | + $this->xmlwriter->end_tag('journal'); |
| 84 | + $this->xmlwriter->end_tag('activity'); |
| 85 | + $this->close_xml_writer(); |
| 86 | + } |
| 87 | +} |
0 commit comments