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.
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
27 require_once('Zend/Gdata/App/Util.php');
32 require_once('Zend/Gdata/Query.php');
35 * Assists in constructing queries for Google Calendar events
37 * @link http://code.google.com/apis/gdata/calendar/
41 * @subpackage Calendar
42 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
43 * @license http://framework.zend.com/license/new-bsd New BSD License
45 class Zend_Gdata_Calendar_EventQuery extends Zend_Gdata_Query
48 const CALENDAR_FEED_URI = 'http://www.google.com/calendar/feeds';
51 * The default URI used for feeds.
53 protected $_defaultFeedUri = self::CALENDAR_FEED_URI;
56 * The comment ID to retrieve. If null, no specific comment will be
57 * retrieved unless already included in the query URI. The event ID
58 * ($_event) must be set, otherwise this property is ignored.
60 protected $_comments = null;
63 * The calendar address to be requested by queries. This may be an email
64 * address if requesting the primary calendar for a user. Defaults to
65 * "default" (the currently authenticated user). A null value should be
66 * used when the calendar address has already been set as part of the
69 protected $_user = 'default';
72 * The visibility to be requested by queries. Defaults to "public". A
73 * null value should be used when the calendar address has already been
74 * set as part of the query URI.
76 protected $_visibility = 'public';
79 * Projection to be requested by queries. Defaults to "full". A null value
80 * should be used when the calendar address has already been set as part
83 protected $_projection = 'full';
86 * The event ID to retrieve. If null, no specific event will be retrieved
87 * unless already included in the query URI.
89 protected $_event = null;
92 * Create Gdata_Calendar_EventQuery object. If a URL is provided,
93 * it becomes the base URL, and additional URL components may be
94 * appended. For instance, if $url is 'http://www.google.com/calendar',
95 * the default URL constructed will be
96 * 'http://www.google.com/calendar/default/public/full'.
98 * If the URL already contains a calendar ID, projection, visibility,
99 * event ID, or comment ID, you will need to set these fields to null
100 * to prevent them from being inserted. See this class's properties for
103 * @param string $url The URL to use as the base path for requests
105 public function __construct($url = null)
107 parent::__construct($url);
112 * @param string $value
113 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
115 public function setComments($value)
117 $this->_comments = $value;
123 * @param string $value
124 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
126 public function setEvent($value)
128 $this->_event = $value;
134 * @param string $value
135 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
137 public function setProjection($value)
139 $this->_projection = $value;
145 * @param string $value
146 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
148 public function setUser($value)
150 $this->_user = $value;
157 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
159 public function setVisibility($value)
161 $this->_visibility = $value;
167 * @return string comments
169 public function getComments()
171 return $this->_comments;
176 * @return string event
178 public function getEvent()
180 return $this->_event;
185 * @return string projection
187 public function getProjection()
189 return $this->_projection;
194 * @return string user
196 public function getUser()
203 * @return string visibility
205 public function getVisibility()
207 return $this->_visibility;
212 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
214 public function setStartMax($value)
216 if ($value != null) {
217 $this->_params['start-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
219 unset($this->_params['start-max']);
226 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
228 public function setStartMin($value)
230 if ($value != null) {
231 $this->_params['start-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
233 unset($this->_params['start-min']);
239 * @param string $value
240 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
242 public function setOrderBy($value)
244 if ($value != null) {
245 $this->_params['orderby'] = $value;
247 unset($this->_params['orderby']);
253 * @return int start-max
255 public function getStartMax()
257 if (array_key_exists('start-max', $this->_params)) {
258 return $this->_params['start-max'];
265 * @return int start-min
267 public function getStartMin()
269 if (array_key_exists('start-min', $this->_params)) {
270 return $this->_params['start-min'];
277 * @return string orderby
279 public function getOrderBy()
281 if (array_key_exists('orderby', $this->_params)) {
282 return $this->_params['orderby'];
289 * @return string sortorder
291 public function getSortOrder()
293 if (array_key_exists('sortorder', $this->_params)) {
294 return $this->_params['sortorder'];
301 * @return string sortorder
303 public function setSortOrder($value)
305 if ($value != null) {
306 $this->_params['sortorder'] = $value;
308 unset($this->_params['sortorder']);
314 * @return string recurrence-expansion-start
316 public function getRecurrenceExpansionStart()
318 if (array_key_exists('recurrence-expansion-start', $this->_params)) {
319 return $this->_params['recurrence-expansion-start'];
326 * @return string recurrence-expansion-start
328 public function setRecurrenceExpansionStart($value)
330 if ($value != null) {
331 $this->_params['recurrence-expansion-start'] = Zend_Gdata_App_Util::formatTimestamp($value);
333 unset($this->_params['recurrence-expansion-start']);
340 * @return string recurrence-expansion-end
342 public function getRecurrenceExpansionEnd()
344 if (array_key_exists('recurrence-expansion-end', $this->_params)) {
345 return $this->_params['recurrence-expansion-end'];
352 * @return string recurrence-expansion-end
354 public function setRecurrenceExpansionEnd($value)
356 if ($value != null) {
357 $this->_params['recurrence-expansion-end'] = Zend_Gdata_App_Util::formatTimestamp($value);
359 unset($this->_params['recurrence-expansion-end']);
365 * @param string $value Also accepts bools.
366 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
368 public function getSingleEvents()
370 if (array_key_exists('singleevents', $this->_params)) {
371 $value = $this->_params['singleevents'];
380 require_once 'Zend/Gdata/App/Exception.php';
381 throw new Zend_Gdata_App_Exception(
382 'Invalid query param value for futureevents: ' .
383 $value . ' It must be a boolean.');
391 * @param string $value Also accepts bools. If using a string, must be either "true" or "false".
392 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
394 public function setSingleEvents($value)
396 if ($value !== null) {
397 if (is_bool($value)) {
398 $this->_params['singleevents'] = ($value?'true':'false');
399 } elseif ($value == 'true' | $value == 'false') {
400 $this->_params['singleevents'] = $value;
402 require_once 'Zend/Gdata/App/Exception.php';
403 throw new Zend_Gdata_App_Exception(
404 'Invalid query param value for futureevents: ' .
405 $value . ' It must be a boolean.');
408 unset($this->_params['singleevents']);
414 * @return string futureevents
416 public function getFutureEvents()
418 if (array_key_exists('futureevents', $this->_params)) {
419 $value = $this->_params['futureevents'];
428 require_once 'Zend/Gdata/App/Exception.php';
429 throw new Zend_Gdata_App_Exception(
430 'Invalid query param value for futureevents: ' .
431 $value . ' It must be a boolean.');
439 * @param string $value Also accepts bools. If using a string, must be either "true" or "false" or
440 * an exception will be thrown on retrieval.
441 * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
443 public function setFutureEvents($value)
445 if ($value !== null) {
446 if (is_bool($value)) {
447 $this->_params['futureevents'] = ($value?'true':'false');
448 } elseif ($value == 'true' | $value == 'false') {
449 $this->_params['futureevents'] = $value;
451 require_once 'Zend/Gdata/App/Exception.php';
452 throw new Zend_Gdata_App_Exception(
453 'Invalid query param value for futureevents: ' .
454 $value . ' It must be a boolean.');
457 unset($this->_params['futureevents']);
465 public function getQueryUrl()
467 if (isset($this->_url)) {
470 $uri = $this->_defaultFeedUri;
472 if ($this->getUser() != null) {
473 $uri .= '/' . $this->getUser();
475 if ($this->getVisibility() != null) {
476 $uri .= '/' . $this->getVisibility();
478 if ($this->getProjection() != null) {
479 $uri .= '/' . $this->getProjection();
481 if ($this->getEvent() != null) {
482 $uri .= '/' . $this->getEvent();
483 if ($this->getComments() != null) {
484 $uri .= '/comments/' . $this->getComments();
487 $uri .= $this->getQueryString();