public function testCreateCdbXMLGuideExample6Dot2() { $event = new CultureFeed_Cdb_Item_Event(); $event->setAvailableFrom('2010-02-25T00:00:00'); $event->setAvailableTo('2010-08-09T00:00:00'); $event->setCdbId('ea37cae2-c91e-4810-89ab-e060432d2b78'); $event->setCreatedBy('mverdoodt'); $event->setCreationDate('2010-07-05T18:28:18'); $event->setExternalId('SKB Import:SKB00001_216413'); $event->setIsParent(FALSE); $event->setLastUpdated('2010-07-28T13:58:55'); $event->setLastUpdatedBy('mverdoodt'); $event->setOwner('SKB Import'); $event->setPctComplete(80); $event->setPublished(TRUE); $event->setValidator('SKB'); $event->setWfStatus('approved'); $event->setAgeFrom(18); $event->setPrivate(FALSE); $calendar = new CultureFeed_Cdb_Data_Calendar_TimestampList(); $calendar->add(new CultureFeed_Cdb_Data_Calendar_Timestamp('2010-08-01', '21:00:00.0000000')); $event->setCalendar($calendar); $categories = new CultureFeed_Cdb_Data_CategoryList(); $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_EVENT_TYPE, '0.50.4.0.0', 'Concert')); $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_THEME, '1.8.2.0.0', 'Jazz en blues')); $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_PUBLICSCOPE, '6.2.0.0.0', 'Regionaal')); $event->setCategories($categories); $contactInfo = new CultureFeed_Cdb_Data_ContactInfo(); $contactInfo->addMail(new CultureFeed_Cdb_Data_Mail('*****@*****.**', NULL, NULL)); $contactInfo->addPhone(new CultureFeed_Cdb_Data_Phone('0487-62.22.31')); $url = new CultureFeed_Cdb_Data_Url('http://www.bonnefooi.be'); $url->setMain(); $contactInfo->addUrl($url); $event->setContactInfo($contactInfo); $details = new CultureFeed_Cdb_Data_EventDetailList(); $detailNl = new CultureFeed_Cdb_Data_EventDetail(); $detailNl->setLanguage('nl'); $detailNl->setTitle('The Bonnefooi Acoustic Jam'); $detailNl->setCalendarSummary('zo 01/08/10 om 21:00'); $performers = new CultureFeed_Cdb_Data_PerformerList(); $performers->add(new CultureFeed_Cdb_Data_Performer('Muzikant', 'Matt, the Englishman in Brussels')); $detailNl->setPerformers($performers); $detailNl->setLongDescription('Weggelaten voor leesbaarheid...'); $file = new CultureFeed_Cdb_Data_File(); $file->setMain(); $file->setCopyright('Bonnefooi'); $file->setHLink('http://www.bonnefooi.be/images/sized/site/images/uploads/Jeroen_Jamming-453x604.jpg'); $file->setMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB); $file->setTitle('Jeroen Jamming'); $detailNl->getMedia()->add($file); $price = new CultureFeed_Cdb_Data_Price(0); $price->setTitle('The Bonnefooi Acoustic Jam'); $detailNl->setPrice($price); $detailNl->setShortDescription('Korte omschrijving.'); $details->add($detailNl); $detailEn = new CultureFeed_Cdb_Data_EventDetail(); $detailEn->setLanguage('en'); $detailEn->setShortDescription('Short description.'); $details->add($detailEn); $event->setDetails($details); // @todo Add headings. //$headings = array(); $event->addKeyword('Free Jazz, Acoustisch'); $address = new CultureFeed_Cdb_Data_Address(); $physicalAddress = new CultureFeed_Cdb_Data_Address_PhysicalAddress(); $physicalAddress->setCity('Brussel'); $physicalAddress->setCountry('BE'); $physicalAddress->setHouseNumber(8); $physicalAddress->setStreet('Steenstraat'); $physicalAddress->setZip(1000); $address->setPhysicalAddress($physicalAddress); $location = new CultureFeed_Cdb_Data_Location($address); $location->setLabel('Café Bonnefooi'); $location->setCdbid('920e9755-94a0-42c1-8c8c-9d17f693d0be'); $event->setLocation($location); $organiser = new CultureFeed_Cdb_Data_Organiser(); $organiser->setLabel('Café Bonnefooi'); $event->setOrganiser($organiser); $languages = new CultureFeed_Cdb_Data_LanguageList(); $languages->add(new CultureFeed_Cdb_Data_Language('Nederlands', CultureFeed_Cdb_Data_Language::TYPE_SPOKEN)); $languages->add(new CultureFeed_Cdb_Data_Language('Frans', CultureFeed_Cdb_Data_Language::TYPE_SPOKEN)); $event->setLanguages($languages); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = FALSE; $dom->formatOutput = TRUE; $dummy_element = $dom->createElementNS(CultureFeed_Cdb_Xml::namespaceUri(), 'cdbxml'); $dom->appendChild($dummy_element); $event->appendToDOM($dummy_element); $xpath = new DOMXPath($dom); $items = $xpath->query('//event'); $this->assertEquals(1, $items->length); $event_element = $items->item(0); $dom->removeChild($dummy_element); $dom->appendChild($event_element); /*$namespaceAttribute = $dom->createAttribute('xmlns'); $namespaceAttribute->value = CultureFeed_Cdb_Xml::namespaceUri(); $event_element->appendChild($namespaceAttribute);*/ // @todo Put xmlns attribute first. $xml = $dom->saveXML(); $sample_dom = new DOMDocument('1.0', 'UTF-8'); $contents = file_get_contents($this->samplePath('cdbxml-guide-example-6-2.xml')); $contents = str_replace('xmlns="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.2/FINAL" ', '', $contents); $sample_dom->preserveWhiteSpace = FALSE; $sample_dom->formatOutput = TRUE; $sample_dom->loadXML($contents); $sample_dom->preserveWhiteSpace = FALSE; $sample_dom->formatOutput = TRUE; $expected_xml = $sample_dom->saveXML(); //$this->assertEquals($sample_dom->documentElement->C14N(), $dom->documentElement->C14N()); $this->assertEquals($expected_xml, $xml); }
/** * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement) * @return CultureFeed_Cdb_Data_Address_PhysicalAddress */ public static function parseFromCdbXml(SimpleXMLElement $xmlElement) { if (empty($xmlElement->city)) { throw new CultureFeed_Cdb_ParseException("City is missing for physical address"); } if (empty($xmlElement->country)) { throw new CultureFeed_Cdb_ParseException("Country is missing for physical address"); } if (empty($xmlElement->zipcode)) { throw new CultureFeed_Cdb_ParseException("Zip code is missing for physical address"); } $physicalAddress = new CultureFeed_Cdb_Data_Address_PhysicalAddress(); $physicalAddress->setCity((string) $xmlElement->city); $physicalAddress->setZip((string) $xmlElement->zipcode); if (!empty($xmlElement->street)) { $physicalAddress->setStreet((string) $xmlElement->street); } if (!empty($xmlElement->housenr)) { $physicalAddress->setHouseNumber((string) $xmlElement->housenr); } if (!empty($xmlElement->country)) { $physicalAddress->setCountry((string) $xmlElement->country); } if (!empty($xmlElement->gis)) { $physicalAddress->setGeoInformation(CultureFeed_Cdb_Data_Address_GeoInformation::parseFromCdbXml($xmlElement->gis)); } return $physicalAddress; }
/** * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement) * @return CultureFeed_Cdb_Item_Page */ public static function parseFromCdbXml(SimpleXMLElement $xmlElement) { if (empty($xmlElement->uid)) { throw new CultureFeed_Cdb_ParseException('Uid missing for page element'); } if (empty($xmlElement->name)) { throw new CultureFeed_Cdb_ParseException('Name missing for page element'); } $page = new self(); // Set ID + name. $page->setId((string) $xmlElement->uid); $page->setName((string) $xmlElement->name); $page->setOfficialPage(filter_var((string) $xmlElement->officialPage, FILTER_VALIDATE_BOOLEAN)); // Set categories $categories = array(); if (!empty($xmlElement->categoryIds->categoryId)) { foreach ($xmlElement->categoryIds->categoryId as $category) { $categories[] = (string) $category; } } $page->setCategories($categories); // Set keywords $keywords = array(); if (!empty($xmlElement->keywords->keyword)) { foreach ($xmlElement->keywords->keyword as $keyword) { $keywords[] = (string) $keyword; } } $page->setKeywords($keywords); // Set description. if (!empty($xmlElement->description)) { $page->setDescription((string) $xmlElement->description); } // Set the image. if (!empty($xmlElement->image)) { $page->setImage((string) $xmlElement->image); } // Set the cover. if (!empty($xmlElement->cover)) { $page->setCover((string) $xmlElement->cover); } // Set the visibility. if (!empty($xmlElement->visible)) { $page->setVisibility((string) $xmlElement->visible); } // Set address. $address = new CultureFeed_Cdb_Data_Address_PhysicalAddress(); $addressElement = $xmlElement->address; $has_address = FALSE; if (!empty($addressElement->city)) { $address->setCity((string) $addressElement->city); $has_address = TRUE; } if (!empty($addressElement->street)) { $address->setStreet((string) $addressElement->street); $has_address = TRUE; } if (!empty($addressElement->zip)) { $address->setZip((string) $addressElement->zip); $has_address = TRUE; } if (!empty($addressElement->country)) { $address->setCountry((string) $addressElement->country); $has_address = TRUE; } if (!empty($addressElement->lat) && !empty($addressElement->lon)) { $coordinates = $addressElement->lat . '-' . $addressElement->lon; if ($coordinates != '0.0-0.0') { $address->setGeoInformation(new CultureFeed_Cdb_Data_Address_GeoInformation((string) $addressElement->lon, (string) $addressElement->lat)); $has_address = TRUE; } } if ($has_address) { $page->setAddress($address); } // Set contact info. if (!empty($xmlElement->contactInfo->email)) { $page->setEmail((string) $xmlElement->contactInfo->email); } if (!empty($xmlElement->contactInfo->telephone)) { $page->setTelephone((string) $xmlElement->contactInfo->telephone); } // Set links. $links = array(); if (!empty($xmlElement->links)) { foreach ($xmlElement->links->children() as $link) { $url = (string) $link; if (empty($url)) { continue; } // Make sure http is in front of the url. if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = 'http://' . $url; } $links[$link->getName()] = $url; } } $page->setLinks($links); // Set the permissions. $page->setPermissions(CultureFeed_Cdb_Data_PagePermissions::parseFromCdbXml($xmlElement->permissions)); // Set tagline. $page->setTagline((string) $xmlElement->tagline); return $page; }