コード例 #1
0
ファイル: OfficeTest.php プロジェクト: atanenl/twinfield
 /**
  * @covers Pronamic\Twinfield\Customer\Customer::setOffice
  * @todo   Implement testSetOffice().
  */
 public function testSetOffice()
 {
     $customer = new Customer();
     $customer->setOffice($this->office);
     $this->assertEquals($this->office, $customer->getOffice());
     return $customer;
 }
コード例 #2
0
ファイル: CustomerMapper.php プロジェクト: japaveh/twinfield
 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;
 }
コード例 #3
0
 /**
  * Turns a passed Customer class into the required markup for interacting
  * with Twinfield.
  *
  * This method doesn't return anything, instead just adds the invoice to
  * this DOMDOcument instance for submission usage.
  *
  * @access public
  * @param \Pronamic\Twinfield\Customer\Customer $customer
  * @return void | [Adds to this instance]
  */
 public function addCustomer(Customer $customer)
 {
     // Elements and their associated methods for customer
     $customerTags = array('code' => 'getCode', 'name' => 'getName', 'type' => 'getType', 'website' => 'getWebsite', 'office' => 'getOffice');
     if ($customer->getOffice()) {
         $customerTags['office'] = 'getOffice';
     }
     $status = $customer->getStatus();
     if (!empty($status)) {
         $this->dimensionElement->setAttribute('status', $status);
     }
     // Go through each customer element and use the assigned method
     foreach ($customerTags as $tag => $method) {
         // Make text node for method value
         $node = $this->createTextNode($customer->{$method}());
         // Make the actual element and assign the node
         $element = $this->createElement($tag);
         $element->appendChild($node);
         // Add the full element
         $this->dimensionElement->appendChild($element);
     }
     // Check if the financial information should be supplied
     if ($customer->getDueDays() > 0) {
         // Financial elements and their methods
         $financialsTags = array('duedays' => 'getDueDays', 'payavailable' => 'getPayAvailable', 'paycode' => 'getPayCode', 'vatcode' => 'getVatCode', 'ebilling' => 'getEBilling', 'ebillmail' => 'getEBillMail');
         // Make the financial element
         $financialElement = $this->createElement('financials');
         $this->dimensionElement->appendChild($financialElement);
         // Go through each financial element and use the assigned method
         foreach ($financialsTags as $tag => $method) {
             // Make the text node for the method value
             $node = $this->createTextNode($customer->{$method}());
             // Make the actual element and assign the node
             $element = $this->createElement($tag);
             $element->appendChild($node);
             // Add the full element
             $financialElement->appendChild($element);
         }
     }
     //check if creditmanagement should be set
     if ($customer->getCreditManagement() !== null) {
         // Credit management elements and their methods
         $creditManagementTags = array('responsibleuser' => 'getResponsibleUser', 'basecreditlimit' => 'getBaseCreditLimit', 'sendreminder' => 'getSendReminder', 'reminderemail' => 'getReminderEmail', 'blocked' => 'getBlocked', 'freetext1' => 'getFreeText1', 'freetext2' => 'getFreeText2', 'comment' => 'getComment');
         // Make the creditmanagement element
         $creditManagementElement = $this->createElement('creditmanagement');
         $this->dimensionElement->appendChild($creditManagementElement);
         // Go through each credit management element and use the assigned method
         foreach ($creditManagementTags as $tag => $method) {
             // Make the text node for the method value
             $nodeValue = $customer->getCreditManagement()->{$method}();
             if (is_bool($nodeValue)) {
                 $nodeValue = $nodeValue ? 'true' : 'false';
             }
             $node = $this->createTextNode($nodeValue);
             // Make the actual element and assign the node
             $element = $this->createElement($tag);
             $element->appendChild($node);
             // Add the full element
             $creditManagementElement->appendChild($element);
         }
     }
     $addresses = $customer->getAddresses();
     if (!empty($addresses)) {
         // Address elements and their methods
         $addressTags = array('name' => 'getName', 'contact' => 'getContact', 'country' => 'getCountry', 'city' => 'getCity', 'postcode' => 'getPostcode', 'telephone' => 'getTelephone', 'telefax' => 'getFax', 'email' => 'getEmail', 'field1' => 'getField1', 'field2' => 'getField2', 'field3' => 'getField3', 'field4' => 'getField4', 'field5' => 'getField5', 'field6' => 'getField6');
         // Make addresses element
         $addressesElement = $this->createElement('addresses');
         $this->dimensionElement->appendChild($addressesElement);
         // Go through each address assigned to the customer
         foreach ($addresses as $address) {
             // Makes new address element
             $addressElement = $this->createElement('address');
             $addressesElement->appendChild($addressElement);
             // Set attributes
             $addressElement->setAttribute('default', $address->getDefault());
             $addressElement->setAttribute('type', $address->getType());
             // Go through each address element and use the assigned method
             foreach ($addressTags as $tag => $method) {
                 // Make the text node for the method value
                 $node = $this->createTextNode($address->{$method}());
                 // Make the actual element and assign the text node
                 $element = $this->createElement($tag);
                 $element->appendChild($node);
                 // Add the completed element
                 $addressElement->appendChild($element);
             }
         }
     }
     $banks = $customer->getBanks();
     if (!empty($banks)) {
         // Bank elements and their methods
         $bankTags = array('ascription' => 'getAscription', 'accountnumber' => 'getAccountnumber', 'bankname' => 'getBankname', 'biccode' => 'getBiccode', 'city' => 'getCity', 'country' => 'getCountry', 'iban' => 'getIban', 'natbiccode' => 'getNatbiccode', 'postcode' => 'getPostcode', 'state' => 'getState');
         // Make banks element
         $banksElement = $this->createElement('banks');
         $this->dimensionElement->appendChild($banksElement);
         // Go through each bank assigned to the customer
         foreach ($banks as $bank) {
             // Makes new bank element
             $bankElement = $this->createElement('bank');
             $banksElement->appendChild($bankElement);
             // Set attributes
             $bankElement->setAttribute('default', $bank->getDefault());
             // Go through each bank element and use the assigned method
             foreach ($bankTags as $tag => $method) {
                 // Make the text node for the method value
                 $node = $this->createTextNode($bank->{$method}());
                 // Make the actual element and assign the text node
                 $element = $this->createElement($tag);
                 $element->appendChild($node);
                 // Add the completed element
                 $bankElement->appendChild($element);
             }
             // Bank address fields
             // Make the text nodes for the bank address fields
             $field2Node = $this->createTextNode($bank->getAddressField2());
             $field3Node = $this->createTextNode($bank->getAddressField3());
             // Make the actual elements and assign the text nodes
             $field2Element = $this->createElement('field2');
             $field3Element = $this->createElement('field3');
             $field2Element->appendChild($field2Node);
             $field3Element->appendChild($field3Node);
             // Combine the fields in an address element and add that to the bank element
             $addressElement = $this->createElement('address');
             $addressElement->appendChild($field2Element);
             $addressElement->appendChild($field3Element);
             $bankElement->appendChild($addressElement);
         }
     }
 }
