/** * @param Promotion $promotion * @return string */ public function toXML(Promotion $promotion) { $dom = new \DOMDocument('1.0', 'UTF-8'); $promotionNode = $dom->createElement('promotion'); $title = $dom->createElement('title', $promotion->getPromotionTitle()); $promotionNode->appendChild($title); $type = $dom->createElement('type', $promotion->getPromotionType()); $promotionNode->appendChild($type); $image = $dom->createElement('image', $promotion->getImageUrl()); $promotionNode->appendChild($image); if (trim($promotion->getLanguage()) !== '') { $language = $dom->createElement('language', $promotion->getLanguage()); $promotionNode->appendChild($language); } $searchTerms = $dom->createElement('searchterms'); foreach ($promotion->getKeywords() as $keyWord) { $keyWordNode = $dom->createElement('searchterm', $keyWord); $searchTerms->appendChild($keyWordNode); } $promotionNode->appendChild($searchTerms); $solrFieldValues = $dom->createElement('solrfieldvalues'); foreach ($promotion->getFieldValues() as $fieldName => $fieldValue) { $solrFieldValue = $dom->createElement('solrfieldvalue', $fieldValue); $fieldNameAttribute = $dom->createAttribute('fieldname'); $attributeValue = $dom->createTextNode($fieldName); $fieldNameAttribute->appendChild($attributeValue); $solrFieldValue->appendChild($fieldNameAttribute); $solrFieldValues->appendChild($solrFieldValue); } $limitedTimeFrom = $dom->createElement('limitedTimeFrom', $promotion->getLimitedTimeFrom()); $promotionNode->appendChild($limitedTimeFrom); $limitedTimeTo = $dom->createElement('limitedTimeTo', $promotion->getLimitedTimeTo()); $promotionNode->appendChild($limitedTimeTo); $promotionNode->appendChild($solrFieldValues); $content = $dom->createElement('content'); $cdata = $dom->createCDATASection($promotion->getPromotionContent()); $content->appendChild($cdata); $promotionNode->appendChild($content); $dom->appendChild($promotionNode); return $dom->saveXML(); }