Exemple #1
0
 /**
  * Convert the raw XML into an object
  *
  * @param \SimpleXMLElement $xml
  * @return Event
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $event = new Event();
     // loop attributes
     foreach ($xml->attributes() as $attributeName => $value) {
         $method = 'set' . ucfirst($attributeName);
         switch ($attributeName) {
             case 'availablefrom':
                 $method = 'setAvailableFrom';
                 $value = new \DateTime($value);
                 break;
             case 'availableto':
                 $method = 'setAvailableTo';
                 $value = new \DateTime($value);
                 break;
             case 'creationdate':
                 $method = 'setCreationDate';
                 $value = new \DateTime($value);
                 break;
             case 'lastupdated':
                 $method = 'setLastUpdated';
                 $value = new \DateTime($value);
                 break;
             case 'pctcomplete':
                 $method = 'setPercentageComplete';
                 $value = (int) $value;
                 break;
             case 'isparent':
                 $method = 'setIsParent';
                 $value = (string) $value == 'true';
                 break;
             case 'published':
             case 'private':
                 $value = (string) $value == 'true';
                 break;
             default:
                 $value = (string) $value;
         }
         if (!method_exists($event, $method)) {
             if (UitDatabank::DEBUG) {
                 throw new Exception('Unknown attribute: ' . $attributeName);
             }
         } else {
             call_user_func(array($event, $method), $value);
         }
     }
     // loop elements
     foreach ($xml as $element) {
         $value = null;
         $elementName = $element->getName();
         $method = 'set' . ucfirst($element->getName());
         switch ($elementName) {
             case 'calendar':
                 $value = Calendar::createFromXML($element);
                 break;
             case 'categories':
                 if (isset($element->category)) {
                     foreach ($element->category as $category) {
                         $event->addCategory(Category::createFromXML($category));
                     }
                 }
                 break;
             case 'contactinfo':
                 $value = ContactInfo::createFromXML($element);
                 break;
             case 'eventdetails':
                 if (isset($element->eventdetail)) {
                     foreach ($element->eventdetail as $eventDetail) {
                         $event->addEventDetail(EventDetail::createFromXML($eventDetail));
                     }
                 }
                 break;
             case 'languages':
                 if (isset($element->language)) {
                     foreach ($element->language as $language) {
                         $event->addLanguage(Language::createFromXML($language));
                     }
                 }
                 break;
             case 'location':
                 $value = Location::createFromXML($element);
                 break;
             case 'organiser':
                 $value = Organiser::createFromXML($element);
                 break;
             case 'agefrom':
                 $value = (int) $value;
                 break;
             case 'bookingperiod':
                 $value = Period::createFromXML($element);
                 break;
             default:
                 $value = (string) $value;
                 break;
         }
         if (!method_exists($event, $method)) {
             if (UitDatabank::DEBUG) {
                 throw new Exception('Unknown element: ' . $elementName);
             }
         } else {
             if ($value !== null) {
                 call_user_func(array($event, $method), $value);
             }
         }
     }
     return $event;
 }
 /**
  * Convert the raw XML into an object
  *
  * @param \SimpleXMLElement $xml
  * @return Calendar
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $calendar = new Calendar();
     // loop attributes
     foreach ($xml->attributes() as $attributeName => $value) {
         $method = 'set' . ucfirst($attributeName);
         switch ($attributeName) {
             default:
                 $value = (string) $value;
         }
         if (!method_exists($calendar, $method)) {
             if (UitDatabank::DEBUG) {
                 throw new Exception('Unknown attribute: ' . $attributeName);
             }
         } else {
             call_user_func(array($calendar, $method), $value);
         }
     }
     // loop elements
     foreach ($xml as $element) {
         $elementName = $element->getName();
         $method = 'set' . ucfirst($element->getName());
         $value = null;
         switch ($elementName) {
             case 'timestamps':
                 if (isset($element->timestamp)) {
                     $calendar->addTimestamp(Timestamp::createFromXML($element->timestamp));
                 }
                 break;
             case 'permanentopeningtimes':
                 if (isset($element->permanent)) {
                     $value = Permanent::createFromXML($element->permanent);
                 }
                 break;
             case 'periods':
                 if (isset($element->period)) {
                     foreach ($element->period as $period) {
                         $calendar->addPeriod(Period::createFromXML($period));
                     }
                 }
                 break;
             default:
                 $value = (string) $element;
                 break;
         }
         if (!method_exists($calendar, $method)) {
             if (UitDatabank::DEBUG) {
                 throw new Exception('Unknown element: ' . $elementName);
             }
         } else {
             if ($value !== null) {
                 call_user_func(array($calendar, $method), $value);
             }
         }
     }
     return $calendar;
 }