PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/exchange/code/trunk/administrator/components/com_exchange/adapters/export/xml.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 96 lines | 51 code | 18 blank | 27 comment | 0 complexity | a06802c3f4d3cb37184f67cf3b4e5e13 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: xml.php 282 2010-09-18 04:56:29Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_exchange
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License version 2 or later.
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die;
  12. /**
  13. * @package NewLifeInIT
  14. * @subpackage com_exchange
  15. */
  16. class ExportAdapterXML
  17. {
  18. /**
  19. * Creates an XMI document that can be imported into Visual Paradigm
  20. *
  21. * @param array $tables An array of the tables to export.
  22. * @param array $fields An associative array of the field in the tables: {field name} => {field data type}.
  23. * @param array $creates An array of the SQL create statements for the tables.
  24. * @param array $options An associative array of options for the adapter: s (source) | limit | limitstart | format | comment.
  25. * @since 1.1
  26. */
  27. function export(&$tables, &$fields, &$creates, &$options)
  28. {
  29. $db = JFactory::getDbo();
  30. $source = JArrayHelper::getValue($options, 'source', '');
  31. $sourceStructure = is_numeric(strpos($source, 's'));
  32. $sourceData = is_numeric(strpos($source, 'd'));
  33. // Get some database information.
  34. $db->setQuery(
  35. 'SHOW VARIABLES WHERE Variable_name IN (\'character_set_database\', \'storage_engine\')'
  36. );
  37. $settings = (object) $db->loadObjectList('Variable_name');
  38. $buffer = array();
  39. $buffer[] = '<?xml version="1.0"?>';
  40. $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
  41. $buffer[] = ' <database name="">';
  42. foreach ($tables as $table)
  43. {
  44. // Get the details columns information.
  45. $db->setQuery(
  46. 'SHOW FULL COLUMNS FROM '.$db->nameQuote($table)
  47. );
  48. $columns = $db->loadObjectList('Field');
  49. $buffer = array_merge($buffer, $this->_createXML($table, $columns, $options));
  50. }
  51. $buffer[] = ' </database>';
  52. $buffer[] = '</mysqldump>';
  53. return implode("\n", $buffer);
  54. }
  55. function _createXML(&$tableName, &$fields, &$options)
  56. {
  57. $db = JFactory::getDbo();
  58. $limit = JArrayHelper::getValue($options, 'lmit', 0);
  59. $limitstart = JArrayHelper::getValue($options, 'limitstart', 0);
  60. $tableName = str_replace($db->getPrefix(), '', $tableName);
  61. $buffer = array();
  62. $buffer[] = ' <table_structure name="' . $tableName . '">';
  63. foreach ($fields as $field) {
  64. $buffer[] = ' <field Field="'.$field->Field.'"'.
  65. ' Type="'.$field->Type.'"'.
  66. ' Null="'.$field->Null.'"'.
  67. ' Key="'.$field->Key.'"'.
  68. ' Default="'.$field->Default.'"'.
  69. ' Extra="'.$field->Extra.'"'.
  70. // Not sure if the following comply with the spec.
  71. //($field->Collation ? ' Collation="'.$field->Collation.'"' : '').
  72. //' Comment="'.$field->Extra.'"'.
  73. ' />';
  74. }
  75. $buffer[] = ' </table_structure>';
  76. return $buffer;
  77. }
  78. }