/** * @param Response $response * * @return Transaction{} */ public static function map(Response $response) { // Get the raw DOMDocument response $responseDOM = $response->getResponseDocument(); // All tags for the transaction $transactionTags = array('code' => 'setCode', 'currency' => 'setCurrency', 'date' => 'setDate', 'period' => 'setPeriod', 'invoicenumber' => 'setInvoiceNumber', 'office' => 'setOffice', 'duedate' => 'setDueDate', 'origin' => 'setOrigin', 'number' => 'setNumber', 'freetext1' => 'setFreetext1', 'freetext2' => 'setFreetext2', 'freetext3' => 'setFreetext3'); // Make new Transaction Object $transactions = array(); // Get the top level transaction element $transactionElements = $responseDOM->getElementsByTagName('transaction'); foreach ($transactionElements as $transactionElement) { // create new transaction $transaction = new Transaction(); // set the result $result = $transactionElement->getAttribute('result'); $transaction->setResult($result); // Set the destiny/location $location = $transactionElement->getAttribute('location'); $transaction->setDestiny($location); // Set the raise warning $raiseWarning = $transactionElement->getAttribute('raisewarning'); $transaction->setRaiseWarning($raiseWarning); // Go through each tag and call the method if a value is set foreach ($transactionTags as $tag => $method) { $_tag = $transactionElement->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $transaction->{$method}($_tag->textContent); } // msg if (isset($_tag) && $_tag->hasAttribute('msg')) { $message = new Message(); $message->setType($_tag->getAttribute('msgtype')); $message->setMessage($_tag->getAttribute('msg')); $message->setField($tag); $transaction->addMessage($message); } } $lineTags = array('dim1' => 'setDim1', 'dim2' => 'setDim2', 'value' => 'setValue', 'debitcredit' => 'setDebitCredit', 'description' => 'setDescription', 'rate' => 'setRate', 'basevalue' => 'setBaseValue', 'reprate' => 'setRepRate', 'vatcode' => 'setVatCode', 'vattotal' => 'setVatTotal', 'vatvalue' => 'setVatValue', 'vatbasetotal' => 'setVatBaseTotal', 'customersupplier' => 'setCustomerSupplier', 'basevalueopen' => 'setBaseValueOpen', 'valueopen' => 'setValueOpen', 'repvalue' => 'setRepValue', 'matchlevel' => 'setMatchLevel', 'matchstatus' => 'setMatchStatus'); foreach ($transactionElement->getElementsByTagName('line') as $lineDOM) { $temp_line = new TransactionLine(); $lineType = $lineDOM->getAttribute('type'); $temp_line->setType($lineType); $lineID = $lineDOM->getAttribute('id'); $temp_line->setID($lineID); foreach ($lineTags as $tag => $method) { $_tag = $lineDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $temp_line->{$method}($_tag->textContent); } } $transaction->addLine($temp_line); unset($lineType); unset($temp_line); } // add $transactions[] = $transaction; } // for backwards compatibility, return only the first instance if there is only one return count($transactions) == 1 ? $transactions[0] : $transactions; }
public static function map(Response $response) { $responseDOM = $response->getResponseDocument(); $invoiceTags = array('office' => 'setOffice', 'invoicetype' => 'setInvoiceType', 'invoicenumber' => 'setInvoiceNumber', 'status' => 'setStatus', 'currency' => 'setCurrency', 'period' => 'setPeriod', 'invoicedate' => 'setInvoiceDate', 'duedate' => 'setDueDate', 'performancedate' => 'setPerformanceDate', 'paymentmethod' => 'setPaymentMethod', 'bank' => 'setBank', 'invoiceaddressnumber' => 'setInvoiceAddressNumber', 'deliveraddressnumber' => 'setDeliverAddressNumber', 'headertext' => 'setHeaderText', 'footertext' => 'setFooterText'); $customerTags = array('customer' => 'setCode'); $totalsTags = array('valueexcl' => 'setValueExcl', 'valueinc' => 'setValueInc'); // Generate new Invoice $invoice = new Invoice(); // Loop through all invoice tags foreach ($invoiceTags as $tag => $method) { $_tag = $responseDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $invoice->{$method}($_tag->textContent); } } // Make a custom, and loop through custom tags $customer = new Customer(); foreach ($customerTags as $tag => $method) { $_tag = $responseDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $customer->{$method}($_tag->textContent); } } // Make an InvoiceTotals and loop through custom tags $invoiceTotals = new InvoiceTotals(); foreach ($totalsTags as $tag => $method) { $_tag = $responseDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $invoiceTotals->{$method}($_tag->textContent); } } // Set the custom classes to the invoice $invoice->setCustomer($customer); $invoice->setTotals($invoiceTotals); $lineTags = array('article' => 'setArticle', 'subarticle' => 'setSubArticle', 'quantity' => 'setQuantity', 'units' => 'setUnits', 'allowdiscountorpremium' => 'setAllowDiscountOrPremium', 'description' => 'setDescription', 'valueexcl' => 'setValueExcl', 'vatvalue' => 'setVatValue', 'valueinc' => 'setValueInc', 'unitspriceexcl' => 'setUnitsPriceExcl', 'unitspriceinc' => 'setUnitsPriceInc', 'freetext1' => 'setFreeText1', 'freetext2' => 'setFreeText2', 'freetext3' => 'setFreeText3', 'performancedate' => 'setPerformanceDate'); foreach ($responseDOM->getElementsByTagName('line') as $lineDOM) { $temp_line = new InvoiceLine(); $temp_line->setID($lineDOM->getAttribute('id')); foreach ($lineTags as $tag => $method) { $_tag = $lineDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $temp_line->{$method}($_tag->textContent); } } $invoice->addLine($temp_line); unset($temp_line); } return $invoice; }
/** * Maps a Response object to a clean Match entity. * * @access public * @param \Pronamic\Twinfield\Response\Response $response * @return \Pronamic\Twinfield\Match\Match */ public static function map(Response $response) { // Generate new Match object $Match = new Match(); // Gets the raw DOMDocument response. $responseDOM = $response->getResponseDocument(); // Set the status attribute $dimensionElement = $responseDOM->getElementsByTagName('header')->item(0); $Match->setDate($dimensionElement->getAttribute('status')); // Match elements and their methods $MatchTags = ['code' => 'setCode', 'office' => 'setOffice', 'type' => 'setType', 'name' => 'setName', 'shortname' => 'setShortName', 'unitnamesingular' => 'setUnitNameSingular', 'unitnameplural' => 'setUnitNamePlural', 'vatcode' => 'setVatCode', 'allowchangevatcode' => 'setAllowChangeVatCode', 'performancetype' => 'setPerformanceType', 'allowchangeperformancetype' => 'setAllowChangePerformanceType', 'percentage' => 'setPercentage', 'allowdiscountorpremium' => 'setAllowDiscountorPremium', 'allowchangeunitsprice' => 'setAllowChangeUnitsPrice', 'allowdecimalquantity' => 'setAllowDecimalQuantity']; // Loop through all the tags foreach ($MatchTags as $tag => $method) { // Get the dom element $_tag = $responseDOM->getElementsByTagName($tag)->item(0); // If it has a value, set it to the associated method if (isset($_tag) && isset($_tag->textContent)) { $Match->{$method}($_tag->textContent); } } $linesDOMTag = $responseDOM->getElementsByTagName('lines'); if (isset($linesDOMTag) && $linesDOMTag->length > 0) { // Element tags and their methods for lines $lineTags = ['unitspriceexcl' => 'setUnitsPriceExcl', 'unitspriceinc' => 'setUnitsPriceInc', 'units' => 'setUnits', 'name' => 'setName', 'shortname' => 'setShortName', 'subcode' => 'setSubCode', 'freetext1' => 'setFreeText1']; $linesDOM = $linesDOMTag->item(0); // Loop through each returned line for the Match foreach ($linesDOM->getElementsByTagName('line') as $lineDOM) { // Make a new tempory MatchLine class $MatchLine = new MatchLine(); // Set the attributes ( id,status,inuse) $MatchLine->setID($lineDOM->getAttribute('id'))->setTransCode($lineDOM->getAttribute('status'))->setTransNumber($lineDOM->getAttribute('inuse')); // Loop through the element tags. Determine if it exists and set it if it does foreach ($lineTags as $tag => $method) { // Get the dom element $_tag = $lineDOM->getElementsByTagName($tag)->item(0); // Check if the tag is set, and its content is set, to prevent DOMNode errors if (isset($_tag) && isset($_tag->textContent)) { $MatchLine->{$method}($_tag->textContent); } } // Add the bank to the customer $Match->addLine($MatchLine); // Clean that memory! unset($MatchLine); } } return $Match; }
public static function map(Response $response) { $responseDOM = $response->getResponseDocument(); $customerTags = array('code' => 'setID', 'uid' => 'setUID', 'name' => 'setName', 'inuse' => 'setInUse', 'behaviour' => 'setBehaviour', 'touched' => 'setTouched', 'beginperiod' => 'setBeginPeriod', 'endperiod' => 'setEndPeriod', 'endyear' => 'setEndYear', 'website' => 'setWebsite', 'cocnumber' => 'setCocNumber', 'vatnumber' => 'setVatNumber', 'editdimensionname' => 'setEditDimensionName'); // Generate new customer object $customer = new Customer(); // Loop through all the tags foreach ($customerTags as $tag => $method) { $_tag = $responseDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $customer->{$method}($_tag->textContent); } } $financialTags = array('duedays' => 'setDueDays', 'payavailable' => 'setPayAvailable', 'paycode' => 'setPayCode', 'ebilling' => 'setEBilling', 'ebillmail' => 'setEBillMail'); // Financial elements $financialElement = $responseDOM->getElementsByTagName('financials')->item(0); foreach ($financialTags as $tag => $method) { $_tag = $financialElement->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $customer->{$method}($_tag->textContent); } } // Element tags and their methods for address $address_tags = array('name' => 'setName', 'country' => 'setCountry', 'city' => 'setCity', 'postcode' => 'setPostcode', 'telephone' => 'setTelephone', 'telefax' => 'setFax', 'email' => 'setEmail', 'field1' => 'setField1', 'field2' => 'setField2', 'field3' => 'setField3', 'field4' => 'setField4', 'field5' => 'setField5', 'field6' => 'setField6'); // Build address entries foreach ($responseDOM->getElementsByTagName('address') as $addressDOM) { // Make a new temp customeraddress class $temp_address = new CustomerAddress(); // Set the default properties ( id, type, default ) $temp_address->setID($addressDOM->getAttribute('id'))->setType($addressDOM->getAttribute('type'))->setDefault($addressDOM->getAttribute('default')); // Loop through the element tags. Determine if it exists and set it if it does foreach ($address_tags as $tag => $method) { $_tag = $addressDOM->getElementsByTagName($tag)->item(0); // Check if the tag is set, and its content is set, to prevent DOMNode errors if (isset($_tag) && isset($_tag->textContent)) { $temp_address->{$method}($_tag->textContent); } } // Add the address to the customer $customer->addAddress($temp_address); // Clean that memory! unset($temp_address); } return $customer; }
/** * Maps a Response object to a clean Customer entity. * * @access public * @param \Pronamic\Twinfield\Response\Response $response * @return \Pronamic\Twinfield\Customer\Customer */ public static function map(Response $response) { // Generate new customer object $customer = new Customer(); // Gets the raw DOMDocument response. $responseDOM = $response->getResponseDocument(); // Set the status attribute $dimensionElement = $responseDOM->getElementsByTagName('dimension')->item(0); $customer->setStatus($dimensionElement->getAttribute('status')); // Customer elements and their methods $customerTags = array('code' => 'setCode', 'uid' => 'setUID', 'name' => 'setName', 'inuse' => 'setInUse', 'behaviour' => 'setBehaviour', 'touched' => 'setTouched', 'beginperiod' => 'setBeginPeriod', 'endperiod' => 'setEndPeriod', 'endyear' => 'setEndYear', 'website' => 'setWebsite', 'editdimensionname' => 'setEditDimensionName', 'office' => 'setOffice'); // Loop through all the tags foreach ($customerTags as $tag => $method) { // Get the dom element $_tag = $responseDOM->getElementsByTagName($tag)->item(0); // If it has a value, set it to the associated method if (isset($_tag) && isset($_tag->textContent)) { $customer->{$method}($_tag->textContent); } } // Financial elements and their methods $financialsTags = array('duedays' => 'setDueDays', 'payavailable' => 'setPayAvailable', 'paycode' => 'setPayCode', 'ebilling' => 'setEBilling', 'ebillmail' => 'setEBillMail'); // Financial elements $financialElement = $responseDOM->getElementsByTagName('financials')->item(0); // Go through each financial element and add to the assigned method foreach ($financialsTags as $tag => $method) { // Get the dom element $_tag = $financialElement->getElementsByTagName($tag)->item(0); // If it has a value, set it to the associated method if (isset($_tag) && isset($_tag->textContent)) { $customer->{$method}($_tag->textContent); } } // Credit management elements $creditManagementElement = $responseDOM->getElementsByTagName('creditmanagement')->item(0); // Credit management elements and their methods $creditManagementTags = array('responsibleuser' => 'setResponsibleUser', 'basecreditlimit' => 'setBaseCreditLimit', 'sendreminder' => 'setSendReminder', 'reminderemail' => 'setReminderEmail', 'blocked' => 'setBlocked', 'freetext1' => 'setFreeText1', 'freetext2' => 'setFreeText2', 'comment' => 'setComment'); $customer->setCreditManagement(new \Pronamic\Twinfield\Customer\CustomerCreditManagement()); // Go through each financial element and add to the assigned method foreach ($creditManagementTags as $tag => $method) { // Get the dom element $_tag = $creditManagementElement->getElementsByTagName($tag)->item(0); // If it has a value, set it to the associated method if (isset($_tag) && isset($_tag->textContent)) { $customer->getCreditManagement()->{$method}($_tag->textContent); } } $addressesDOMTag = $responseDOM->getElementsByTagName('addresses'); if (isset($addressesDOMTag) && $addressesDOMTag->length > 0) { // Element tags and their methods for address $addressTags = array('name' => 'setName', 'contact' => 'setContact', 'country' => 'setCountry', 'city' => 'setCity', 'postcode' => 'setPostcode', 'telephone' => 'setTelephone', 'telefax' => 'setFax', 'email' => 'setEmail', 'field1' => 'setField1', 'field2' => 'setField2', 'field3' => 'setField3', 'field4' => 'setField4', 'field5' => 'setField5', 'field6' => 'setField6'); $addressesDOM = $addressesDOMTag->item(0); // Loop through each returned address for the customer foreach ($addressesDOM->getElementsByTagName('address') as $addressDOM) { // Make a new tempory CustomerAddress class $temp_address = new CustomerAddress(); // Set the attributes ( id, type, default ) $temp_address->setID($addressDOM->getAttribute('id'))->setType($addressDOM->getAttribute('type'))->setDefault($addressDOM->getAttribute('default')); // Loop through the element tags. Determine if it exists and set it if it does foreach ($addressTags as $tag => $method) { // Get the dom element $_tag = $addressDOM->getElementsByTagName($tag)->item(0); // Check if the tag is set, and its content is set, to prevent DOMNode errors if (isset($_tag) && isset($_tag->textContent)) { $temp_address->{$method}($_tag->textContent); } } // Add the address to the customer $customer->addAddress($temp_address); // Clean that memory! unset($temp_address); } } $banksDOMTag = $responseDOM->getElementsByTagName('banks'); if (isset($banksDOMTag) && $banksDOMTag->length > 0) { // Element tags and their methods for bank $bankTags = array('ascription' => 'setAscription', 'accountnumber' => 'setAccountnumber', 'field2' => 'setAddressField2', 'field3' => 'setAddressField3', 'bankname' => 'setBankname', 'biccode' => 'setBiccode', 'city' => 'setCity', 'country' => 'setCountry', 'iban' => 'setIban', 'natbiccode' => 'setNatbiccode', 'postcode' => 'setPostcode', 'state' => 'setState'); $banksDOM = $banksDOMTag->item(0); // Loop through each returned bank for the customer foreach ($banksDOM->getElementsByTagName('bank') as $bankDOM) { // Make a new tempory CustomerBank class $temp_bank = new CustomerBank(); // Set the attributes ( id, default ) $temp_bank->setID($bankDOM->getAttribute('id'))->setDefault($bankDOM->getAttribute('default')); // Loop through the element tags. Determine if it exists and set it if it does foreach ($bankTags as $tag => $method) { // Get the dom element $_tag = $bankDOM->getElementsByTagName($tag)->item(0); // Check if the tag is set, and its content is set, to prevent DOMNode errors if (isset($_tag) && isset($_tag->textContent)) { $temp_bank->{$method}($_tag->textContent); } } // Add the bank to the customer $customer->addBank($temp_bank); // Clean that memory! unset($temp_bank); } } return $customer; }