Zend_Gdata_Calendar.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 "<emphasis>hidden</emphasis>" 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. "<emphasis>private-magicCookieValue</emphasis>", where magicCookieValue is the
  318. random string obtained when viewing the private <acronym>XML</acronym> address in
  319. the 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 "<command>$query->setFutureevents('true')</command>", since
  360. <property>futureevents</property> will override <property>startMin</property> and
  361. <property>startMax</property>.
  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 <property>startMin</property> is inclusive whereas
  369. <property>startMax</property> is exclusive. As a result, only events through
  370. 2006-12-15 23:59:59 will be returned.
  371. </para>
  372. </sect3>
  373. <sect3 id="zend.gdata.event_retrieval.fulltext">
  374. <title>Retrieving Events By Fulltext Query</title>
  375. <para>
  376. To print out all events which contain a specific word, for example "dogfood", use
  377. the <methodname>setQuery()</methodname> method when creating the query.
  378. </para>
  379. <programlisting language="php"><![CDATA[
  380. $query->setQuery("dogfood");
  381. ]]></programlisting>
  382. </sect3>
  383. <sect3 id="zend.gdata.event_retrieval.individual">
  384. <title>Retrieving Individual Events</title>
  385. <para>
  386. Individual events can be retrieved by specifying their event ID as part of the
  387. query. Instead of calling <methodname>getCalendarEventFeed()</methodname>,
  388. <methodname>getCalendarEventEntry()</methodname> should be called instead.
  389. </para>
  390. <programlisting language="php"><![CDATA[
  391. $query = $service->newEventQuery();
  392. $query->setUser('default');
  393. $query->setVisibility('private');
  394. $query->setProjection('full');
  395. $query->setEvent($eventId);
  396. try {
  397. $event = $service->getCalendarEventEntry($query);
  398. } catch (Zend_Gdata_App_Exception $e) {
  399. echo "Error: " . $e->getMessage();
  400. }
  401. ]]></programlisting>
  402. <para>
  403. In a similar fashion, if the event <acronym>URL</acronym> is known, it can be passed
  404. directly into <methodname>getCalendarEntry()</methodname> to retrieve a specific
  405. event. In this case, no query object is required since the event
  406. <acronym>URL</acronym> contains all the necessary information to retrieve the event.
  407. </para>
  408. <programlisting language="php"><![CDATA[
  409. $eventURL = "http://www.google.com/calendar/feeds/default/private"
  410. . "/full/g829on5sq4ag12se91d10uumko";
  411. try {
  412. $event = $service->getCalendarEventEntry($eventURL);
  413. } catch (Zend_Gdata_App_Exception $e) {
  414. echo "Error: " . $e->getMessage();
  415. }
  416. ]]></programlisting>
  417. </sect3>
  418. </sect2>
  419. <sect2 id="zend.gdata.calendar.creating_events">
  420. <title>Creating Events</title>
  421. <sect3 id="zend.gdata.calendar.creating_events.single">
  422. <title>Creating Single-Occurrence Events</title>
  423. <para>
  424. Events are added to a calendar by creating an instance of
  425. <classname>Zend_Gdata_EventEntry</classname> and populating it with the appropriate
  426. data. The calendar service instance (<classname>Zend_Gdata_Calendar</classname>) is
  427. then used to used to transparently covert the event into <acronym>XML</acronym> and
  428. POST it to the calendar server. Creating events requires either an AuthSub or
  429. ClientAuth authenticated connection to the calendar server.
  430. </para>
  431. <para>At a minimum, the following attributes should be set:</para>
  432. <itemizedlist>
  433. <listitem>
  434. <para>
  435. <firstterm>Title</firstterm>
  436. provides the headline that will appear above the event
  437. within the Google Calendar UI.
  438. </para>
  439. </listitem>
  440. <listitem>
  441. <para>
  442. <firstterm>When</firstterm>
  443. indicates the duration of the event and, optionally,
  444. any reminders that are associated with it. See the next
  445. section for more information on this attribute.
  446. </para>
  447. </listitem>
  448. </itemizedlist>
  449. <para>Other useful attributes that may optionally set include:</para>
  450. <itemizedlist>
  451. <listitem>
  452. <para>
  453. <firstterm>Author</firstterm>
  454. provides information about the user who created the
  455. event.
  456. </para>
  457. </listitem>
  458. <listitem>
  459. <para>
  460. <firstterm>Content</firstterm>
  461. provides additional information about the event which
  462. appears when the event details are requested from
  463. within Google Calendar.
  464. </para>
  465. </listitem>
  466. <listitem>
  467. <para>
  468. <firstterm>EventStatus</firstterm>
  469. indicates whether the event is confirmed, tentative, or
  470. canceled.
  471. </para>
  472. </listitem>
  473. <listitem>
  474. <para>
  475. <firstterm>Transparency</firstterm>
  476. indicates whether the event should be consume time on
  477. the user's free/busy list.
  478. </para>
  479. </listitem>
  480. <listitem>
  481. <para>
  482. <firstterm>WebContent</firstterm>
  483. allows links to external content to be provided within
  484. an event.
  485. </para>
  486. </listitem>
  487. <listitem>
  488. <para>
  489. <firstterm>Where</firstterm>
  490. indicates the location of the event.
  491. </para>
  492. </listitem>
  493. <listitem>
  494. <para>
  495. <firstterm>Visibility</firstterm>
  496. allows the event to be hidden from the public event
  497. lists.
  498. </para>
  499. </listitem>
  500. </itemizedlist>
  501. <para>
  502. For a complete list of event attributes, refer to the <ulink
  503. url="http://framework.zend.com/apidoc/core/">Zend Framework
  504. <acronym>API</acronym> Documentation</ulink> and the <ulink
  505. url="http://code.google.com/apis/gdata/reference.html">Calendar Protocol
  506. Reference</ulink>. Attributes that can contain multiple values, such as where,
  507. are implemented as arrays and need to be created accordingly. Be aware that all of
  508. these attributes require objects as parameters. Trying instead to populate them
  509. using strings or primitives will result in errors during conversion to
  510. <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
  515. <methodname>insertEvent()</methodname> 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. <property>when</property> property, which contains the properties
  546. <property>startTime</property>, <property>endTime</property>, and
  547. <property>valueString</property>. <emphasis>StartTime</emphasis> and
  548. <emphasis>EndTime</emphasis> control the duration of the
  549. event, while the <property>valueString</property> property is currently unused.
  550. </para>
  551. <para>
  552. All-day events can be scheduled by specifying only the date omitting the time when
  553. setting <property>startTime</property> and <property>endTime</property>. Likewise,
  554. zero-duration events can be specified by omitting the <property>endTime</property>.
  555. In all cases, date and time values should be provided in
  556. <ulink url="http://www.ietf.org/rfc/rfc3339.txt">RFC3339</ulink> format.
  557. </para>
  558. <programlisting language="php"><![CDATA[
  559. // Schedule the event to occur on December 05, 2007 at 2 PM PST (UTC-8)
  560. // with a duration of one hour.
  561. $when = $service->newWhen();
  562. $when->startTime = "2007-12-05T14:00:00-08:00";
  563. $when->endTime="2007-12-05T15:00:00:00-08:00";
  564. // Apply the when property to an event
  565. $event->when = array($when);
  566. ]]></programlisting>
  567. <para>
  568. The <property>when</property> attribute also controls when reminders are sent to a
  569. user. Reminders are stored in an array and each event may have up to find reminders
  570. associated with it.
  571. </para>
  572. <para>
  573. For a <emphasis>reminder</emphasis> to be valid, it needs to have two attributes
  574. set: <property>method</property> and a time. <emphasis>Method</emphasis> can accept
  575. one of the following strings: "alert", "email", or "sms". The time should be entered
  576. as an integer and can be set with either the property <property>minutes</property>,
  577. <property>hours</property>, <property>days</property>, or
  578. <property>absoluteTime</property>. However, a valid request may only have one of
  579. these attributes set. If a mixed time is desired, convert to the most precise unit
  580. available. For example, 1 hour and 30 minutes should be entered as 90 minutes.
  581. </para>
  582. <programlisting language="php"><![CDATA[
  583. // Create a new reminder object. It should be set to send an email
  584. // to the user 10 minutes beforehand.
  585. $reminder = $service->newReminder();
  586. $reminder->method = "email";
  587. $reminder->minutes = "10";
  588. // Apply the reminder to an existing event's when property
  589. $when = $event->when[0];
  590. $when->reminders = array($reminder);
  591. ]]></programlisting>
  592. </sect3>
  593. <sect3 id="zend.gdata.calendar.creating_events.recurring">
  594. <title>Creating Recurring Events</title>
  595. <para>
  596. Recurring events are created the same way as single-occurrence events, except a
  597. recurrence attribute should be provided instead of a where attribute. The
  598. recurrence attribute should hold a string describing the event's recurrence pattern
  599. using properties defined in the iCalendar standard (<ulink
  600. url="http://www.ietf.org/rfc/rfc2445.txt">RFC 2445</ulink>).
  601. </para>
  602. <para>
  603. Exceptions to the recurrence pattern will usually be specified by a distinct
  604. <property>recurrenceException</property> attribute. However, the iCalendar standard
  605. provides a secondary format for defining recurrences, and the possibility that
  606. either may be used must be accounted for.
  607. </para>
  608. <para>
  609. Due to the complexity of parsing recurrence patterns, further information on this
  610. them is outside the scope of this document. However, more information can be found
  611. in the <ulink
  612. url="http://code.google.com/apis/gdata/elements.html#gdRecurrence">Common
  613. Elements section of the Google Data <acronym>API</acronym>s Developer
  614. Guide</ulink>, as well as in <acronym>RFC</acronym> 2445.
  615. </para>
  616. <programlisting language="php"><![CDATA[
  617. // Create a new entry using the calendar service's magic factory method
  618. $event= $service->newEventEntry();
  619. // Populate the event with the desired information
  620. // Note that each attribute is crated as an instance of a matching class
  621. $event->title = $service->newTitle("My Recurring Event");
  622. $event->where = array($service->newWhere("Palo Alto, California"));
  623. $event->content =
  624. $service->newContent(' This is my other awesome event, ' .
  625. ' occurring all-day every Tuesday from ' .
  626. '2007-05-01 until 207-09-04. No RSVP required.');
  627. // Set the duration and frequency by specifying a recurrence pattern.
  628. $recurrence = "DTSTART;VALUE=DATE:20070501\r\n" .
  629. "DTEND;VALUE=DATE:20070502\r\n" .
  630. "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904\r\n";
  631. $event->recurrence = $service->newRecurrence($recurrence);
  632. // Upload the event to the calendar server
  633. // A copy of the event as it is recorded on the server is returned
  634. $newEvent = $service->insertEvent($event);
  635. ]]></programlisting>
  636. </sect3>
  637. <sect3 id="zend.gdata.calendar.creating_events.quickadd">
  638. <title>Using QuickAdd</title>
  639. <para>
  640. QuickAdd is a feature which allows events to be created using free-form text entry.
  641. For example, the string "Dinner at Joe's Diner on Thursday" would create an event
  642. with the title "Dinner", location "Joe's Diner", and date "Thursday". To take
  643. advantage of QuickAdd, create a new <property>QuickAdd</property> property set to
  644. <constant>TRUE</constant> and store the freeform text as a
  645. <property>content</property> property.
  646. </para>
  647. <programlisting language="php"><![CDATA[
  648. // Create a new entry using the calendar service's magic factory method
  649. $event= $service->newEventEntry();
  650. // Populate the event with the desired information
  651. $event->content= $service->newContent("Dinner at Joe's Diner on Thursday");
  652. $event->quickAdd = $service->newQuickAdd("true");
  653. // Upload the event to the calendar server
  654. // A copy of the event as it is recorded on the server is returned
  655. $newEvent = $service->insertEvent($event);
  656. ]]></programlisting>
  657. </sect3>
  658. </sect2>
  659. <sect2 id="zend.gdata.calendar.modifying_events">
  660. <title>Modifying Events</title>
  661. <para>
  662. Once an instance of an event has been obtained, the event's attributes can be locally
  663. modified in the same way as when creating an event. Once all modifications are
  664. complete, calling the event's <methodname>save()</methodname> method will upload the
  665. changes to the calendar server and return a copy of the event as it was created on the
  666. server.
  667. </para>
  668. <para>
  669. In the event another user has modified the event since the local copy was retrieved,
  670. <methodname>save()</methodname> will fail and the server will return a 409 (Conflict)
  671. status code. To resolve this a fresh copy of the event must be retrieved from the server
  672. before attempting to resubmit any modifications.
  673. </para>
  674. <programlisting language="php"><![CDATA[
  675. // Get the first event in the user's event list
  676. $event = $eventFeed[0];
  677. // Change the title to a new value
  678. $event->title = $service->newTitle("Woof!");
  679. // Upload the changes to the server
  680. try {
  681. $event->save();
  682. } catch (Zend_Gdata_App_Exception $e) {
  683. echo "Error: " . $e->getMessage();
  684. }
  685. ]]></programlisting>
  686. </sect2>
  687. <sect2 id="zend.gdata.calendar.deleting_events">
  688. <title>Deleting Events</title>
  689. <para>
  690. Calendar events can be deleted either by calling the calendar service's
  691. <methodname>delete()</methodname> method and providing the edit <acronym>URL</acronym>
  692. of an event or by calling an existing event's own <methodname>delete()</methodname>
  693. method.
  694. </para>
  695. <para>
  696. In either case, the deleted event will still show up on a user's private event feed if
  697. an <property>updateMin</property> query parameter is provided. Deleted events can be
  698. distinguished from regular events because they will have their
  699. <property>eventStatus</property> property set to
  700. "http://schemas.google.com/g/2005#event.canceled".
  701. </para>
  702. <programlisting language="php"><![CDATA[
  703. // Option 1: Events can be deleted directly
  704. $event->delete();
  705. ]]></programlisting>
  706. <programlisting language="php"><![CDATA[
  707. // Option 2: Events can be deleted supplying the edit URL of the event
  708. // to the calendar service, if known
  709. $service->delete($event->getEditLink()->href);
  710. ]]></programlisting>
  711. </sect2>
  712. <sect2 id="zend.gdata.calendar.comments">
  713. <title>Accessing Event Comments</title>
  714. <para>
  715. When using the full event view, comments are not directly stored within an entry.
  716. Instead, each event contains a <acronym>URL</acronym> to its associated comment feed
  717. which must be manually requested.
  718. </para>
  719. <para>
  720. Working with comments is fundamentally similar to working with events, with the only
  721. significant difference being that a different feed and event class should be used and
  722. that the additional meta-data for events such as where and when does not exist for
  723. comments. Specifically, the comment's author is stored in the
  724. <property>author</property> property, and the comment text is stored in the
  725. <property>content</property> property.
  726. </para>
  727. <programlisting language="php"><![CDATA[
  728. // Extract the comment URL from the first event in a user's feed list
  729. $event = $eventFeed[0];
  730. $commentUrl = $event->comments->feedLink->url;
  731. // Retrieve the comment list for the event
  732. try {
  733. $commentFeed = $service->getFeed($commentUrl);
  734. } catch (Zend_Gdata_App_Exception $e) {
  735. echo "Error: " . $e->getMessage();
  736. }
  737. // Output each comment as an HTML list
  738. echo "<ul>";
  739. foreach ($commentFeed as $comment) {
  740. echo "<li><em>Comment By: " . $comment->author->name "</em><br/>" .
  741. $comment->content . "</li>";
  742. }
  743. echo "</ul>";
  744. ]]></programlisting>
  745. </sect2>
  746. </sect1>