2
0

Calendar.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Calendar
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata
  23. */
  24. require_once 'Zend/Gdata.php';
  25. /**
  26. * @see Zend_Gdata_Calendar_EventFeed
  27. */
  28. require_once 'Zend/Gdata/Calendar/EventFeed.php';
  29. /**
  30. * @see Zend_Gdata_Calendar_EventEntry
  31. */
  32. require_once 'Zend/Gdata/Calendar/EventEntry.php';
  33. /**
  34. * @see Zend_Gdata_Calendar_ListFeed
  35. */
  36. require_once 'Zend/Gdata/Calendar/ListFeed.php';
  37. /**
  38. * @see Zend_Gdata_Calendar_ListEntry
  39. */
  40. require_once 'Zend/Gdata/Calendar/ListEntry.php';
  41. /**
  42. * Service class for interacting with the Google Calendar data API
  43. * @link http://code.google.com/apis/gdata/calendar.html
  44. *
  45. * @category Zend
  46. * @package Zend_Gdata
  47. * @subpackage Calendar
  48. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  49. * @license http://framework.zend.com/license/new-bsd New BSD License
  50. */
  51. class Zend_Gdata_Calendar extends Zend_Gdata
  52. {
  53. const CALENDAR_FEED_URI = 'http://www.google.com/calendar/feeds';
  54. const CALENDAR_EVENT_FEED_URI = 'http://www.google.com/calendar/feeds/default/private/full';
  55. const AUTH_SERVICE_NAME = 'cl';
  56. protected $_defaultPostUri = self::CALENDAR_EVENT_FEED_URI;
  57. /**
  58. * Namespaces used for Zend_Gdata_Calendar
  59. *
  60. * @var array
  61. */
  62. public static $namespaces = array(
  63. array('gCal', 'http://schemas.google.com/gCal/2005', 1, 0)
  64. );
  65. /**
  66. * Create Gdata_Calendar object
  67. *
  68. * @param Zend_Http_Client $client (optional) The HTTP client to use when
  69. * when communicating with the Google servers.
  70. * @param string $applicationId The identity of the app in the form of Company-AppName-Version
  71. */
  72. public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
  73. {
  74. $this->registerPackage('Zend_Gdata_Calendar');
  75. $this->registerPackage('Zend_Gdata_Calendar_Extension');
  76. parent::__construct($client, $applicationId);
  77. $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
  78. }
  79. /**
  80. * Retreive feed object
  81. *
  82. * @param mixed $location The location for the feed, as a URL or Query
  83. * @return Zend_Gdata_Calendar_EventFeed
  84. */
  85. public function getCalendarEventFeed($location = null)
  86. {
  87. if ($location == null) {
  88. $uri = self::CALENDAR_EVENT_FEED_URI;
  89. } else if ($location instanceof Zend_Gdata_Query) {
  90. $uri = $location->getQueryUrl();
  91. } else {
  92. $uri = $location;
  93. }
  94. return parent::getFeed($uri, 'Zend_Gdata_Calendar_EventFeed');
  95. }
  96. /**
  97. * Retreive entry object
  98. *
  99. * @return Zend_Gdata_Calendar_EventEntry
  100. */
  101. public function getCalendarEventEntry($location = null)
  102. {
  103. if ($location == null) {
  104. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  105. throw new Zend_Gdata_App_InvalidArgumentException(
  106. 'Location must not be null');
  107. } else if ($location instanceof Zend_Gdata_Query) {
  108. $uri = $location->getQueryUrl();
  109. } else {
  110. $uri = $location;
  111. }
  112. return parent::getEntry($uri, 'Zend_Gdata_Calendar_EventEntry');
  113. }
  114. /**
  115. * Retrieve feed object
  116. *
  117. * @return Zend_Gdata_Calendar_ListFeed
  118. */
  119. public function getCalendarListFeed()
  120. {
  121. $uri = self::CALENDAR_FEED_URI . '/default';
  122. return parent::getFeed($uri,'Zend_Gdata_Calendar_ListFeed');
  123. }
  124. /**
  125. * Retreive entryobject
  126. *
  127. * @return Zend_Gdata_Calendar_ListEntry
  128. */
  129. public function getCalendarListEntry($location = null)
  130. {
  131. if ($location == null) {
  132. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  133. throw new Zend_Gdata_App_InvalidArgumentException(
  134. 'Location must not be null');
  135. } else if ($location instanceof Zend_Gdata_Query) {
  136. $uri = $location->getQueryUrl();
  137. } else {
  138. $uri = $location;
  139. }
  140. return parent::getEntry($uri,'Zend_Gdata_Calendar_ListEntry');
  141. }
  142. public function insertEvent($event, $uri=null)
  143. {
  144. if ($uri == null) {
  145. $uri = $this->_defaultPostUri;
  146. }
  147. $newEvent = $this->insertEntry($event, $uri, 'Zend_Gdata_Calendar_EventEntry');
  148. return $newEvent;
  149. }
  150. }