|
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 00018 00028 defined('MOODLE_INTERNAL') || die(); 00029 00035 abstract class xml_database_exporter extends database_exporter { 00040 protected abstract function output($text); 00041 00051 public function begin_database_export($version, $release, $timestamp, $description) { 00052 $this->output('<?xml version="1.0" encoding="utf-8"?>'); 00053 //TODO add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and schema information 00054 $this->output('<moodle_database version="'.$version.'" release="'.$release.'" timestamp="'.$timestamp.'"'.(empty ($description) ? '' : ' comment="'.htmlspecialchars($description, ENT_QUOTES).'"').'>'); 00055 } 00056 00063 public function begin_table_export(xmldb_table $table) { 00064 $this->output('<table name="'.$table->getName().'" schemaHash="'.$table->getHash().'">'); 00065 } 00066 00072 public function finish_table_export(xmldb_table $table) { 00073 $this->output('</table>'); 00074 } 00075 00079 public function finish_database_export() { 00080 $this->output('</moodle_database>'); 00081 } 00082 00090 public function export_table_data(xmldb_table $table, $data) { 00091 $this->output('<record>'); 00092 foreach ($data as $key => $value) { 00093 if (is_null($value)) { 00094 $this->output('<field name="'.$key.'" value="null" />'); 00095 } else { 00096 $this->output('<field name="'.$key.'">'.htmlspecialchars($value, ENT_NOQUOTES).'</field>'); 00097 } 00098 } 00099 $this->output('</record>'); 00100 } 00101 }