EventQuery.php 12 KB

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