I’ve been able to incorporate a feed from my public calendar into my site using the normal PHP way of going about it: with getElementbyTagName for normal xml values and getAttributeNode for the namespaces.
However, I’m trying to use the Zend GData library to integrate with other parts of my site and I can’t seem to find any documentation on parsing the namespaces in values like gd:where(valuestring) or gd:when(starttime & endtime)
Other than just creating a new DOMDocument within the instance of getCalendarEventFeed … is there a more efficient way of doing this?
I’ve looked at getCalendarEventFeed but still don’t see any docs on the parsing of the namespaces. Also, if I’m just grabbing a feed of the last 5 entries, I SHOULD be able to iterate through them and pull out the values I need - including the namespaces, right?
Thanks. I’m partially surprised that this functionality isn’t already coded into the GData library. But I guess the library is mainly intended to help access private calendars with authentication requirements.
But seeing more than one namespace used in the google calendar xml feed - <gd:…>, <gcal:…> made me think there should be a way to access those namespaces within the class.
I guess you need to just open a DOM document once you’ve brought in the feed. And YES, using XPath to register the namespaces probably makes it easier to work with the calendar going forward.
There should be no need to dive into DOM-land to get at the calendar/event data. The framework is designed to do all of the heavy lifting for you, details like when and where are available as either properties (via magic __get()) or methods (getWhen(), getWhere()) on the event object (a Zend_Gdata_Calendar_EventEntry). Bear in mind that both of those are arrays, so you might want to either access the first item if you’re only after one when/where, or loop over them. Here’s quickie example:
$event_feed = $service->getCalendarEventFeed($query);
foreach ($event_feed as $event) {
echo "Event: \
{$event->title}\
";
echo "Where: \
{$event->where[0]}\
";
echo "When: \
";
foreach ($event->when as $when) {
$format = 'd/m/Y H:i';
// $when->startTime is a string like "2011-05-10T20:00:00.000+01:00"
$start = date_create($when->startTime)->format($format);
$end = date_create($when->endTime)->format($format);
echo " $start until $end\
";
}
echo "Details: \
{$event->content}\
\
";
}
Which outputs something like
Event:
Evening Fun
Where:
Peter's Yard
When:
10/05/2011 20:00 until 10/05/2011 21:00
11/05/2011 20:00 until 11/05/2011 21:00
Details:
Have tea.
I hate the whole Zend Gdata library. I ended up writing my own parser for all data coming from Blogger API. Zend library is really really buggy and way overly complicated.
But I’m sure Zend is a great product, if you like it, don’t take it personally.
Thanks Salathe. That was really helpful. I was also looking for a way of grabbing gd:feedLink and/or gcal:uid - neither property was recognized.
But more importantly, when you mention the getWhen() and getWhere() methods … I ran a search for those methods in my GData directory and did not find anything. Mostly, what I’m looking for is some good documentation on the GData library, so I can answer more of these questions on my own … do you have any suggestions on where to look?
[QUOTE=Salathe;4874926]There should be no need to dive into DOM-land to get at the calendar/event data. The framework is designed to do all of the heavy lifting for you, details like when and where are available as either properties (via magic __get()) or methods (getWhen(), getWhere()) on the event object (a Zend_Gdata_Calendar_EventEntry). Bear in mind that both of those are arrays, so you might want to either access the first item if you’re only after one when/where, or loop over them. Here’s quickie example:
I’ve heard good and bad things about Zend myself. And it being “bloated” is one of the main criticisms. At the same time, it seem sto be in big demand - at least in my local job market.
Like I said, I’d already written the code I needed using the DOM but was looking for an “easier” way to do it with Zend