EventQuery.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. * 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-2015 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 = 'https://www.google.com/calendar/feeds';
  44. /**
  45. * The default URI used for feeds.
  46. */
  47. protected $_defaultFeedUri = self::CALENDAR_FEED_URI;
  48. /**
  49. * The comment ID to retrieve. If null, no specific comment will be
  50. * retrieved unless already included in the query URI. The event ID
  51. * ($_event) must be set, otherwise this property is ignored.
  52. */
  53. protected $_comments = null;
  54. /**
  55. * The calendar address to be requested by queries. This may be an email
  56. * address if requesting the primary calendar for a user. Defaults to
  57. * "default" (the currently authenticated user). A null value should be
  58. * used when the calendar address has already been set as part of the
  59. * query URI.
  60. */
  61. protected $_user = 'default';
  62. /*
  63. * The visibility to be requested by queries. Defaults to "public". A
  64. * null value should be used when the calendar address has already been
  65. * set as part of the query URI.
  66. */
  67. protected $_visibility = 'public';
  68. /**
  69. * Projection to be requested by queries. Defaults to "full". A null value
  70. * should be used when the calendar address has already been set as part
  71. * of the query URI.
  72. */
  73. protected $_projection = 'full';
  74. /**
  75. * The event ID to retrieve. If null, no specific event will be retrieved
  76. * unless already included in the query URI.
  77. */
  78. protected $_event = null;
  79. /**
  80. * Create Gdata_Calendar_EventQuery object. If a URL is provided,
  81. * it becomes the base URL, and additional URL components may be
  82. * appended. For instance, if $url is 'https://www.google.com/calendar',
  83. * the default URL constructed will be
  84. * 'https://www.google.com/calendar/default/public/full'.
  85. *
  86. * If the URL already contains a calendar ID, projection, visibility,
  87. * event ID, or comment ID, you will need to set these fields to null
  88. * to prevent them from being inserted. See this class's properties for
  89. * more information.
  90. *
  91. * @param string $url The URL to use as the base path for requests
  92. */
  93. public function __construct($url = null)
  94. {
  95. parent::__construct($url);
  96. }
  97. /**
  98. * @see $_comments
  99. * @param string $value
  100. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  101. */
  102. public function setComments($value)
  103. {
  104. $this->_comments = $value;
  105. return $this;
  106. }
  107. /**
  108. * @see $_event
  109. * @param string $value
  110. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  111. */
  112. public function setEvent($value)
  113. {
  114. $this->_event = $value;
  115. return $this;
  116. }
  117. /**
  118. * @see $_projection
  119. * @param string $value
  120. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  121. */
  122. public function setProjection($value)
  123. {
  124. $this->_projection = $value;
  125. return $this;
  126. }
  127. /**
  128. * @see $_user
  129. * @param string $value
  130. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  131. */
  132. public function setUser($value)
  133. {
  134. $this->_user = $value;
  135. return $this;
  136. }
  137. /**
  138. * @see $_visibility
  139. * @param bool $value
  140. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  141. */
  142. public function setVisibility($value)
  143. {
  144. $this->_visibility = $value;
  145. return $this;
  146. }
  147. /**
  148. * @see $_comments;
  149. * @return string comments
  150. */
  151. public function getComments()
  152. {
  153. return $this->_comments;
  154. }
  155. /**
  156. * @see $_event;
  157. * @return string event
  158. */
  159. public function getEvent()
  160. {
  161. return $this->_event;
  162. }
  163. /**
  164. * @see $_projection
  165. * @return string projection
  166. */
  167. public function getProjection()
  168. {
  169. return $this->_projection;
  170. }
  171. /**
  172. * @see $_user
  173. * @return string user
  174. */
  175. public function getUser()
  176. {
  177. return $this->_user;
  178. }
  179. /**
  180. * @see $_visibility
  181. * @return string visibility
  182. */
  183. public function getVisibility()
  184. {
  185. return $this->_visibility;
  186. }
  187. /**
  188. * @param int $value
  189. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  190. */
  191. public function setStartMax($value)
  192. {
  193. if ($value != null) {
  194. $this->_params['start-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
  195. } else {
  196. unset($this->_params['start-max']);
  197. }
  198. return $this;
  199. }
  200. /**
  201. * @param int $value
  202. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  203. */
  204. public function setStartMin($value)
  205. {
  206. if ($value != null) {
  207. $this->_params['start-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
  208. } else {
  209. unset($this->_params['start-min']);
  210. }
  211. return $this;
  212. }
  213. /**
  214. * @param string $value
  215. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  216. */
  217. public function setOrderBy($value)
  218. {
  219. if ($value != null) {
  220. $this->_params['orderby'] = $value;
  221. } else {
  222. unset($this->_params['orderby']);
  223. }
  224. return $this;
  225. }
  226. /**
  227. * @return int start-max
  228. */
  229. public function getStartMax()
  230. {
  231. if (array_key_exists('start-max', $this->_params)) {
  232. return $this->_params['start-max'];
  233. } else {
  234. return null;
  235. }
  236. }
  237. /**
  238. * @return int start-min
  239. */
  240. public function getStartMin()
  241. {
  242. if (array_key_exists('start-min', $this->_params)) {
  243. return $this->_params['start-min'];
  244. } else {
  245. return null;
  246. }
  247. }
  248. /**
  249. * @return string orderby
  250. */
  251. public function getOrderBy()
  252. {
  253. if (array_key_exists('orderby', $this->_params)) {
  254. return $this->_params['orderby'];
  255. } else {
  256. return null;
  257. }
  258. }
  259. /**
  260. * @return string sortorder
  261. */
  262. public function getSortOrder()
  263. {
  264. if (array_key_exists('sortorder', $this->_params)) {
  265. return $this->_params['sortorder'];
  266. } else {
  267. return null;
  268. }
  269. }
  270. /**
  271. * @return string sortorder
  272. */
  273. public function setSortOrder($value)
  274. {
  275. if ($value != null) {
  276. $this->_params['sortorder'] = $value;
  277. } else {
  278. unset($this->_params['sortorder']);
  279. }
  280. return $this;
  281. }
  282. /**
  283. * @return string recurrence-expansion-start
  284. */
  285. public function getRecurrenceExpansionStart()
  286. {
  287. if (array_key_exists('recurrence-expansion-start', $this->_params)) {
  288. return $this->_params['recurrence-expansion-start'];
  289. } else {
  290. return null;
  291. }
  292. }
  293. /**
  294. * @return string recurrence-expansion-start
  295. */
  296. public function setRecurrenceExpansionStart($value)
  297. {
  298. if ($value != null) {
  299. $this->_params['recurrence-expansion-start'] = Zend_Gdata_App_Util::formatTimestamp($value);
  300. } else {
  301. unset($this->_params['recurrence-expansion-start']);
  302. }
  303. return $this;
  304. }
  305. /**
  306. * @return string recurrence-expansion-end
  307. */
  308. public function getRecurrenceExpansionEnd()
  309. {
  310. if (array_key_exists('recurrence-expansion-end', $this->_params)) {
  311. return $this->_params['recurrence-expansion-end'];
  312. } else {
  313. return null;
  314. }
  315. }
  316. /**
  317. * @return string recurrence-expansion-end
  318. */
  319. public function setRecurrenceExpansionEnd($value)
  320. {
  321. if ($value != null) {
  322. $this->_params['recurrence-expansion-end'] = Zend_Gdata_App_Util::formatTimestamp($value);
  323. } else {
  324. unset($this->_params['recurrence-expansion-end']);
  325. }
  326. return $this;
  327. }
  328. /**
  329. * @param string $value Also accepts bools.
  330. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  331. */
  332. public function getSingleEvents()
  333. {
  334. if (array_key_exists('singleevents', $this->_params)) {
  335. $value = $this->_params['singleevents'];
  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".
  355. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  356. */
  357. public function setSingleEvents($value)
  358. {
  359. if ($value !== null) {
  360. if (is_bool($value)) {
  361. $this->_params['singleevents'] = ($value?'true':'false');
  362. } elseif ($value == 'true' | $value == 'false') {
  363. $this->_params['singleevents'] = $value;
  364. } else {
  365. require_once 'Zend/Gdata/App/Exception.php';
  366. throw new Zend_Gdata_App_Exception(
  367. 'Invalid query param value for futureevents: ' .
  368. $value . ' It must be a boolean.');
  369. }
  370. } else {
  371. unset($this->_params['singleevents']);
  372. }
  373. return $this;
  374. }
  375. /**
  376. * @return string futureevents
  377. */
  378. public function getFutureEvents()
  379. {
  380. if (array_key_exists('futureevents', $this->_params)) {
  381. $value = $this->_params['futureevents'];
  382. switch ($value) {
  383. case 'true':
  384. return true;
  385. break;
  386. case 'false':
  387. return false;
  388. break;
  389. default:
  390. require_once 'Zend/Gdata/App/Exception.php';
  391. throw new Zend_Gdata_App_Exception(
  392. 'Invalid query param value for futureevents: ' .
  393. $value . ' It must be a boolean.');
  394. }
  395. } else {
  396. return null;
  397. }
  398. }
  399. /**
  400. * @param string $value Also accepts bools. If using a string, must be either "true" or "false" or
  401. * an exception will be thrown on retrieval.
  402. * @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
  403. */
  404. public function setFutureEvents($value)
  405. {
  406. if ($value !== null) {
  407. if (is_bool($value)) {
  408. $this->_params['futureevents'] = ($value?'true':'false');
  409. } elseif ($value == 'true' | $value == 'false') {
  410. $this->_params['futureevents'] = $value;
  411. } else {
  412. require_once 'Zend/Gdata/App/Exception.php';
  413. throw new Zend_Gdata_App_Exception(
  414. 'Invalid query param value for futureevents: ' .
  415. $value . ' It must be a boolean.');
  416. }
  417. } else {
  418. unset($this->_params['futureevents']);
  419. }
  420. return $this;
  421. }
  422. /**
  423. * @return string url
  424. */
  425. public function getQueryUrl()
  426. {
  427. if (isset($this->_url)) {
  428. $uri = $this->_url;
  429. } else {
  430. $uri = $this->_defaultFeedUri;
  431. }
  432. if ($this->getUser() != null) {
  433. $uri .= '/' . $this->getUser();
  434. }
  435. if ($this->getVisibility() != null) {
  436. $uri .= '/' . $this->getVisibility();
  437. }
  438. if ($this->getProjection() != null) {
  439. $uri .= '/' . $this->getProjection();
  440. }
  441. if ($this->getEvent() != null) {
  442. $uri .= '/' . $this->getEvent();
  443. if ($this->getComments() != null) {
  444. $uri .= '/comments/' . $this->getComments();
  445. }
  446. }
  447. $uri .= $this->getQueryString();
  448. return $uri;
  449. }
  450. }