I'm not sure if the issue is with whoever has domain over the PHP
documentation, or if there is a hold up making new classes/
documentation for the Zend Framework or if Google just thinks anybody
using PHP is incapable of grasping core programming concepts so that
PHP developers are last on their priority list, but!

I asked and got no response. I found someone else who had asked and
got a vague response, finally after looking at the .NET documentation
(bleck!) and the Python Documentation and finally the Zend Google API
class library (including some core stuff under the Google API) I was
able to successfully add a new non-primary calendar AND add events to
said calendar.

If the problem is simply that these features are as new as the other
docs make it sound and PHP documentation has yet to be written,
please, whoever reads these and can make important decisions, feel
free to add this or something similar to the official documentation.
My only request is that in exchange you add the documentation for
batch requests, because a person needs 8 hours of sleep at night.

Without further ado:

Adding a new non-primary calendar in PHP:

First, we set up the usual stuff:
     $gdataCal = new Zend_Gdata_Calendar($client);

Next, I like to make sure that the calenard isn't their already:

     $calFeed = $gdataCal->getCalendarListFeed();

     $noAppCal = true;

     foreach ($calFeed as $calendar) {
          $noAppCal = ($calendar -> title -> text == "App Calendar") ?
false : $noAppCal;
     }

If we don't find it, we then create the calendar:

     if($noAppCal) {
          $appCal = $gdataCal -> newListEntry();
          $appCal -> title = $gdataCal-> newTitle("App Calendar");
          $own_cal = "http://www.google.com/calendar/feeds/default/
owncalendars/full";
          $gdataCal->insertEvent($appCal, $own_cal);
     }

Notice that this identical to adding a calendar event except in three
ways:

1. Instead of newEventEntry() we use newListEntry(); (This was a lucky
guess based on magic methods and the .NET api)

2. Instead of using the default URI produced by $client, you replace
it with:

   http://www.google.com/calendar/feeds/default/owncalendars/full

(This is documented in all other server-side APIs I ran across)

3. In order to actually set the URI to something other than the
default used by $client, you must set the second parameter of the
insertEvent() method. (This was the part I got stuck on the longest, I
finally found this in the Zend_Http_Client library).

Oh, and the calendar has several options you can set, including color.
Check out the other api's for details.

And there you have it. On two daunting task two:

Creating an event in a non-primary calendar in PHP:

We'll use the client from the last example, and add the event to the
new calendar just created...

First we have to find out the unique URI for our new calendar. So
again, we loop:

     $calFeed = $gdataCal->getCalendarListFeed();

     foreach ($calFeed as $calendar) {
          $appCallUri = ($calendar->title->text == "App Calendar") ?
$calendar->content->src : "";
     }

It took me forever to find a nice path in the XMLDOM that returned
that URI, but that's the one.

Next we create our event as normal. But I'd like to show how I get the
Date/Time, as the official documentation is a bit confusing:

     $title = "Christmas Dinner";
     $date = "12/25/2009";
     $start = "7:30 PM";
     $end = "9:00 PM";

     $eventStart = date('Y-m-d\TH:i:sP', strtotime($start." ".$date);
     $eventEnd = date('Y-m-d\TH:i:sP', strtotime($end." ".$date);

     $newEvent = $gdataCal->newEventEntry();
     $newEvent->title = $gdataCal->newTitle($title);
     $when = $gdataCal->newWhen();
     $when->startTime = $eventStart;
     $when->endTime = $eventEnd;
     $newEvent->when = array($when);

And then, finally, we add the event, using the calendar URI from that
last loop:

     $createdEvent = $gdataCal->insertEvent($newEvent, $appCalUrl);


For this part, it's much simplier. You just need to loop through the
calendars, search by title->text for the calendar name and grab
content->src as the URI to set, then it's just a matter of setting it
in the same way we did to create it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to