EventQuery.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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-2009 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. * Zend_Gdata_App_util
  24. */
  25. require_once('Zend/Gdata/App/Util.php');
  26. /**
  27. * Zend_Gdata_Query
  28. */
  29. require_once('Zend/Gdata/Query.php');
  30. /**
  31. * Assists in constructing queries for Google Calendar events
  32. *
  33. * @link http://code.google.com/apis/gdata/calendar/
  34. *
  35. * @category Zend
  36. * @package Zend_Gdata
  37. * @subpackage Calendar
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Gdata_Calendar_EventQuery extends Zend_Gdata_Query
  42. {
  43. const CALENDAR_FEED_URI = 'http://www.google.com/calendar/feeds';
  44. protected $_defaultFeedUri = self::CALENDAR_FEED_URI;
  45. protected $_comments = null;
  46. protected $_user = null;
  47. protected $_visibility = null;
  48. protected $_projection = null;
  49. protected $_event = null;
  50. /**
  51. * Create Gdata_Calendar_EventQuery object. If a URL is provided,
  52. * it becomes the base URL, and additional URL components may be
  53. * appended. For instance, if $url is 'http://www.foo.com', the
  54. * default URL constructed will be 'http://www.foo.com/default/public/full'
  55. *
  56. * @param string $url The URL to use as the base path for requests
  57. */
  58. public function __construct($url = null)
  59. {
  60. parent::__construct($url);
  61. }
  62. /**
  63. * @param string $value
  64. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  65. */
  66. public function setComments($value)
  67. {
  68. $this->_comments = $value;
  69. return $this;
  70. }
  71. /**
  72. * @param string $value
  73. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  74. */
  75. public function setEvent($value)
  76. {
  77. $this->_event = $value;
  78. return $this;
  79. }
  80. /**
  81. * @param string $value
  82. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  83. */
  84. public function setProjection($value)
  85. {
  86. $this->_projection = $value;
  87. return $this;
  88. }
  89. /**
  90. * @param string $value
  91. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  92. */
  93. public function setUser($value)
  94. {
  95. $this->_user = $value;
  96. return $this;
  97. }
  98. /**
  99. * @param bool $value
  100. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  101. */
  102. public function setVisibility($value)
  103. {
  104. $this->_visibility = $value;
  105. return $this;
  106. }
  107. /**
  108. * @return string comments
  109. */
  110. public function getComments()
  111. {
  112. return $this->_comments;
  113. }
  114. /**
  115. * @return string event
  116. */
  117. public function getEvent()
  118. {
  119. return $this->_event;
  120. }
  121. /**
  122. * @return string projection
  123. */
  124. public function getProjection()
  125. {
  126. return $this->_projection;
  127. }
  128. /**
  129. * @return string user
  130. */
  131. public function getUser()
  132. {
  133. return $this->_user;
  134. }
  135. /**
  136. * @return string visibility
  137. */
  138. public function getVisibility()
  139. {
  140. return $this->_visibility;
  141. }
  142. /**
  143. * @param int $value
  144. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  145. */
  146. public function setStartMax($value)
  147. {
  148. if ($value != null) {
  149. $this->_params['start-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
  150. } else {
  151. unset($this->_params['start-max']);
  152. }
  153. return $this;
  154. }
  155. /**
  156. * @param int $value
  157. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  158. */
  159. public function setStartMin($value)
  160. {
  161. if ($value != null) {
  162. $this->_params['start-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
  163. } else {
  164. unset($this->_params['start-min']);
  165. }
  166. return $this;
  167. }
  168. /**
  169. * @param string $value
  170. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  171. */
  172. public function setOrderBy($value)
  173. {
  174. if ($value != null) {
  175. $this->_params['orderby'] = $value;
  176. } else {
  177. unset($this->_params['orderby']);
  178. }
  179. return $this;
  180. }
  181. /**
  182. * @return int start-max
  183. */
  184. public function getStartMax()
  185. {
  186. if (array_key_exists('start-max', $this->_params)) {
  187. return $this->_params['start-max'];
  188. } else {
  189. return null;
  190. }
  191. }
  192. /**
  193. * @return int start-min
  194. */
  195. public function getStartMin()
  196. {
  197. if (array_key_exists('start-min', $this->_params)) {
  198. return $this->_params['start-min'];
  199. } else {
  200. return null;
  201. }
  202. }
  203. /**
  204. * @return string orderby
  205. */
  206. public function getOrderBy()
  207. {
  208. if (array_key_exists('orderby', $this->_params)) {
  209. return $this->_params['orderby'];
  210. } else {
  211. return null;
  212. }
  213. }
  214. /**
  215. * @return string sortorder
  216. */
  217. public function getSortOrder()
  218. {
  219. if (array_key_exists('sortorder', $this->_params)) {
  220. return $this->_params['sortorder'];
  221. } else {
  222. return null;
  223. }
  224. }
  225. /**
  226. * @return string sortorder
  227. */
  228. public function setSortOrder($value)
  229. {
  230. if ($value != null) {
  231. $this->_params['sortorder'] = $value;
  232. } else {
  233. unset($this->_params['sortorder']);
  234. }
  235. return $this;
  236. }
  237. /**
  238. * @return string recurrence-expansion-start
  239. */
  240. public function getRecurrenceExpansionStart()
  241. {
  242. if (array_key_exists('recurrence-expansion-start', $this->_params)) {
  243. return $this->_params['recurrence-expansion-start'];
  244. } else {
  245. return null;
  246. }
  247. }
  248. /**
  249. * @return string recurrence-expansion-start
  250. */
  251. public function setRecurrenceExpansionStart($value)
  252. {
  253. if ($value != null) {
  254. $this->_params['recurrence-expansion-start'] = Zend_Gdata_App_Util::formatTimestamp($value);
  255. } else {
  256. unset($this->_params['recurrence-expansion-start']);
  257. }
  258. return $this;
  259. }
  260. /**
  261. * @return string recurrence-expansion-end
  262. */
  263. public function getRecurrenceExpansionEnd()
  264. {
  265. if (array_key_exists('recurrence-expansion-end', $this->_params)) {
  266. return $this->_params['recurrence-expansion-end'];
  267. } else {
  268. return null;
  269. }
  270. }
  271. /**
  272. * @return string recurrence-expansion-end
  273. */
  274. public function setRecurrenceExpansionEnd($value)
  275. {
  276. if ($value != null) {
  277. $this->_params['recurrence-expansion-end'] = Zend_Gdata_App_Util::formatTimestamp($value);
  278. } else {
  279. unset($this->_params['recurrence-expansion-end']);
  280. }
  281. return $this;
  282. }
  283. /**
  284. * @param string $value Also accepts bools.
  285. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  286. */
  287. public function getSingleEvents()
  288. {
  289. if (array_key_exists('singleevents', $this->_params)) {
  290. $value = $this->_params['singleevents'];
  291. switch ($value) {
  292. case 'true':
  293. return true;
  294. break;
  295. case 'false':
  296. return false;
  297. break;
  298. default:
  299. require_once 'Zend/Gdata/App/Exception.php';
  300. throw new Zend_Gdata_App_Exception(
  301. 'Invalid query param value for futureevents: ' .
  302. $value . ' It must be a boolean.');
  303. }
  304. } else {
  305. return null;
  306. }
  307. }
  308. /**
  309. * @param string $value Also accepts bools. If using a string, must be either "true" or "false".
  310. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  311. */
  312. public function setSingleEvents($value)
  313. {
  314. if ($value !== null) {
  315. if (is_bool($value)) {
  316. $this->_params['singleevents'] = ($value?'true':'false');
  317. } elseif ($value == 'true' | $value == 'false') {
  318. $this->_params['singleevents'] = $value;
  319. } else {
  320. require_once 'Zend/Gdata/App/Exception.php';
  321. throw new Zend_Gdata_App_Exception(
  322. 'Invalid query param value for futureevents: ' .
  323. $value . ' It must be a boolean.');
  324. }
  325. } else {
  326. unset($this->_params['singleevents']);
  327. }
  328. return $this;
  329. }
  330. /**
  331. * @return string futureevents
  332. */
  333. public function getFutureEvents()
  334. {
  335. if (array_key_exists('futureevents', $this->_params)) {
  336. $value = $this->_params['futureevents'];
  337. switch ($value) {
  338. case 'true':
  339. return true;
  340. break;
  341. case 'false':
  342. return false;
  343. break;
  344. default:
  345. require_once 'Zend/Gdata/App/Exception.php';
  346. throw new Zend_Gdata_App_Exception(
  347. 'Invalid query param value for futureevents: ' .
  348. $value . ' It must be a boolean.');
  349. }
  350. } else {
  351. return null;
  352. }
  353. }
  354. /**
  355. * @param string $value Also accepts bools. If using a string, must be either "true" or "false" or
  356. * an exception will be thrown on retrieval.
  357. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  358. */
  359. public function setFutureEvents($value)
  360. {
  361. if ($value !== null) {
  362. if (is_bool($value)) {
  363. $this->_params['futureevents'] = ($value?'true':'false');
  364. } elseif ($value == 'true' | $value == 'false') {
  365. $this->_params['futureevents'] = $value;
  366. } else {
  367. require_once 'Zend/Gdata/App/Exception.php';
  368. throw new Zend_Gdata_App_Exception(
  369. 'Invalid query param value for futureevents: ' .
  370. $value . ' It must be a boolean.');
  371. }
  372. } else {
  373. unset($this->_params['futureevents']);
  374. }
  375. return $this;
  376. }
  377. /**
  378. * @return string url
  379. */
  380. public function getQueryUrl()
  381. {
  382. if (isset($this->_url)) {
  383. $uri = $this->_url;
  384. } else {
  385. $uri = $this->_defaultFeedUri;
  386. }
  387. if ($this->getUser() != null) {
  388. $uri .= '/' . $this->getUser();
  389. } else {
  390. $uri .= '/default';
  391. }
  392. if ($this->getVisibility() != null) {
  393. $uri .= '/' . $this->getVisibility();
  394. } else {
  395. $uri .= '/public';
  396. }
  397. if ($this->getProjection() != null) {
  398. $uri .= '/' . $this->getProjection();
  399. } else {
  400. $uri .= '/full';
  401. }
  402. if ($this->getEvent() != null) {
  403. $uri .= '/' . $this->getEvent();
  404. if ($this->getComments() != null) {
  405. $uri .= '/comments/' . $this->getComments();
  406. }
  407. }
  408. $uri .= $this->getQueryString();
  409. return $uri;
  410. }
  411. }