/** * Convert the raw XML into an object * * @param \SimpleXMLElement $xml * @return Result */ public static function createFromXML(\SimpleXMLElement $xml) { $result = new Result(); if (isset($xml->nofrecords)) { $result->setNumResults((int) $xml->nofrecords); } if (isset($xml->event)) { foreach ($xml->event as $event) { $result->addEvent(\CultureFeed_Cdb_Item_Event::parseFromCdbXml($event)); } } return $result; }
/** * Get an event. * * @param string $id * * @return \CultureFeed_Cdb_Item_Event * * @throws \CultureFeed_Cdb_ParseException * @throws \CultureFeed_ParseException */ public function getEvent($id) { $request = $this->getClient()->get('event/' . $id, array('Content-Type' => 'application/xml; charset=UTF-8')); $response = $request->send(); $result = $response->getBody(true); try { $xml = new \SimpleXMLElement($result); } catch (Exception $e) { throw new \CultureFeed_ParseException($result); } if ($xml->event) { $eventXml = $xml->event; return \CultureFeed_Cdb_Item_Event::parseFromCdbXml($eventXml); } throw new \CultureFeed_ParseException($result); }
/** * Integration test for parsing the following additions to cdbxml version 3.3: * - event publisher and weight * - file subbrand and description */ public function testParseCdbXml3Dot3SchemaAdditions() { $xml = $this->loadSample('085377d6-a3c9-4c8f-88b9-3d6ab0201361.xml', '3.3'); $event = CultureFeed_Cdb_Item_Event::parseFromCdbXml($xml); $this->assertEquals('085377d6-a3c9-4c8f-88b9-3d6ab0201361', $event->getCdbId()); $this->assertEquals('48fe254ceba710aec4609017d2e34d91', $event->getPublisher()); $this->assertSame(12, $event->getWeight()); $nlDetail = $event->getDetails()->getDetailByLanguage('nl'); $media = $nlDetail->getMedia(); $media->next(); /** @var CultureFeed_Cdb_Data_File $secondFile */ $secondFile = $media->current(); $this->assertEquals('{"keyword": "Culturefeed.be selectie", "text": "Hello World", "image": "https://www.facebook.com/23424317091/photos/a.200759332091.131532.23424317091/10153148846107092/?type=1", "article": "http://www.humo.be/jeroom/3973/"}', $secondFile->getDescription()); $this->assertEquals('2b88e17a-27fc-4310-9556-4df7188a051f', $secondFile->getSubBrand()); }
/** * Get an event. * * @param string $id * ID of the event to load. * * @return CultureFeed_Cdb_Item_Event * @throws CultureFeed_ParseException */ public function getEvent($id) { $result = $this->oauth_client->authenticatedGetAsXml('event/' . $id); try { $xml = new CultureFeed_SimpleXMLElement($result); } catch (Exception $e) { throw new CultureFeed_ParseException($result); } if ($xml->event) { $eventXml = $xml->event; return CultureFeed_Cdb_Item_Event::parseFromCdbXml($eventXml); } throw new CultureFeed_ParseException($result); }
/** * Parse a given xml element to an CultureFeed_Cdb_Item_Base. * @param SimpleXMLElement $xmlElement * XML element from the item to parse. */ public static function parseItem(SimpleXMLElement $xmlElement) { // Return the correct cdb item. switch ($xmlElement->getName()) { case 'event': return CultureFeed_Cdb_Item_Event::parseFromCdbXml($xmlElement); case 'production': return CultureFeed_Cdb_Item_Production::parseFromCdbXml($xmlElement); case 'actor': return CultureFeed_Cdb_Item_Actor::parseFromCdbXml($xmlElement); default: return NULL; } }