/** * Helper function for converting to an array mapping paths to tag values * * @param QuickBooks_XML_Node $node * @param string $current * @param array $paths * @return void */ protected function _asArrayPathsHelper($node, $current, &$paths) { if ($node->hasChildNodes()) { foreach ($node->children() as $child) { $this->_asArrayPathsHelper($child, $current . ' ' . $node->name(), $paths); } } else { if ($node->hasData()) { $paths[trim($current . ' ' . $node->name())] = $node->data(); } } }
protected function _parseIDS_v2($xml, $optype, $flavor, $version, &$xml_errnum, &$xml_errmsg, &$err_code, &$err_desc, &$err_db) { // Massage it... *sigh* $xml = $this->_massageQBOXML($xml, $optype); // Parse it $Parser = new QuickBooks_XML_Parser($xml); // Initial to success $xml_errnum = QuickBooks_XML::ERROR_OK; $err_code = QuickBooks_IPP::ERROR_OK; // Try to parse the XML IDS response $errnum = QuickBooks_XML::ERROR_OK; $errmsg = null; if ($Doc = $Parser->parse($errnum, $errmsg)) { $Root = $Doc->getRoot(); $List = current($Root->children()); switch ($optype) { case QuickBooks_IPP_IDS::OPTYPE_REPORT: // Parse a REPORT type response $Report = new QuickBooks_IPP_Object_Report('@todo Make sure we show the title of the report!'); foreach ($List->children() as $Child) { $class = 'QuickBooks_IPP_Object_' . $Child->name(); $Object = new $class(); foreach ($Child->children() as $Data) { $this->_push($Data, $Object); } $method = 'add' . $Child->name(); $Report->{$method}($Object); } return $Report; break; case QuickBooks_IPP_IDS::OPTYPE_QUERY: // Parse a QUERY type response // Parse a QUERY type response case QuickBooks_IPP_IDS::OPTYPE_FINDBYID: //print_r($List); //exit; //print_r($Root); //exit; // Stupid QuickBooks Online... *sigh* if ($optype == QuickBooks_IPP_IDS::OPTYPE_FINDBYID and $flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) { $List = new QuickBooks_XML_Node(__CLASS__ . '__line_' . __LINE__); $List->addChild($Root); } //print_r($List); //exit; // Normal parsing of query results $list = array(); foreach ($List->children() as $Child) { $class = 'QuickBooks_IPP_Object_' . $Child->name(); $Object = new $class(); foreach ($Child->children() as $Data) { $this->_push($Data, $Object); } $list[] = $Object; } return $list; break; case QuickBooks_IPP_IDS::OPTYPE_ADD: // Parse an ADD type response // Parse an ADD type response case QuickBooks_IPP_IDS::OPTYPE_MOD: //print("\n\n\n" . 'response was: ' . $List->name() . "\n\n\n"); //print_r('list name [' . $List->name() . ']'); switch ($List->name()) { case 'Id': // This is what QuickBooks Online, IDS v2 does return QuickBooks_IPP_IDS::buildIDType($List->getAttribute('idDomain'), $List->data()); case 'Error': $err_code = $List->getChildDataAt('Error ErrorCode'); $err_desc = $List->getChildDataAt('Error ErrorDesc'); $err_db = $List->getChildDataAt('Error DBErrorCode'); return false; case 'Success': $checks = array('Success PartyRoleRef Id', 'Success PartyRoleRef PartyReferenceId', 'Success ObjectRef Id'); foreach ($checks as $xpath) { $IDNode = $List->getChildAt($xpath); if ($IDNode) { return QuickBooks_IPP_IDS::buildIDType($IDNode->getAttribute('idDomain'), $IDNode->data()); } } $err_code = QuickBooks_IPP::ERROR_INTERNAL; $err_desc = 'Could not locate unique ID in response: ' . $xml; $err_db = ''; return false; default: // This should never happen unless Keith neglected // to implement some part of the IPP/IDS spec $err_code = QuickBooks_IPP::ERROR_INTERNAL; $err_desc = 'The parseIDS() method could not understand node [' . $List->name() . '] in response: ' . $xml; $err_db = null; return false; } break; default: $err_code = QuickBooks_IPP::ERROR_INTERNAL; $err_desc = 'The parseIDS() method could not understand the specified optype: [' . $optype . ']'; $err_db = null; return false; } } else { $xml_errnum = $errnum; $xml_errmsg = $errmsg; return false; } }
/** * 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; } */ }
/** * 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; }