/library/Zend/GData/Calendar/EventQuery.php

https://github.com/jtai/zf2 · PHP · 484 lines · 263 code · 39 blank · 182 comment · 60 complexity · 934a78f2b93ec86768e086ee3e853efb MD5 · raw file

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