Zend_Gdata_Calendar.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.calendar">
  4. <title>Using Google Calendar</title>
  5. <para>
  6. You can use the
  7. <classname>Zend_Gdata_Calendar</classname>
  8. class to view, create, update, and delete events in the online Google Calendar service.
  9. </para>
  10. <para>
  11. See <ulink
  12. url="http://code.google.com/apis/calendar/overview.html">
  13. http://code.google.com/apis/calendar/overview.html</ulink>
  14. for more information about the Google Calendar <acronym>API</acronym>.
  15. </para>
  16. <sect2 id="zend.gdata.calendar.connecting">
  17. <title>Connecting To The Calendar Service</title>
  18. <para>
  19. The Google Calendar <acronym>API</acronym>, like all GData <acronym>API</acronym>s, is based off of the Atom Publishing
  20. Protocol (APP), an <acronym>XML</acronym> based format for managing web-based resources. Traffic between
  21. a client and the Google Calendar servers occurs over <acronym>HTTP</acronym> and allows for both
  22. authenticated and unauthenticated connections.
  23. </para>
  24. <para>
  25. Before any transactions can occur, this connection needs to be made. Creating a
  26. connection to the calendar servers involves two steps: creating an <acronym>HTTP</acronym> client and
  27. binding a <classname>Zend_Gdata_Calendar</classname> service instance to that client.
  28. </para>
  29. <sect3 id="zend.gdata.calendar.connecting.authentication">
  30. <title>Authentication</title>
  31. <para>
  32. The Google Calendar <acronym>API</acronym> allows access to both public and private calendar feeds.
  33. Public feeds do not require authentication, but are read-only and offer reduced
  34. functionality. Private feeds offers the most complete functionality but requires
  35. an authenticated connection to the calendar servers. There are three authentication
  36. schemes that are supported by Google Calendar:
  37. </para>
  38. <itemizedlist>
  39. <listitem>
  40. <para>
  41. <firstterm>ClientAuth</firstterm>
  42. provides direct username/password authentication to the
  43. calendar servers. Since this scheme requires that users
  44. provide your application with their password, this
  45. authentication is only recommended when other
  46. authentication schemes are insufficient.
  47. </para>
  48. </listitem>
  49. <listitem>
  50. <para>
  51. <firstterm>AuthSub</firstterm>
  52. allows authentication to the calendar servers via a
  53. Google proxy server. This provides the same level of
  54. convenience as ClientAuth but without the security
  55. risk, making this an ideal choice for web-based
  56. applications.
  57. </para>
  58. </listitem>
  59. <listitem>
  60. <para>
  61. <firstterm>MagicCookie</firstterm>
  62. allows authentication based on a semi-random <acronym>URL</acronym>
  63. available from within the Google Calendar interface.
  64. This is the simplest authentication scheme to
  65. implement, but requires that users manually retrieve
  66. their secure <acronym>URL</acronym> before they can authenticate, doesn't
  67. provide access to calendar lists, and is limited to
  68. read-only access.
  69. </para>
  70. </listitem>
  71. </itemizedlist>
  72. <para>
  73. The
  74. <classname>Zend_Gdata</classname>
  75. library provides support for all three authentication schemes.
  76. The rest of this chapter will assume that you are familiar the
  77. authentication schemes available and how to create an
  78. appropriate authenticated connection. For more information,
  79. please see section the <link
  80. linkend="zend.gdata.introduction.authentication">Authentication section</link>
  81. of this manual or the <ulink
  82. url="http://code.google.com/apis/gdata/auth.html">Authentication Overview in the
  83. Google Data <acronym>API</acronym> Developer's Guide</ulink>.
  84. </para>
  85. </sect3>
  86. <sect3 id="zend.gdata.calendar.connecting.service">
  87. <title>Creating A Service Instance</title>
  88. <para>
  89. In order to interact with Google Calendar, this library provides the
  90. <classname>Zend_Gdata_Calendar</classname> service class. This class provides a common
  91. interface to the Google Data and Atom Publishing Protocol models and assists in
  92. marshaling requests to and from the calendar servers.
  93. </para>
  94. <para>
  95. Once deciding on an authentication scheme, the next step is to create an instance
  96. of <classname>Zend_Gdata_Calendar</classname>. The class constructor takes an instance of
  97. <classname>Zend_Http_Client</classname> as a single argument. This provides an interface for
  98. AuthSub and ClientAuth authentication, as both of these require creation of a
  99. special authenticated <acronym>HTTP</acronym> client. If no arguments are provided, an unauthenticated
  100. instance of <classname>Zend_Http_Client</classname> will be automatically created.
  101. </para>
  102. <para>
  103. The example below shows how to create a Calendar service class using ClientAuth
  104. authentication:
  105. </para>
  106. <programlisting language="php"><![CDATA[
  107. // Parameters for ClientAuth authentication
  108. $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
  109. $user = "sample.user@gmail.com";
  110. $pass = "pa$$w0rd";
  111. // Create an authenticated HTTP client
  112. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  113. // Create an instance of the Calendar service
  114. $service = new Zend_Gdata_Calendar($client);
  115. ]]></programlisting>
  116. <para>
  117. A Calendar service using AuthSub can be created in a similar, though slightly more
  118. lengthy fashion:
  119. </para>
  120. <programlisting language="php"><![CDATA[
  121. /*
  122. * Retrieve the current URL so that the AuthSub server knows where to
  123. * redirect the user after authentication is complete.
  124. */
  125. function getCurrentUrl()
  126. {
  127. global $_SERVER;
  128. // Filter php_self to avoid a security vulnerability.
  129. $php_request_uri =
  130. htmlentities(substr($_SERVER['REQUEST_URI'],
  131. 0,
  132. strcspn($_SERVER['REQUEST_URI'], "\n\r")),
  133. ENT_QUOTES);
  134. if (isset($_SERVER['HTTPS']) &&
  135. strtolower($_SERVER['HTTPS']) == 'on') {
  136. $protocol = 'https://';
  137. } else {
  138. $protocol = 'http://';
  139. }
  140. $host = $_SERVER['HTTP_HOST'];
  141. if ($_SERVER['HTTP_PORT'] != '' &&
  142. (($protocol == 'http://' && $_SERVER['HTTP_PORT'] != '80') ||
  143. ($protocol == 'https://' && $_SERVER['HTTP_PORT'] != '443'))) {
  144. $port = ':' . $_SERVER['HTTP_PORT'];
  145. } else {
  146. $port = '';
  147. }
  148. return $protocol . $host . $port . $php_request_uri;
  149. }
  150. /**
  151. * Obtain an AuthSub authenticated HTTP client, redirecting the user
  152. * to the AuthSub server to login if necessary.
  153. */
  154. function getAuthSubHttpClient()
  155. {
  156. global $_SESSION, $_GET;
  157. // if there is no AuthSub session or one-time token waiting for us,
  158. // redirect the user to the AuthSub server to get one.
  159. if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
  160. // Parameters to give to AuthSub server
  161. $next = getCurrentUrl();
  162. $scope = "http://www.google.com/calendar/feeds/";
  163. $secure = false;
  164. $session = true;
  165. // Redirect the user to the AuthSub server to sign in
  166. $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next,
  167. $scope,
  168. $secure,
  169. $session);
  170. header("HTTP/1.0 307 Temporary redirect");
  171. header("Location: " . $authSubUrl);
  172. exit();
  173. }
  174. // Convert an AuthSub one-time token into a session token if needed
  175. if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  176. $_SESSION['sessionToken'] =
  177. Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  178. }
  179. // At this point we are authenticated via AuthSub and can obtain an
  180. // authenticated HTTP client instance
  181. // Create an authenticated HTTP client
  182. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
  183. return $client;
  184. }
  185. // -> Script execution begins here <-
  186. // Make sure that the user has a valid session, so we can record the
  187. // AuthSub session token once it is available.
  188. session_start();
  189. // Create an instance of the Calendar service, redirecting the user
  190. // to the AuthSub server if necessary.
  191. $service = new Zend_Gdata_Calendar(getAuthSubHttpClient());
  192. ]]></programlisting>
  193. <para>
  194. Finally, an unauthenticated server can be created for use with either public feeds
  195. or MagicCookie authentication:
  196. </para>
  197. <programlisting language="php"><![CDATA[
  198. // Create an instance of the Calendar service using an unauthenticated
  199. // HTTP client
  200. $service = new Zend_Gdata_Calendar();
  201. ]]></programlisting>
  202. <para>
  203. Note that MagicCookie authentication is not supplied with the <acronym>HTTP</acronym> connection, but
  204. is instead specified along with the desired visibility when submitting queries. See
  205. the section on retrieving events below for an example.
  206. </para>
  207. </sect3>
  208. </sect2>
  209. <sect2 id="zend.gdata.calendar_retrieval">
  210. <title>Retrieving A Calendar List</title>
  211. <para>
  212. The calendar service supports retrieving a list of calendars for the authenticated
  213. user. This is the same list of calendars which are displayed in the Google Calendar
  214. UI, except those marked as "<code>hidden</code>" are also available.
  215. </para>
  216. <para>
  217. The calendar list is always private and must be accessed over an authenticated
  218. connection. It is not possible to retrieve another user's calendar list and it cannot
  219. be accessed using MagicCookie authentication. Attempting to access a calendar list
  220. without holding appropriate credentials will fail and result in a 401 (Authentication
  221. Required) status code.
  222. </para>
  223. <programlisting language="php"><![CDATA[
  224. $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
  225. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  226. $service = new Zend_Gdata_Calendar($client);
  227. try {
  228. $listFeed= $service->getCalendarListFeed();
  229. } catch (Zend_Gdata_App_Exception $e) {
  230. echo "Error: " . $e->getMessage();
  231. }
  232. ]]></programlisting>
  233. <para>
  234. Calling <methodname>getCalendarListFeed()</methodname> creates a new instance of
  235. <classname>Zend_Gdata_Calendar_ListFeed</classname> containing each available calendar as an
  236. instance of <classname>Zend_Gdata_Calendar_ListEntry</classname>. After retrieving the feed, you
  237. can use the iterator and accessors contained within the feed to inspect the enclosed
  238. calendars.
  239. </para>
  240. <programlisting language="php"><![CDATA[
  241. echo "<h1>Calendar List Feed</h1>";
  242. echo "<ul>";
  243. foreach ($listFeed as $calendar) {
  244. echo "<li>" . $calendar->title .
  245. " (Event Feed: " . $calendar->id . ")</li>";
  246. }
  247. echo "</ul>";
  248. ]]></programlisting>
  249. </sect2>
  250. <sect2 id="zend.gdata.event_retrieval">
  251. <title>Retrieving Events</title>
  252. <para>
  253. Like the list of calendars, events are also retrieved using the
  254. <classname>Zend_Gdata_Calendar</classname> service class. The event list returned is of type
  255. <classname>Zend_Gdata_Calendar_EventFeed</classname> and contains each event as an instance of
  256. <classname>Zend_Gdata_Calendar_EventEntry</classname>. As before, the iterator and accessors
  257. contained within the event feed instance allow inspection of individual events.
  258. </para>
  259. <sect3 id="zend.gdata.event_retrieval.queries">
  260. <title>Queries</title>
  261. <para>
  262. When retrieving events using the Calendar <acronym>API</acronym>, specially constructed query <acronym>URL</acronym>s are
  263. used to describe what events should be returned. The
  264. <classname>Zend_Gdata_Calendar_EventQuery</classname> class simplifies this task by
  265. automatically constructing a query <acronym>URL</acronym> based on provided parameters. A full list of
  266. these parameters is available at the <ulink
  267. url="http://code.google.com/apis/gdata/reference.html#Queries">Queries section of
  268. the Google Data <acronym>API</acronym>s Protocol Reference</ulink>. However, there are three
  269. parameters that are worth special attention:
  270. </para>
  271. <itemizedlist>
  272. <listitem>
  273. <para>
  274. <firstterm>User</firstterm>
  275. is used to specify the user whose calendar is being
  276. searched for, and is specified as an email address. If
  277. no user is provided, "default" will be used instead to
  278. indicate the currently authenticated user (if
  279. authenticated).
  280. </para>
  281. </listitem>
  282. <listitem>
  283. <para>
  284. <firstterm>Visibility</firstterm>
  285. specifies whether a users public or private calendar
  286. should be searched. If using an unauthenticated session
  287. and no MagicCookie is available, only the public feed
  288. will be available.
  289. </para>
  290. </listitem>
  291. <listitem>
  292. <para>
  293. <firstterm>Projection</firstterm>
  294. specifies how much data should be returned by the
  295. server and in what format. In most cases you will want
  296. to use the "full" projection. Also available is the
  297. "basic" projection, which places most meta-data into
  298. each event's content field as human readable text, and
  299. the "composite" projection which includes complete text
  300. for any comments alongside each event. The "composite"
  301. view is often much larger than the "full" view.
  302. </para>
  303. </listitem>
  304. </itemizedlist>
  305. </sect3>
  306. <sect3 id="zend.gdata.event_retrieval.start_time">
  307. <title>Retrieving Events In Order Of Start Time</title>
  308. <para>
  309. The example below illustrates the use of the <classname>Zend_Gdata_Query</classname> class
  310. and specifies the private visibility feed, which requires that an authenticated
  311. connection is available to the calendar servers. If a MagicCookie is being used for
  312. authentication, the visibility should be instead set to
  313. "<code>private-magicCookieValue</code>", where magicCookieValue is the random
  314. string obtained when viewing the private <acronym>XML</acronym> address in the Google Calendar UI.
  315. Events are requested chronologically by start time and only events occurring in the
  316. future are returned.
  317. </para>
  318. <programlisting language="php"><![CDATA[
  319. $query = $service->newEventQuery();
  320. $query->setUser('default');
  321. // Set to $query->setVisibility('private-magicCookieValue') if using
  322. // MagicCookie auth
  323. $query->setVisibility('private');
  324. $query->setProjection('full');
  325. $query->setOrderby('starttime');
  326. $query->setFutureevents('true');
  327. // Retrieve the event list from the calendar server
  328. try {
  329. $eventFeed = $service->getCalendarEventFeed($query);
  330. } catch (Zend_Gdata_App_Exception $e) {
  331. echo "Error: " . $e->getMessage();
  332. }
  333. // Iterate through the list of events, outputting them as an HTML list
  334. echo "<ul>";
  335. foreach ($eventFeed as $event) {
  336. echo "<li>" . $event->title . " (Event ID: " . $event->id . ")</li>";
  337. }
  338. echo "</ul>";
  339. ]]></programlisting>
  340. <para>
  341. Additional properties such as ID, author, when, event status, visibility, web
  342. content, and content, among others are available within
  343. <classname>Zend_Gdata_Calendar_EventEntry</classname>. Refer to the
  344. <ulink url="http://framework.zend.com/apidoc/core/">Zend Framework <acronym>API</acronym>
  345. Documentation</ulink> and the
  346. <ulink url="http://code.google.com/apis/gdata/reference.html">Calendar Protocol
  347. Reference</ulink> for a complete list.
  348. </para>
  349. </sect3>
  350. <sect3 id="zend.gdata.event_retrieval.date_range">
  351. <title>Retrieving Events In A Specified Date Range</title>
  352. <para>
  353. To print out all events within a certain range, for example from December 1,
  354. 2006 through December 15, 2007, add the following two lines to the previous sample.
  355. Take care to remove "<code>$query->setFutureevents('true')</code>", since
  356. <code>futureevents</code> will override <code>startMin</code> and
  357. <code>startMax</code>.
  358. </para>
  359. <programlisting language="php"><![CDATA[
  360. $query->setStartMin('2006-12-01');
  361. $query->setStartMax('2006-12-16');
  362. ]]></programlisting>
  363. <para>
  364. Note that <code>startMin</code> is inclusive whereas <code>startMax</code> is
  365. exclusive. As a result, only events through 2006-12-15 23:59:59 will be returned.
  366. </para>
  367. </sect3>
  368. <sect3 id="zend.gdata.event_retrieval.fulltext">
  369. <title>Retrieving Events By Fulltext Query</title>
  370. <para>
  371. To print out all events which contain a specific word, for example "dogfood", use
  372. the <methodname>setQuery()</methodname> method when creating the query.
  373. </para>
  374. <programlisting language="php"><![CDATA[
  375. $query->setQuery("dogfood");
  376. ]]></programlisting>
  377. </sect3>
  378. <sect3 id="zend.gdata.event_retrieval.individual">
  379. <title>Retrieving Individual Events</title>
  380. <para>
  381. Individual events can be retrieved by specifying their event ID as part of the
  382. query. Instead of calling <methodname>getCalendarEventFeed()</methodname>,
  383. <methodname>getCalendarEventEntry()</methodname> should be called instead.
  384. </para>
  385. <programlisting language="php"><![CDATA[
  386. $query = $service->newEventQuery();
  387. $query->setUser('default');
  388. $query->setVisibility('private');
  389. $query->setProjection('full');
  390. $query->setEvent($eventId);
  391. try {
  392. $event = $service->getCalendarEventEntry($query);
  393. } catch (Zend_Gdata_App_Exception $e) {
  394. echo "Error: " . $e->getMessage();
  395. }
  396. ]]></programlisting>
  397. <para>
  398. In a similar fashion, if the event <acronym>URL</acronym> is known, it can be passed directly into
  399. <methodname>getCalendarEntry()</methodname> to retrieve a specific event. In this case, no
  400. query object is required since the event <acronym>URL</acronym> contains all the necessary information
  401. to retrieve the event.
  402. </para>
  403. <programlisting language="php"><![CDATA[
  404. $eventURL = "http://www.google.com/calendar/feeds/default/private"
  405. . "/full/g829on5sq4ag12se91d10uumko";
  406. try {
  407. $event = $service->getCalendarEventEntry($eventURL);
  408. } catch (Zend_Gdata_App_Exception $e) {
  409. echo "Error: " . $e->getMessage();
  410. }
  411. ]]></programlisting>
  412. </sect3>
  413. </sect2>
  414. <sect2 id="zend.gdata.calendar.creating_events">
  415. <title>Creating Events</title>
  416. <sect3 id="zend.gdata.calendar.creating_events.single">
  417. <title>Creating Single-Occurrence Events</title>
  418. <para>
  419. Events are added to a calendar by creating an instance of
  420. <classname>Zend_Gdata_EventEntry</classname> and populating it with the appropriate data.
  421. The calendar service instance (<classname>Zend_Gdata_Calendar</classname>) is then used to
  422. used to transparently covert the event into <acronym>XML</acronym> and POST it to the calendar server.
  423. Creating events requires either an AuthSub or ClientAuth authenticated connection
  424. to the calendar server.
  425. </para>
  426. <para>At a minimum, the following attributes should be set:</para>
  427. <itemizedlist>
  428. <listitem>
  429. <para>
  430. <firstterm>Title</firstterm>
  431. provides the headline that will appear above the event
  432. within the Google Calendar UI.
  433. </para>
  434. </listitem>
  435. <listitem>
  436. <para>
  437. <firstterm>When</firstterm>
  438. indicates the duration of the event and, optionally,
  439. any reminders that are associated with it. See the next
  440. section for more information on this attribute.
  441. </para>
  442. </listitem>
  443. </itemizedlist>
  444. <para>Other useful attributes that may optionally set include:</para>
  445. <itemizedlist>
  446. <listitem>
  447. <para>
  448. <firstterm>Author</firstterm>
  449. provides information about the user who created the
  450. event.
  451. </para>
  452. </listitem>
  453. <listitem>
  454. <para>
  455. <firstterm>Content</firstterm>
  456. provides additional information about the event which
  457. appears when the event details are requested from
  458. within Google Calendar.
  459. </para>
  460. </listitem>
  461. <listitem>
  462. <para>
  463. <firstterm>EventStatus</firstterm>
  464. indicates whether the event is confirmed, tentative, or
  465. canceled.
  466. </para>
  467. </listitem>
  468. <listitem>
  469. <para>
  470. <firstterm>Hidden</firstterm>
  471. removes the event from the Google Calendar UI.
  472. </para>
  473. </listitem>
  474. <listitem>
  475. <para>
  476. <firstterm>Transparency</firstterm>
  477. indicates whether the event should be consume time on
  478. the user's free/busy list.
  479. </para>
  480. </listitem>
  481. <listitem>
  482. <para>
  483. <firstterm>WebContent</firstterm>
  484. allows links to external content to be provided within
  485. an event.
  486. </para>
  487. </listitem>
  488. <listitem>
  489. <para>
  490. <firstterm>Where</firstterm>
  491. indicates the location of the event.
  492. </para>
  493. </listitem>
  494. <listitem>
  495. <para>
  496. <firstterm>Visibility</firstterm>
  497. allows the event to be hidden from the public event
  498. lists.
  499. </para>
  500. </listitem>
  501. </itemizedlist>
  502. <para>
  503. For a complete list of event attributes, refer to the
  504. <ulink url="http://framework.zend.com/apidoc/core/">Zend Framework <acronym>API</acronym>
  505. Documentation</ulink> and the
  506. <ulink url="http://code.google.com/apis/gdata/reference.html">Calendar Protocol
  507. Reference</ulink>. Attributes that can contain multiple values, such as where, are
  508. implemented as arrays and need to be created accordingly. Be aware that all of
  509. these attributes require objects as parameters. Trying instead to populate them
  510. using strings or primitives will result in errors during conversion to <acronym>XML</acronym>.
  511. </para>
  512. <para>
  513. Once the event has been populated, it can be uploaded to the calendar server by
  514. passing it as an argument to the calendar service's <methodname>insertEvent()</methodname>
  515. function.
  516. </para>
  517. <programlisting language="php"><![CDATA[
  518. // Create a new entry using the calendar service's magic factory method
  519. $event= $service->newEventEntry();
  520. // Populate the event with the desired information
  521. // Note that each attribute is crated as an instance of a matching class
  522. $event->title = $service->newTitle("My Event");
  523. $event->where = array($service->newWhere("Mountain View, California"));
  524. $event->content =
  525. $service->newContent(" This is my awesome event. RSVP required.");
  526. // Set the date using RFC 3339 format.
  527. $startDate = "2008-01-20";
  528. $startTime = "14:00";
  529. $endDate = "2008-01-20";
  530. $endTime = "16:00";
  531. $tzOffset = "-08";
  532. $when = $service->newWhen();
  533. $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
  534. $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
  535. $event->when = array($when);
  536. // Upload the event to the calendar server
  537. // A copy of the event as it is recorded on the server is returned
  538. $newEvent = $service->insertEvent($event);
  539. ]]></programlisting>
  540. </sect3>
  541. <sect3 id="zend.gdata.calendar.creating_events.schedulers_reminders">
  542. <title>Event Schedules and Reminders</title>
  543. <para>
  544. An event's starting time and duration are determined by the value of its
  545. <code>when</code> property, which contains the properties
  546. <code>startTime</code>, <code>endTime</code>, and <code>valueString</code>.
  547. <code>StartTime</code> and <code>EndTime</code> control the duration of the
  548. event, while the <code>valueString</code> property is currently unused.
  549. </para>
  550. <para>
  551. All-day events can be scheduled by specifying only the date omitting the time when
  552. setting <code>startTime</code> and <code>endTime</code>. Likewise, zero-duration
  553. events can be specified by omitting the <code>endTime</code>. In all cases,
  554. date/time values should be provided in
  555. <ulink url="http://www.ietf.org/rfc/rfc3339.txt">RFC3339</ulink> format.
  556. </para>
  557. <programlisting language="php"><![CDATA[
  558. // Schedule the event to occur on December 05, 2007 at 2 PM PST (UTC-8)
  559. // with a duration of one hour.
  560. $when = $service->newWhen();
  561. $when->startTime = "2007-12-05T14:00:00-08:00";
  562. $when->endTime="2007-12-05T15:00:00:00-08:00";
  563. // Apply the when property to an event
  564. $event->when = array($when);
  565. ]]></programlisting>
  566. <para>
  567. The <code>when</code> attribute also controls when reminders are sent to a user.
  568. Reminders are stored in an array and each event may have up to find reminders
  569. associated with it.
  570. </para>
  571. <para>
  572. For a <code>reminder</code> to be valid, it needs to have two attributes set:
  573. <code>method</code> and a time. <code>Method</code> can accept one of the following
  574. strings: "alert", "email", or "sms". The time should be entered as an integer and
  575. can be set with either the property <code>minutes</code>, <code>hours</code>,
  576. <code>days</code>, or <code>absoluteTime</code>. However, a valid request may only
  577. have one of these attributes set. If a mixed time is desired, convert to the most
  578. precise unit available. For example, 1 hour and 30 minutes should be entered as 90
  579. minutes.
  580. </para>
  581. <programlisting language="php"><![CDATA[
  582. // Create a new reminder object. It should be set to send an email
  583. // to the user 10 minutes beforehand.
  584. $reminder = $service->newReminder();
  585. $reminder->method = "email";
  586. $reminder->minutes = "10";
  587. // Apply the reminder to an existing event's when property
  588. $when = $event->when[0];
  589. $when->reminders = array($reminder);
  590. ]]></programlisting>
  591. </sect3>
  592. <sect3 id="zend.gdata.calendar.creating_events.recurring">
  593. <title>Creating Recurring Events</title>
  594. <para>
  595. Recurring events are created the same way as single-occurrence events, except a
  596. recurrence attribute should be provided instead of a where attribute. The
  597. recurrence attribute should hold a string describing the event's recurrence pattern
  598. using properties defined in the iCalendar standard (<ulink
  599. url="http://www.ietf.org/rfc/rfc2445.txt">RFC 2445</ulink>).
  600. </para>
  601. <para>
  602. Exceptions to the recurrence pattern will usually be specified by a distinct
  603. <code>recurrenceException</code> attribute. However, the iCalendar standard
  604. provides a secondary format for defining recurrences, and the possibility that
  605. either may be used must be accounted for.
  606. </para>
  607. <para>
  608. Due to the complexity of parsing recurrence patterns, further information on this
  609. them is outside the scope of this document. However, more information can be found
  610. in the <ulink url="http://code.google.com/apis/gdata/elements.html#gdRecurrence">
  611. Common Elements section of the Google Data <acronym>API</acronym>s Developer Guide</ulink>, as well as
  612. in <acronym>RFC</acronym> 2445.
  613. </para>
  614. <programlisting language="php"><![CDATA[
  615. // Create a new entry using the calendar service's magic factory method
  616. $event= $service->newEventEntry();
  617. // Populate the event with the desired information
  618. // Note that each attribute is crated as an instance of a matching class
  619. $event->title = $service->newTitle("My Recurring Event");
  620. $event->where = array($service->newWhere("Palo Alto, California"));
  621. $event->content =
  622. $service->newContent(' This is my other awesome event, ' .
  623. ' occurring all-day every Tuesday from .
  624. '2007-05-01 until 207-09-04. No RSVP required.');
  625. // Set the duration and frequency by specifying a recurrence pattern.
  626. $recurrence = "DTSTART;VALUE=DATE:20070501\r\n" .
  627. "DTEND;VALUE=DATE:20070502\r\n" .
  628. "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904\r\n";
  629. $event->recurrence = $service->newRecurrence($recurrence);
  630. // Upload the event to the calendar server
  631. // A copy of the event as it is recorded on the server is returned
  632. $newEvent = $service->insertEvent($event);
  633. ]]></programlisting>
  634. </sect3>
  635. <sect3 id="zend.gdata.calendar.creating_events.quickadd">
  636. <title>Using QuickAdd</title>
  637. <para>
  638. QuickAdd is a feature which allows events to be created using free-form text entry.
  639. For example, the string "Dinner at Joe's Diner on Thursday" would create an event
  640. with the title "Dinner", location "Joe's Diner", and date "Thursday". To take
  641. advantage of QuickAdd, create a new <code>QuickAdd</code> property set to
  642. <constant>TRUE</constant> and store the freeform text as a <code>content</code>
  643. property.
  644. </para>
  645. <programlisting language="php"><![CDATA[
  646. // Create a new entry using the calendar service's magic factory method
  647. $event= $service->newEventEntry();
  648. // Populate the event with the desired information
  649. $event->content= $service->newContent("Dinner at Joe's Diner on Thursday");
  650. $event->quickAdd = $service->newQuickAdd("true");
  651. // Upload the event to the calendar server
  652. // A copy of the event as it is recorded on the server is returned
  653. $newEvent = $service->insertEvent($event);
  654. ]]></programlisting>
  655. </sect3>
  656. </sect2>
  657. <sect2 id="zend.gdata.calendar.modifying_events">
  658. <title>Modifying Events</title>
  659. <para>
  660. Once an instance of an event has been obtained, the event's attributes can be locally
  661. modified in the same way as when creating an event. Once all modifications are
  662. complete, calling the event's <methodname>save()</methodname> method will upload the changes to the
  663. calendar server and return a copy of the event as it was created on the server.
  664. </para>
  665. <para>
  666. In the event another user has modified the event since the local copy was retrieved,
  667. <methodname>save()</methodname> will fail and the server will return a 409 (Conflict) status code.
  668. To resolve this a fresh copy of the event must be retrieved from the server before
  669. attempting to resubmit any modifications.
  670. </para>
  671. <programlisting language="php"><![CDATA[
  672. // Get the first event in the user's event list
  673. $event = $eventFeed[0];
  674. // Change the title to a new value
  675. $event->title = $service->newTitle("Woof!");
  676. // Upload the changes to the server
  677. try {
  678. $event->save();
  679. } catch (Zend_Gdata_App_Exception $e) {
  680. echo "Error: " . $e->getMessage();
  681. }
  682. ]]></programlisting>
  683. </sect2>
  684. <sect2 id="zend.gdata.calendar.deleting_events">
  685. <title>Deleting Events</title>
  686. <para>
  687. Calendar events can be deleted either by calling the calendar service's
  688. <methodname>delete()</methodname> method and providing the edit <acronym>URL</acronym> of an event or by calling an
  689. existing event's own <methodname>delete()</methodname> method.
  690. </para>
  691. <para>
  692. In either case, the deleted event will still show up on a user's private event feed if
  693. an <code>updateMin</code> query parameter is provided. Deleted events can be
  694. distinguished from regular events because they will have their <code>eventStatus</code>
  695. property set to "http://schemas.google.com/g/2005#event.canceled".
  696. </para>
  697. <programlisting language="php"><![CDATA[
  698. // Option 1: Events can be deleted directly
  699. $event->delete();
  700. ]]></programlisting>
  701. <programlisting language="php"><![CDATA[
  702. // Option 2: Events can be deleted supplying the edit URL of the event
  703. // to the calendar service, if known
  704. $service->delete($event->getEditLink()->href);
  705. ]]></programlisting>
  706. </sect2>
  707. <sect2 id="zend.gdata.calendar.comments">
  708. <title>Accessing Event Comments</title>
  709. <para>
  710. When using the full event view, comments are not directly stored within an entry.
  711. Instead, each event contains a <acronym>URL</acronym> to its associated comment feed which must be
  712. manually requested.
  713. </para>
  714. <para>
  715. Working with comments is fundamentally similar to working with events, with the only
  716. significant difference being that a different feed and event class should be used and
  717. that the additional meta-data for events such as where and when does not exist for
  718. comments. Specifically, the comment's author is stored in the <code>author</code>
  719. property, and the comment text is stored in the <code>content</code> property.
  720. </para>
  721. <programlisting language="php"><![CDATA[
  722. // Extract the comment URL from the first event in a user's feed list
  723. $event = $eventFeed[0];
  724. $commentUrl = $event->comments->feedLink->url;
  725. // Retrieve the comment list for the event
  726. try {
  727. $commentFeed = $service->getFeed($commentUrl);
  728. } catch (Zend_Gdata_App_Exception $e) {
  729. echo "Error: " . $e->getMessage();
  730. }
  731. // Output each comment as an HTML list
  732. echo "<ul>";
  733. foreach ($commentFeed as $comment) {
  734. echo "<li><em>Comment By: " . $comment->author->name "</em><br/>" .
  735. $comment->content . "</li>";
  736. }
  737. echo "</ul>";
  738. ]]></programlisting>
  739. </sect2>
  740. </sect1>