Exemplo n.º 1
0
 public function asIDSXML($indent = 0, $parent = null, $optype = null, $flavor = null)
 {
     // We're not going to actually change the data, just change a copy of it
     $data = $this->_data;
     if (!$parent) {
         $parent = $this->resource();
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_ADD or $optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
             $xml = str_repeat("\t", $indent) . '<' . $this->resource() . ' xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns2="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:ns3="http://www.intuit.com/sb/cdm/qbo">' . QUICKBOOKS_CRLF;
         } else {
             $xml = str_repeat("\t", $indent) . '<Object xsi:type="' . $this->resource() . '">' . QUICKBOOKS_CRLF;
         }
         // Merge in the defaults for this object type
         $data = array_merge($this->_defaults(), $data);
     } else {
         if ($parent == 'CustomField') {
             $xml = str_repeat("\t", $indent) . '<' . $parent . ' xsi:type="StringTypeCustomField">' . QUICKBOOKS_CRLF;
         } else {
             $xml = str_repeat("\t", $indent) . '<' . $parent . '>' . QUICKBOOKS_CRLF;
         }
     }
     // Re-order is correctly
     $data = $this->_reorder($data);
     // Go through the data, creating XML out of it
     foreach ($data as $key => $value) {
         if (is_object($value)) {
             // If this causes problems, it can be commented out. It handles only situations where you are ->set(...)ing full objects, which can also be done by ->add(...)ing full objects instead
             $xml .= $value->asIDSXML($indent + 1, null, null, $flavor);
         } else {
             if (is_array($value)) {
                 foreach ($value as $skey => $svalue) {
                     //print('converting array: [' . $key . ' >> ' . $skey . ']');
                     if (is_object($svalue)) {
                         $xml .= $svalue->asIDSXML($indent + 1, $key, null, $flavor);
                     } else {
                         if (substr($key, -2, 2) == 'Id') {
                             $for_qbxml = false;
                             $tmp = QuickBooks_IPP_IDS::parseIdType($svalue);
                             if ($tmp[0]) {
                                 $xml .= str_repeat("\t", $indent + 1) . '<' . $key . ' idDomain="' . $tmp[0] . '">';
                             } else {
                                 $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                             }
                             $xml .= QuickBooks_XML::encode($tmp[1], $for_qbxml);
                             $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                         } else {
                             //$for_qbxml = false;
                             //
                             //$xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                             //$xml .= QuickBooks_XML::encode($value, $for_qbxml);
                             //$xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                             $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>' . QuickBooks_XML::encode($svalue, false) . '</' . $key . '>' . QUICKBOOKS_CRLF;
                         }
                     }
                 }
             } else {
                 if (substr($key, -2, 2) == 'Id') {
                     $for_qbxml = false;
                     $tmp = QuickBooks_IPP_IDS::parseIdType($value);
                     if ($tmp[0]) {
                         $xml .= str_repeat("\t", $indent + 1) . '<' . $key . ' idDomain="' . $tmp[0] . '">';
                     } else {
                         $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                     }
                     $xml .= QuickBooks_XML::encode($tmp[1], $for_qbxml);
                     $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                 } else {
                     $for_qbxml = false;
                     $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                     $xml .= QuickBooks_XML::encode($value, $for_qbxml);
                     $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                 }
             }
         }
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_ADD or $optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
             $xml .= str_repeat("\t", $indent) . '</' . $this->resource() . '>' . QUICKBOOKS_CRLF;
         } else {
             $xml .= str_repeat("\t", $indent) . '</Object>' . QUICKBOOKS_CRLF;
         }
     } else {
         $xml .= str_repeat("\t", $indent) . '</' . $parent . '>' . QUICKBOOKS_CRLF;
     }
     return $xml;
 }