コード例 #4
0
ファイル: CustomerMapper.php プロジェクト: atanenl/twinfield
 /**
  * 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;
 }
コード例 #5
0
 public function addCustomer(Customer $customer)
 {
     // Makes code element
     $codeElement = $this->createElement('code');
     $codeElement->appendChild($this->createTextNode($customer->getID()));
     $this->dimensionElement->appendChild($codeElement);
     // Make name element
     $nameElement = $this->createElement('name');
     $nameElement->appendChild($this->createTextNode($customer->getName()));
     $this->dimensionElement->appendChild($nameElement);
     // Make type element
     $typeElement = $this->createElement('type');
     $typeElement->appendChild($this->createTextNode($customer->getType()));
     $this->dimensionElement->appendChild($typeElement);
     // Make website element
     $websiteElement = $this->createElement('website');
     $websiteElement->appendChild($this->createTextNode($customer->getWebsite()));
     $this->dimensionElement->appendChild($websiteElement);
     // Test coc element
     $cocNumberElement = $this->createElement('cocnumber');
     $cocNumberElement->appendChild($this->createTextNode($customer->getCocNumber()));
     $this->dimensionElement->appendChild($cocNumberElement);
     if ($customer->getDueDays() > 0) {
         // Make financial element
         $financialElement = $this->createElement('financials');
         $this->dimensionElement->appendChild($financialElement);
         // Set financial child elements
         $dueDaysElement = $this->createElement('duedays');
         $dueDaysElement->appendChild($this->createTextNode($customer->getDueDays()));
         $payAvailableElement = $this->createElement('payavailable');
         $payAvailableElement->appendChild($this->createTextNode($customer->getPayAvailable()));
         $payCodeElement = $this->createElement('paycode');
         $payCodeElement->appendChild($this->createTextNode($customer->getPayCode()));
         $vatCodeElement = $this->createElement('vatcode');
         $vatCodeElement->appendChild($this->createTextNode($customer->getVatCode()));
         $eBillingElement = $this->createElement('ebilling');
         $eBillingElement->appendChild($this->createTextNode($customer->getEBilling()));
         $eBillMailElement = $this->createElement('ebillmail');
         $eBillMailElement->appendChild($this->createTextNode($customer->getEBillMail()));
         // Add these to the financial element
         $financialElement->appendChild($dueDaysElement);
         $financialElement->appendChild($payAvailableElement);
         $financialElement->appendChild($payCodeElement);
         $financialElement->appendChild($vatCodeElement);
         $financialElement->appendChild($eBillingElement);
         $financialElement->appendChild($eBillMailElement);
     }
     // Make address element
     $addressesElement = $this->createElement('addresses');
     $this->dimensionElement->appendChild($addressesElement);
     foreach ($customer->getAddresses() as $address) {
         // Makes new address element
         $addressElement = $this->createElement('address');
         $addressesElement->appendChild($addressElement);
         // Set attributes
         $addressElement->setAttribute('default', $address->getDefault());
         $addressElement->setAttribute('type', $address->getType());
         // Build elements
         $aNameElement = $this->createElement('name');
         $aNameElement->appendChild($this->createTextNode($address->getName()));
         $countryElement = $this->createElement('country');
         $countryElement->appendChild($this->createTextNode($address->getCountry()));
         $cityElement = $this->createElement('city');
         $cityElement->appendChild($this->createTextNode($address->getCity()));
         $postcodeElement = $this->createElement('postcode');
         $postcodeElement->appendChild($this->createTextNode($address->getPostcode()));
         $telephoneElement = $this->createElement('telephone');
         $telephoneElement->appendChild($this->createTextNode($address->getTelephone()));
         $faxElement = $this->createElement('telefax');
         $faxElement->appendChild($this->createTextNode($address->getFax()));
         $emailElement = $this->createElement('email');
         $emailElement->appendChild($this->createTextNode($address->getEmail()));
         $field1Element = $this->createElement('field1');
         $field1Element->appendChild($this->createTextNode($address->getField1()));
         $field2Element = $this->createElement('field2');
         $field2Element->appendChild($this->createTextNode($address->getField2()));
         $field3Element = $this->createElement('field3');
         $field3Element->appendChild($this->createTextNode($address->getField3()));
         $field4Element = $this->createElement('field4');
         $field4Element->appendChild($this->createTextNode($address->getField4()));
         $field5Element = $this->createElement('field5');
         $field5Element->appendChild($this->createTextNode($address->getField5()));
         $field6Element = $this->createElement('field6');
         $field6Element->appendChild($this->createTextNode($address->getField6()));
         // Add these elements to the address
         $addressElement->appendChild($aNameElement);
         $addressElement->appendChild($countryElement);
         $addressElement->appendChild($cityElement);
         $addressElement->appendChild($postcodeElement);
         $addressElement->appendChild($telephoneElement);
         $addressElement->appendChild($faxElement);
         $addressElement->appendChild($emailElement);
         $addressElement->appendChild($field1Element);
         $addressElement->appendChild($field2Element);
         $addressElement->appendChild($field3Element);
         $addressElement->appendChild($field4Element);
         $addressElement->appendChild($field5Element);
         $addressElement->appendChild($field6Element);
     }
 }