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