/** * @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; }