Example #1
0
 /**
  * Turns a passed Article class into the required markup for interacting
  * with Twinfield.
  * 
  * This method doesn't return anything, instead just adds the Article to 
  * this DOMDOcument instance for submission usage.
  * 
  * @access public
  * @param \Pronamic\Twinfield\Article\Article $article
  * @return void | [Adds to this instance]
  */
 public function addArticle(Article $article)
 {
     // Article->header elements and their methods
     $articleTags = array('office' => 'getOffice', 'code' => 'getCode', 'type' => 'getType', 'name' => 'getName', 'shortname' => 'getShortName', 'unitnamesingular' => 'getUnitNameSingular', 'unitnameplural' => 'getUnitNamePlural', 'vatcode' => 'getVatCode', 'allowchangevatcode' => 'getAllowChangeVatCode', 'allowdiscountorpremium' => 'getAllowDiscountorPremium', 'allowchangeunitsprice' => 'getAllowChangeUnitsPrice', 'allowdecimalquantity' => 'getAllowDecimalQuantity', 'performancetype' => 'getPerformanceType', 'percentage' => 'getPercentage');
     // Make header element
     $headerElement = $this->createElement('header');
     $this->articleElement->appendChild($headerElement);
     $status = $article->getStatus();
     if (!empty($status)) {
         $headerElement->setAttribute('status', $status);
     }
     // Go through each Article element and use the assigned method
     foreach ($articleTags as $tag => $method) {
         // Make text node for method value
         $node = $this->createTextNode($article->{$method}());
         // Make the actual element and assign the node
         $element = $this->createElement($tag);
         $element->appendChild($node);
         // Add the full element
         $headerElement->appendChild($element);
     }
     $lines = $article->getLines();
     if (!empty($lines)) {
         // Element tags and their methods for lines
         $lineTags = ['unitspriceexcl' => 'getUnitsPriceExcl', 'unitspriceinc' => 'getUnitsPriceInc', 'units' => 'getUnits', 'name' => 'getName', 'shortname' => 'getShortName', 'subcode' => 'getSubCode', 'freetext1' => 'getFreeText1'];
         // Make addresses element
         $linesElement = $this->createElement('lines');
         $this->articleElement->appendChild($linesElement);
         // Go through each line assigned to the article
         foreach ($lines as $line) {
             // Makes new articleLine element
             $lineElement = $this->createElement('line');
             $linesElement->appendChild($lineElement);
             $status = $line->getStatus();
             $id = $line->getID();
             $inUse = $line->getInUse();
             if (!empty($status)) {
                 $lineElement->setAttribute('status', $status);
             }
             if (!empty($id)) {
                 $lineElement->setAttribute('id', $id);
             }
             if (!empty($inUse)) {
                 $lineElement->setAttribute('inuse', $inUse);
             }
             // Go through each line element and use the assigned method
             foreach ($lineTags as $tag => $method) {
                 // Make the text node for the method value
                 $node = $this->createTextNode($line->{$method}());
                 // Make the actual element and assign the text node
                 $element = $this->createElement($tag);
                 $element->appendChild($node);
                 // Add the completed element
                 $lineElement->appendChild($element);
             }
         }
     }
 }