Zend_Gdata_Calendar.xml 37 KB

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