[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Provides support for the conversion of moodle1 backup to the moodle2 format 19 * 20 * @package mod_feedback 21 * @copyright 2011 Rossiani Wijaya <rwijaya@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Feedback module conversion handler 29 */ 30 class moodle1_mod_feedback_handler extends moodle1_mod_handler { 31 32 /** @var moodle1_file_manager */ 33 protected $fileman = null; 34 35 /** @var int cmid */ 36 protected $moduleid = null; 37 38 /** 39 * Declare the paths in moodle.xml we are able to convert 40 * 41 * The method returns list of {@link convert_path} instances. 42 * For each path returned, the corresponding conversion method must be 43 * defined. 44 * 45 * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK does not 46 * actually exist in the file. The last element with the module name was 47 * appended by the moodle1_converter class. 48 * 49 * @return array of {@link convert_path} instances 50 */ 51 public function get_paths() { 52 return array( 53 new convert_path( 54 'feedback', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK', 55 array( 56 'renamefields' => array( 57 'summary' => 'intro', 58 'pageaftersub' => 'page_after_submit', 59 ), 60 'newfields' => array( 61 'autonumbering' => 1, 62 'site_after_submit' => '', 63 'introformat' => 0, 64 'page_after_submitformat' => 0, 65 'completionsubmit' => 0, 66 ), 67 ) 68 ), 69 new convert_path( 70 'feedback_item', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM', 71 array ( 72 'newfields' => array( 73 'label' => '', 74 'options' => '', 75 'dependitem' => 0, 76 'dependvalue' => '', 77 ), 78 ) 79 ), 80 ); 81 } 82 83 /** 84 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK 85 * data available 86 */ 87 public function process_feedback($data) { 88 global $CFG; 89 90 // get the course module id and context id 91 $instanceid = $data['id']; 92 $cminfo = $this->get_cminfo($instanceid); 93 $this->moduleid = $cminfo['id']; 94 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 95 96 // get a fresh new file manager for this instance 97 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_feedback'); 98 99 // convert course files embedded into the intro 100 $this->fileman->filearea = 'intro'; 101 $this->fileman->itemid = 0; 102 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 103 104 // Convert the introformat if necessary. 105 if ($CFG->texteditors !== 'textarea') { 106 $data['intro'] = text_to_html($data['intro'], false, false, true); 107 $data['introformat'] = FORMAT_HTML; 108 } 109 110 // start writing feedback.xml 111 $this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml"); 112 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 113 'modulename' => 'feedback', 'contextid' => $contextid)); 114 $this->xmlwriter->begin_tag('feedback', array('id' => $instanceid)); 115 116 foreach ($data as $field => $value) { 117 if ($field <> 'id') { 118 $this->xmlwriter->full_tag($field, $value); 119 } 120 } 121 122 $this->xmlwriter->begin_tag('items'); 123 124 return $data; 125 } 126 127 /** 128 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM 129 * data available 130 */ 131 public function process_feedback_item($data) { 132 $this->write_xml('item', $data, array('/item/id')); 133 } 134 135 /** 136 * This is executed when we reach the closing </MOD> tag of our 'feedback' path 137 */ 138 public function on_feedback_end() { 139 // finish writing feedback.xml 140 $this->xmlwriter->end_tag('items'); 141 $this->xmlwriter->end_tag('feedback'); 142 $this->xmlwriter->end_tag('activity'); 143 $this->close_xml_writer(); 144 145 // write inforef.xml 146 $this->open_xml_writer("activities/feedback_{$this->moduleid}/inforef.xml"); 147 $this->xmlwriter->begin_tag('inforef'); 148 $this->xmlwriter->begin_tag('fileref'); 149 foreach ($this->fileman->get_fileids() as $fileid) { 150 $this->write_xml('file', array('id' => $fileid)); 151 } 152 $this->xmlwriter->end_tag('fileref'); 153 $this->xmlwriter->end_tag('inforef'); 154 $this->close_xml_writer(); 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |