2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
12 * @package ActiveSupport
13 * @subpackage Converters
14 * @author Bermi Ferrer <bermi a.t akelos c.om>
15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
18 class AkDBDesignerToAkelosDatabaseDesign
21 var $_stack = array();
22 var $_errors = array();
23 var $db_schema = array();
26 function AkDBDesignerToAkelosDatabaseDesign()
28 $this->_parser
= xml_parser_create();
29 xml_set_object($this->_parser
, &$this);
30 xml_set_element_handler($this->_parser
, 'tagOpen', 'tagClose');
31 xml_parser_set_option($this->_parser
, XML_OPTION_CASE_FOLDING
, false);
35 function addError($error)
37 $this->_errors
[] = $error.' on line '.$this->getCurrentLine();
40 function getCurrentLine()
42 return xml_get_current_line_number($this->_parser
) +
$this->_startLine
;
45 function hasErrors(&$xhtml)
47 return count($this->getErrors()) > 0;
52 return array_unique($this->_errors
);
57 echo '<ul><li>'.join("</li>\n<li>", $this->getErrors()).'</li></ul>';
62 if (!xml_parse($this->_parser
, $this->source
)) {
63 $this->addError(Ak
::t('DBDesigner file is not well-formed.').' '.xml_error_string(xml_get_error_code($this->_parser
)));
66 foreach ($this->db_schema
as $table=>$create_text){
67 $this->db_schema
[$table] = rtrim($create_text,", \n");
70 return $this->db_schema
;
74 function tagOpen($parser, $tag, $attributes)
76 if(!empty($attributes['Tablename'])){
77 $this->current_table
= $attributes['Tablename'];
79 if(!empty($attributes['ColName']) && !empty($this->current_table
)){
80 $this->db_schema
[$this->current_table
] = empty($this->db_schema
[$this->current_table
]) ?
'' : $this->db_schema
[$this->current_table
];
81 $this->db_schema
[$this->current_table
] .=
82 $attributes['ColName'].' '.
83 $this->getDataType($attributes['idDatatype']).$attributes['DatatypeParams'].
84 (empty($attributes['PrimaryKey']) ?
'' : ' primary').
85 (empty($attributes['NotNull']) ?
'' : ' not null').
86 (empty($attributes['AutoInc']) ?
'' : ' auto increment').
87 (empty($attributes['DefaultValue']) ?
'' : ' default='.$attributes['DefaultValue']).",\n";
91 function getDataType($type)
94 $dbdesigner_data_types = array(
131 return empty($dbdesigner_data_types[$type]) ?
'string' : $dbdesigner_data_types[$type];
135 function tagClose($parser, $tag)