|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 defined('MOODLE_INTERNAL') || die(); 00029 00033 class moodle1_mod_data_handler extends moodle1_mod_handler { 00034 00036 protected $fileman = null; 00037 00039 protected $moduleid = null; 00040 00054 public function get_paths() { 00055 return array( 00056 new convert_path('data', '/MOODLE_BACKUP/COURSE/MODULES/MOD/DATA', 00057 array( 00058 'newfields' => array( 00059 'introformat' => 0, 00060 'assesstimestart' => 0, 00061 'assesstimefinish' => 0, 00062 ) 00063 ) 00064 ), 00065 new convert_path('data_field', '/MOODLE_BACKUP/COURSE/MODULES/MOD/DATA/FIELDS/FIELD') 00066 ); 00067 } 00068 00073 public function process_data($data) { 00074 global $CFG; 00075 00076 // get the course module id and context id 00077 $instanceid = $data['id']; 00078 $cminfo = $this->get_cminfo($instanceid); 00079 $this->moduleid = $cminfo['id']; 00080 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00081 00082 // replay the upgrade step 2007101512 00083 if (!array_key_exists('asearchtemplate', $data)) { 00084 $data['asearchtemplate'] = null; 00085 } 00086 00087 // replay the upgrade step 2007101513 00088 if (is_null($data['notification'])) { 00089 $data['notification'] = 0; 00090 } 00091 00092 // conditionally migrate to html format in intro 00093 if ($CFG->texteditors !== 'textarea') { 00094 $data['intro'] = text_to_html($data['intro'], false, false, true); 00095 $data['introformat'] = FORMAT_HTML; 00096 } 00097 00098 // get a fresh new file manager for this instance 00099 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_data'); 00100 00101 // convert course files embedded into the intro 00102 $this->fileman->filearea = 'intro'; 00103 $this->fileman->itemid = 0; 00104 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00105 00106 // @todo: user data - upgrade content to new file storage 00107 00108 // add 'export' tag to list and single template. 00109 $pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/'; 00110 $replacement = '##delete##$1##approve##$1##export##'; 00111 $data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']); 00112 $data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']); 00113 00114 //@todo: user data - move data comments to comments table 00115 //@todo: user data - move data ratings to ratings table 00116 00117 // start writing data.xml 00118 $this->open_xml_writer("activities/data_{$this->moduleid}/data.xml"); 00119 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00120 'modulename' => 'data', 'contextid' => $contextid)); 00121 $this->xmlwriter->begin_tag('data', array('id' => $instanceid)); 00122 00123 foreach ($data as $field => $value) { 00124 if ($field <> 'id') { 00125 $this->xmlwriter->full_tag($field, $value); 00126 } 00127 } 00128 00129 $this->xmlwriter->begin_tag('fields'); 00130 00131 return $data; 00132 } 00133 00138 public function process_data_field($data) { 00139 // process database fields 00140 $this->write_xml('field', $data, array('/field/id')); 00141 } 00142 00147 public function process_data_record($data) { 00148 //@todo process user data, and define the convert path in get_paths() above. 00149 //$this->write_xml('record', $data, array('/record/id')); 00150 } 00151 00155 public function on_data_end() { 00156 // finish writing data.xml 00157 $this->xmlwriter->end_tag('fields'); 00158 $this->xmlwriter->end_tag('data'); 00159 $this->xmlwriter->end_tag('activity'); 00160 $this->close_xml_writer(); 00161 00162 // write inforef.xml 00163 $this->open_xml_writer("activities/data_{$this->moduleid}/inforef.xml"); 00164 $this->xmlwriter->begin_tag('inforef'); 00165 $this->xmlwriter->begin_tag('fileref'); 00166 foreach ($this->fileman->get_fileids() as $fileid) { 00167 $this->write_xml('file', array('id' => $fileid)); 00168 } 00169 $this->xmlwriter->end_tag('fileref'); 00170 $this->xmlwriter->end_tag('inforef'); 00171 $this->close_xml_writer(); 00172 } 00173 }