Calendar.php 4.9 KB

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