Exemplo n.º 1
0
 /**
  * Transform an XML document into an SQL schema
  * 
  * @param string $curpath
  * @param QuickBooks_XML_Node $node
  * @param array $tables
  * @return 
  */
 protected static function _transform($curpath, $node, &$tables)
 {
     //print("\n");
     print '' . $curpath . '   node: ' . $node->name() . "\n";
     //print('	node: ' . $node->name() . "\n");
     //$tables = array();
     $table = '';
     $field = '';
     //QuickBooks_SQL_Schema::mapPathToSQL($node->name(), $table, $field);		// table name
     //print('		table for node: ' . $table . "\n");
     //print('		field for node: ' . $field . "\n");
     $this_sql = array();
     $other_sql = array();
     QuickBooks_SQL_Schema::mapToSchema($curpath . ' ' . $node->name(), QUICKBOOKS_SQL_SCHEMA_MAP_TO_SQL, $this_sql, $other_sql);
     //print('mapping: ');
     //print_r($this_sql);
     //print_r($other_sql);
     //print("\n\n\n");
     //print_r($this_sql);
     foreach (array_merge(array($this_sql), $other_sql) as $sql) {
         $table = $sql[0];
         $field = $sql[1];
         if (!$sql[0] or !$sql[1]) {
             print '		table for node: ' . $sql[0] . "\n";
             print '		field for node: ' . $sql[1] . "\n";
         } else {
             print "\n";
         }
         if ($table) {
             if (!isset($tables[$table])) {
                 //print('trying to map key for: ' . $curpath . ' ' . $name);
                 //$map = null;
                 //QuickBooks_SQL_Schema::mapPrimaryKey($curpath . ' ' . $name, QUICKBOOKS_SQL_SCHEMA_MAP_TO_SQL, $map);
                 //print_r($map);
                 //exit;
                 $tables[$table] = array(0 => $table, 1 => array(), 2 => null, 3 => array(), 4 => array());
             }
         }
         if ($table and $field) {
             if (!isset($tables[$table][1][$field])) {
                 $tables[$table][1][$field] = QuickBooks_SQL_Schema::mapFieldToSQLDefinition($table, $field, $node->data());
             }
         }
     }
     if ($node->childCount()) {
         /*
         $sql = array();
         $other_sql = array();
         QuickBooks_SQL_Schema::mapToSchema($curpath . ' ' . $node->name(), QUICKBOOKS_SQL_SCHEMA_MAP_TO_SQL, $sql, $other_sql);
         
         foreach (array_merge($sql, $other_sql) as $sql)
         {
         	$table = $sql[0];
         	$field = $sql[1];
         }
         */
         foreach ($node->children() as $child) {
             QuickBooks_SQL_Schema::_transform($curpath . ' ' . $node->name(), $child, $tables);
         }
     }
     /*
     print('tables: ');
     print_r($tables);
     exit;
     
     foreach ($tables as $table)
     {
     	//print_r($table);
     	exit;
     }
     */
 }
