[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkConverters/ -> AkDBDesignerToAkelosDatabaseDesign.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   3  
   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  // +----------------------------------------------------------------------+
  10  
  11  /**
  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>
  17   */
  18  class AkDBDesignerToAkelosDatabaseDesign
  19  {
  20      var $_parser;
  21      var $_stack = array();
  22      var $_errors = array();
  23      var $db_schema = array();
  24      var $current_table;
  25  
  26      function AkDBDesignerToAkelosDatabaseDesign()
  27      {
  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);
  32      }
  33  
  34  
  35      function addError($error)
  36      {
  37          $this->_errors[] = $error.' on line '.$this->getCurrentLine();
  38      }
  39  
  40      function getCurrentLine()
  41      {
  42          return xml_get_current_line_number($this->_parser) + $this->_startLine;
  43      }
  44  
  45      function hasErrors(&$xhtml)
  46      {
  47          return count($this->getErrors()) > 0;
  48      }
  49  
  50      function getErrors()
  51      {
  52          return array_unique($this->_errors);
  53      }
  54  
  55      function showErrors()
  56      {
  57          echo '<ul><li>'.join("</li>\n<li>", $this->getErrors()).'</li></ul>';
  58      }
  59  
  60      function convert()
  61      {
  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)));
  64          }
  65          
  66          foreach ($this->db_schema as $table=>$create_text){
  67              $this->db_schema[$table] = rtrim($create_text,", \n");
  68          }
  69          
  70          return $this->db_schema;
  71      }
  72  
  73  
  74      function tagOpen($parser, $tag, $attributes)
  75      {
  76          if(!empty($attributes['Tablename'])){
  77              $this->current_table = $attributes['Tablename'];
  78          }
  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";
  88          }
  89      }
  90  
  91      function getDataType($type)
  92      {
  93          (int)$type = $type;
  94          $dbdesigner_data_types = array(
  95          1 => 'integer',
  96          2 => 'integer',
  97          3 => 'integer',
  98          4 => 'integer',
  99          5 => 'integer',
 100          6 => 'integer',
 101          7 => 'float',
 102          8 => 'float',
 103          9 => 'float',
 104          10 => 'float',
 105          11 => 'float',
 106          12 => 'float',
 107          13 => 'float',
 108  
 109          14 => 'date',
 110          15 => 'datetime',
 111          16 => 'timestamp',
 112          17 => 'time',
 113          18 => 'integer',
 114  
 115          19 => 'string',
 116          20 => 'string',
 117  
 118          21 => 'boolean',
 119          22 => 'boolean',
 120  
 121          23 => 'binary',
 122          24 => 'binary',
 123          25 => 'binary',
 124          26 => 'binary',
 125  
 126          27 => 'text',
 127          28 => 'text',
 128          29 => 'text',
 129          30 => 'text');
 130          
 131          return empty($dbdesigner_data_types[$type]) ? 'string' : $dbdesigner_data_types[$type];
 132  
 133      }
 134  
 135      function tagClose($parser, $tag)
 136      {
 137      }
 138  }
 139  
 140  
 141  ?>


Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6