Exemple #1
0
 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;
     }
 }