PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/Exercise/zf2
PHP | 485 lines | 263 code | 39 blank | 183 comment | 60 complexity | 8d21a56fe00a2cd0a426ebcc500805af 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-2010 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. * @namespace
  24. */
  25. namespace Zend\GData\Calendar;
  26. use Zend\GData\App;
  27. /**
  28. * Assists in constructing queries for Google Calendar events
  29. *
  30. * @link http://code.google.com/apis/gdata/calendar/
  31. *
  32. * @uses \Zend\GData\App\Exception
  33. * @uses \Zend\GData\App\Util
  34. * @uses \Zend\GData\Query
  35. * @category Zend
  36. * @package Zend_Gdata
  37. * @subpackage Calendar
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class EventQuery extends \Zend\GData\Query
  42. {
  43. const CALENDAR_FEED_URI = 'http://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 'http://www.google.com/calendar',
  83. * the default URL constructed will be
  84. * 'http://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'] = 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'] = 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'] = 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'] = 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. throw new App\Exception(
  345. 'Invalid query param value for futureevents: ' .
  346. $value . ' It must be a boolean.');
  347. }
  348. } else {
  349. return null;
  350. }
  351. }
  352. /**
  353. * @param string $value Also accepts bools. If using a string, must be either "true" or "false".
  354. * @return \Zend\GData\Calendar\EventQuery Provides a fluent interface
  355. */
  356. public function setSingleEvents($value)
  357. {
  358. if ($value !== null) {
  359. if (is_bool($value)) {
  360. $this->_params['singleevents'] = ($value?'true':'false');
  361. } elseif ($value == 'true' | $value == 'false') {
  362. $this->_params['singleevents'] = $value;
  363. } else {
  364. throw new App\Exception(
  365. 'Invalid query param value for futureevents: ' .
  366. $value . ' It must be a boolean.');
  367. }
  368. } else {
  369. unset($this->_params['singleevents']);
  370. }
  371. return $this;
  372. }
  373. /**
  374. * @return string futureevents
  375. */
  376. public function getFutureEvents()
  377. {
  378. if (array_key_exists('futureevents', $this->_params)) {
  379. $value = $this->_params['futureevents'];
  380. switch ($value) {
  381. case 'true':
  382. return true;
  383. break;
  384. case 'false':
  385. return false;
  386. break;
  387. default:
  388. throw new App\Exception(
  389. 'Invalid query param value for futureevents: ' .
  390. $value . ' It must be a boolean.');
  391. }
  392. } else {
  393. return null;
  394. }
  395. }
  396. /**
  397. * @param string $value Also accepts bools. If using a string, must be either "true" or "false" or
  398. * an exception will be thrown on retrieval.
  399. * @return \Zend\GData\Calendar\EventQuery Provides a fluent interface
  400. */
  401. public function setFutureEvents($value)
  402. {
  403. if ($value !== null) {
  404. if (is_bool($value)) {
  405. $this->_params['futureevents'] = ($value?'true':'false');
  406. } elseif ($value == 'true' | $value == 'false') {
  407. $this->_params['futureevents'] = $value;
  408. } else {
  409. throw new App\Exception(
  410. 'Invalid query param value for futureevents: ' .
  411. $value . ' It must be a boolean.');
  412. }
  413. } else {
  414. unset($this->_params['futureevents']);
  415. }
  416. return $this;
  417. }
  418. /**
  419. * @return string url
  420. */
  421. public function getQueryUrl()
  422. {
  423. if (isset($this->_url)) {
  424. $uri = $this->_url;
  425. } else {
  426. $uri = $this->_defaultFeedUri;
  427. }
  428. if ($this->getUser() != null) {
  429. $uri .= '/' . $this->getUser();
  430. }
  431. if ($this->getVisibility() != null) {
  432. $uri .= '/' . $this->getVisibility();
  433. }
  434. if ($this->getProjection() != null) {
  435. $uri .= '/' . $this->getProjection();
  436. }
  437. if ($this->getEvent() != null) {
  438. $uri .= '/' . $this->getEvent();
  439. if ($this->getComments() != null) {
  440. $uri .= '/comments/' . $this->getComments();
  441. }
  442. }
  443. $uri .= $this->getQueryString();
  444. return $uri;
  445. }
  446. }