/** * Turns a passed Match class into the required markup for interacting * with Twinfield. * * This method doesn't return anything, instead just adds the Match to * this DOMDOcument instance for submission usage. * * @access public * @param \Pronamic\Twinfield\Match\Match $match * @return void | [Adds to this instance] */ public function addMatch(Match $match) { // Match->header elements and their methods $matchTags = array('office' => 'getOffice', 'matchcode' => 'getCode', 'matchdate' => 'getDate'); // Go through each Match element and use the assigned method foreach ($matchTags as $tag => $method) { // Make text node for method value $node = $this->createTextNode($match->{$method}()); // Make the actual element and assign the node $element = $this->createElement($tag); $element->appendChild($node); // Add the full element $this->setElement->appendChild($element); } $lines = $match->getLines(); if (!empty($lines)) { $linesElement = $this->createElement('lines'); $this->setElement->appendChild($linesElement); // Element tags and their methods for lines $lineTags = ['transcode' => 'getTransCode', 'transnumber' => 'getTransNumber', 'transline' => 'getTransLine', 'matchvalue' => 'getMatchValue']; // Go through each line assigned to the Match foreach ($lines as $line) { // Makes new MatchLine element $lineElement = $this->createElement('line'); $linesElement->appendChild($lineElement); // Go through each line element and use the assigned method foreach ($lineTags as $tag => $method) { // Make the text node for the method value $value = $line->{$method}(); if ($value === null) { continue; } $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); } } } }