/exchange/code/trunk/administrator/components/com_exchange/adapters/export/xml.php
PHP | 96 lines | 51 code | 18 blank | 27 comment | 0 complexity | a06802c3f4d3cb37184f67cf3b4e5e13 MD5 | raw file
- <?php
- /**
- * @version $Id: xml.php 282 2010-09-18 04:56:29Z eddieajau $
- * @package NewLifeInIT
- * @subpackage com_exchange
- * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License version 2 or later.
- * @link http://www.theartofjoomla.com
- */
- // no direct access
- defined('_JEXEC') or die;
- /**
- * @package NewLifeInIT
- * @subpackage com_exchange
- */
- class ExportAdapterXML
- {
- /**
- * Creates an XMI document that can be imported into Visual Paradigm
- *
- * @param array $tables An array of the tables to export.
- * @param array $fields An associative array of the field in the tables: {field name} => {field data type}.
- * @param array $creates An array of the SQL create statements for the tables.
- * @param array $options An associative array of options for the adapter: s (source) | limit | limitstart | format | comment.
- * @since 1.1
- */
- function export(&$tables, &$fields, &$creates, &$options)
- {
- $db = JFactory::getDbo();
- $source = JArrayHelper::getValue($options, 'source', '');
- $sourceStructure = is_numeric(strpos($source, 's'));
- $sourceData = is_numeric(strpos($source, 'd'));
- // Get some database information.
- $db->setQuery(
- 'SHOW VARIABLES WHERE Variable_name IN (\'character_set_database\', \'storage_engine\')'
- );
- $settings = (object) $db->loadObjectList('Variable_name');
- $buffer = array();
- $buffer[] = '<?xml version="1.0"?>';
- $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
- $buffer[] = ' <database name="">';
- foreach ($tables as $table)
- {
- // Get the details columns information.
- $db->setQuery(
- 'SHOW FULL COLUMNS FROM '.$db->nameQuote($table)
- );
- $columns = $db->loadObjectList('Field');
- $buffer = array_merge($buffer, $this->_createXML($table, $columns, $options));
- }
- $buffer[] = ' </database>';
- $buffer[] = '</mysqldump>';
- return implode("\n", $buffer);
- }
- function _createXML(&$tableName, &$fields, &$options)
- {
- $db = JFactory::getDbo();
- $limit = JArrayHelper::getValue($options, 'lmit', 0);
- $limitstart = JArrayHelper::getValue($options, 'limitstart', 0);
- $tableName = str_replace($db->getPrefix(), '', $tableName);
- $buffer = array();
- $buffer[] = ' <table_structure name="' . $tableName . '">';
- foreach ($fields as $field) {
- $buffer[] = ' <field Field="'.$field->Field.'"'.
- ' Type="'.$field->Type.'"'.
- ' Null="'.$field->Null.'"'.
- ' Key="'.$field->Key.'"'.
- ' Default="'.$field->Default.'"'.
- ' Extra="'.$field->Extra.'"'.
- // Not sure if the following comply with the spec.
- //($field->Collation ? ' Collation="'.$field->Collation.'"' : '').
- //' Comment="'.$field->Extra.'"'.
- ' />';
- }
- $buffer[] = ' </table_structure>';
- return $buffer;
- }
- }