/** * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement * $xmlElement) * * @return CultureFeed_Cdb_Item_Production */ public static function parseFromCdbXml(SimpleXMLElement $xmlElement) { if (empty($xmlElement->categories)) { throw new CultureFeed_ParseException('Categories are required for production element'); } if (empty($xmlElement->productiondetails)) { throw new CultureFeed_ParseException('Production details are required for production element'); } $attributes = $xmlElement->attributes(); $production = new CultureFeed_Cdb_Item_Production(); // Set ID. if (isset($attributes['cdbid'])) { $production->setCdbId((string) $attributes['cdbid']); } if (isset($attributes['externalid'])) { $production->setExternalId((string) $attributes['externalid']); } if (isset($event_attributes['availablefrom'])) { $production->setAvailableFrom((string) $event_attributes['availablefrom']); } if (isset($event_attributes['availableto'])) { $production->setAvailableTo((string) $event_attributes['availableto']); } if (isset($event_attributes['createdby'])) { $production->setCreatedBy((string) $event_attributes['createdby']); } if (isset($event_attributes['creationdate'])) { $production->setCreationDate((string) $event_attributes['creationdate']); } if (!empty($xmlElement->agefrom)) { $production->setAgeFrom((int) $xmlElement->agefrom); } // Set organiser. if (!empty($xmlElement->organiser)) { $production->setOrganiser(CultureFeed_Cdb_Data_Organiser::parseFromCdbXml($xmlElement->organiser)); } // Set categories $production->setCategories(CultureFeed_Cdb_Data_CategoryList::parseFromCdbXml($xmlElement->categories)); // Set production details. $production->setDetails(CultureFeed_Cdb_Data_ProductionDetailList::parseFromCdbXml($xmlElement->productiondetails)); // Set max participants. if (!empty($xmlElement->maxparticipants)) { $production->setMaxParticipants((int) $xmlElement->maxparticipants); } // Set booking period. if (!empty($xmlElement->bookingperiod)) { $production->setBookingPeriod(CultureFeed_Cdb_Data_Calendar_BookingPeriod::parseFromCdbXml($xmlElement->bookingperiod)); } // Set the related events for this production. if (!empty($xmlElement->relatedevents) && isset($xmlElement->relatedevents->id)) { foreach ($xmlElement->relatedevents->id as $relatedItem) { $attributes = $relatedItem->attributes(); $production->addRelation(new CultureFeed_Cdb_Item_Reference((string) $attributes['cdbid'])); } } // Set the keywords. self::parseKeywords($xmlElement, $production); return $production; }
/** * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement * $xmlElement) * @return CultureFeed_Cdb_Item_Event */ public static function parseFromCdbXml(SimpleXMLElement $xmlElement) { if (empty($xmlElement->calendar)) { throw new CultureFeed_Cdb_ParseException('Calendar missing for event element'); } if (empty($xmlElement->categories)) { throw new CultureFeed_Cdb_ParseException('Categories missing for event element'); } if (empty($xmlElement->contactinfo)) { throw new CultureFeed_Cdb_ParseException('Contact info missing for event element'); } if (empty($xmlElement->eventdetails)) { throw new CultureFeed_Cdb_ParseException('Eventdetails missing for event element'); } if (empty($xmlElement->location)) { throw new CultureFeed_Cdb_ParseException('Location missing for event element'); } $event_attributes = $xmlElement->attributes(); $event = new CultureFeed_Cdb_Item_Event(); CultureFeed_Cdb_Item_Base::parseCommonAttributes($event, $xmlElement); if (isset($event_attributes['private'])) { $event->setPrivate(filter_var((string) $event_attributes['private'], FILTER_VALIDATE_BOOLEAN)); } if (isset($event_attributes['isparent'])) { $event->setIsParent(filter_var((string) $event_attributes['isparent'], FILTER_VALIDATE_BOOLEAN)); } if (isset($event_attributes['pctcomplete'])) { $event->setPctComplete(floatval($event_attributes['pctcomplete'])); } if (isset($event_attributes['published'])) { $event->setPublished(filter_var((string) $event_attributes['published'], FILTER_VALIDATE_BOOLEAN)); } if (isset($event_attributes['validator'])) { $event->setValidator((string) $event_attributes['validator']); } if (isset($event_attributes['weight'])) { $event->setWeight((int) $event_attributes['weight']); } if (isset($xmlElement->agefrom)) { $event->setAgeFrom((int) $xmlElement->agefrom); } // Set calendar information. $calendar_type = key($xmlElement->calendar); if ($calendar_type == 'permanentopeningtimes') { $event->setCalendar(CultureFeed_Cdb_Data_Calendar_Permanent::parseFromCdbXml($xmlElement->calendar)); } elseif ($calendar_type == 'timestamps') { $event->setCalendar(CultureFeed_Cdb_Data_Calendar_TimestampList::parseFromCdbXml($xmlElement->calendar->timestamps)); } elseif ($calendar_type == 'periods') { $event->setCalendar(CultureFeed_Cdb_Data_Calendar_PeriodList::parseFromCdbXml($xmlElement->calendar)); } // Set categories $event->setCategories(CultureFeed_Cdb_Data_CategoryList::parseFromCdbXml($xmlElement->categories)); // Set contact information. $event->setContactInfo(CultureFeed_Cdb_Data_ContactInfo::parseFromCdbXml($xmlElement->contactinfo)); // Set event details. $event->setDetails(CultureFeed_Cdb_Data_EventDetailList::parseFromCdbXml($xmlElement->eventdetails)); // Set location. $event->setLocation(CultureFeed_Cdb_Data_Location::parseFromCdbXml($xmlElement->location)); // Set organiser if (!empty($xmlElement->organiser)) { $event->setOrganiser(CultureFeed_Cdb_Data_Organiser::parseFromCdbXml($xmlElement->organiser)); } // Set max participants. if (!empty($xmlElement->maxparticipants)) { $event->setMaxParticipants((int) $xmlElement->maxparticipants); } // Set booking period. if (!empty($xmlElement->bookingperiod)) { $event->setBookingPeriod(CultureFeed_Cdb_Data_Calendar_BookingPeriod::parseFromCdbXml($xmlElement->bookingperiod)); } // Set relations. if (!empty($xmlElement->eventrelations) && !empty($xmlElement->eventrelations->relatedproduction)) { foreach ($xmlElement->eventrelations->relatedproduction as $relatedProduction) { $attributes = $relatedProduction->attributes(); $event->addRelation(new CultureFeed_Cdb_Item_Reference((string) $attributes['cdbid'], (string) $relatedProduction, (string) $attributes['externalid'])); } } self::parseKeywords($xmlElement, $event); if (!empty($xmlElement->languages)) { $event->setLanguages(CultureFeed_Cdb_Data_LanguageList::parseFromCdbXml($xmlElement->languages)); } return $event; }