Exemplo n.º 2
0
 /**
  * Resursive helper function for converting to XML
  * 
  * @param QuickBooks_XML_Node $node
  * @param integer $tabs
  * @param boolean $empty				A constant, one of: QUICKBOOKS_XML_XML_PRESERVE, QUICKBOOKS_XML_XML_DROP, QUICKBOOKS_XML_XML_COMPRESS
  * @param string $indent
  * @return string
  */
 public function _asXMLHelper($node, $tabs, $empty, $indent)
 {
     $xml = '';
     if ($node->childCount()) {
         $xml .= str_repeat($indent, $tabs) . '<' . $node->name();
         foreach ($node->attributes() as $key => $value) {
             // Make sure double-encode is *off*
             //$xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value, true, false) . '"';
             $xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value) . '"';
         }
         $xml .= '>' . "\n";
         foreach ($node->children() as $child) {
             $xml .= $this->_asXMLHelper($child, $tabs + 1, $empty, $indent);
         }
         $xml .= str_repeat($indent, $tabs) . '</' . $node->name() . '>' . "\n";
     } else {
         if ($node->hasAttributes()) {
             $xml .= str_repeat($indent, $tabs) . '<' . $node->name();
             foreach ($node->attributes() as $key => $value) {
                 // Double-encode is *off*
                 //$xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value, true, false) . '"';
                 $xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value) . '"';
             }
             // Double-encode is *off*
             //$xml .= '>' . QuickBooks_XML::encode($node->data(), true, false) . '</' . $node->name() . '>' . "\n";
             $xml .= '>' . QuickBooks_XML::encode($node->data()) . '</' . $node->name() . '>' . "\n";
         } else {
             if ($node->hasData() or $empty == QUICKBOOKS_XML_XML_PRESERVE) {
                 // Double-encode is *off*
                 //$xml .= str_repeat($indent, $tabs) . '<' . $node->name() . '>' . QuickBooks_XML::encode($node->data(), true, false) . '</' . $node->name() . '>' . "\n";
                 $xml .= str_repeat($indent, $tabs) . '<' . $node->name() . '>' . QuickBooks_XML::encode($node->data()) . '</' . $node->name() . '>' . "\n";
             } else {
                 if ($empty == QUICKBOOKS_XML_XML_COMPRESS) {
                     $xml .= str_repeat($indent, $tabs) . '<' . $node->name() . ' />' . "\n";
                 } else {
                     if ($empty == QUICKBOOKS_XML_XML_DROP) {
                         // do nothing, drop the empty element
                     }
                 }
             }
         }
         /*
         $xml .= str_repeat($indent, $tabs) . '<' . $node->name();
         
         foreach ($node->attributes() as $key => $value)
         {
         	$xml .= ' ' . $key . '="' . htmlentities($value, ENT_QUOTES) . '"';
         }
         
         if ($node->data())
         {
         	$xml .= '>' . htmlentities($node->data()) . '</' . $node->name() . '>' . "\n";
         }
         else if ($compress)
         {
         	$xml .= ' />' . "\n";
         }
         else
         {
         	$xml .= '></' . $node->name() . '>' . "\n";
         }
         */
     }
     return $xml;
 }
Exemplo n.º 3
0
 /**
  * Transform an XML document into an SQL schema
  * 
  * @param string $curpath
  * @param QuickBooks_XML_Node $node
  * @param array $tables
  * @return 
  */
 protected static function _transform($curpath, $node, &$tables)
 {
     print '' . $curpath . '   node: ' . $node->name() . "\n";
     $table = '';
     $field = '';
     $this_sql = array();
     $other_sql = array();
     QuickBooks_SQL_Schema::mapToSchema($curpath . ' ' . $node->name(), QUICKBOOKS_SQL_SCHEMA_MAP_TO_SQL, $this_sql, $other_sql);
     foreach (array_merge(array($this_sql), $other_sql) as $sql) {
         $table = $sql[0];
         $field = $sql[1];
         /*
         if (!$sql[0] or !$sql[1])
         {
         	print('		table for node: ' . $sql[0] . "\n");
         	print('		field for node: ' . $sql[1] . "\n");
         }
         else
         {
         	print("\n");
         }
         */
         if ($table) {
             if (!isset($tables[$table])) {
                 $tables[$table] = array(0 => $table, 1 => array(), 2 => null, 3 => array(), 4 => array());
             }
         }
         if ($table and $field) {
             if (!isset($tables[$table][1][$field])) {
                 $tables[$table][1][$field] = QuickBooks_SQL_Schema::mapFieldToSQLDefinition($table, $field, $node->data());
             }
         }
     }
     if ($node->childCount()) {
         foreach ($node->children() as $child) {
             QuickBooks_SQL_Schema::_transform($curpath . ' ' . $node->name(), $child, $tables);
         }
     }
     return true;
 }