PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/zend/Zend/Gdata/Query.php

http://github.com/moodle/moodle
PHP | 418 lines | 236 code | 37 blank | 145 comment | 56 complexity | 46eab981b45622a351f001cb07224c6a MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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 Gdata
  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. * Zend_Gdata_App_Util
  24. */
  25. require_once 'Zend/Gdata/App/Util.php';
  26. /**
  27. * Provides a mechanism to build a query URL for Gdata services.
  28. * Queries are not defined for APP, but are provided by Gdata services
  29. * as an extension.
  30. *
  31. * @category Zend
  32. * @package Zend_Gdata
  33. * @subpackage Gdata
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Gdata_Query
  38. {
  39. /**
  40. * Query parameters.
  41. *
  42. * @var array
  43. */
  44. protected $_params = array();
  45. /**
  46. * Default URL
  47. *
  48. * @var string
  49. */
  50. protected $_defaultFeedUri = null;
  51. /**
  52. * Base URL
  53. * TODO: Add setters and getters
  54. *
  55. * @var string
  56. */
  57. protected $_url = null;
  58. /**
  59. * Category for the query
  60. *
  61. * @var string
  62. */
  63. protected $_category = null;
  64. /**
  65. * Create Gdata_Query object
  66. */
  67. public function __construct($url = null)
  68. {
  69. $this->_url = $url;
  70. }
  71. /**
  72. * @return string querystring
  73. */
  74. public function getQueryString()
  75. {
  76. $queryArray = array();
  77. foreach ($this->_params as $name => $value) {
  78. if (substr($name, 0, 1) == '_') {
  79. continue;
  80. }
  81. $queryArray[] = urlencode($name) . '=' . urlencode($value);
  82. }
  83. if (count($queryArray) > 0) {
  84. return '?' . implode('&', $queryArray);
  85. } else {
  86. return '';
  87. }
  88. }
  89. /**
  90. *
  91. */
  92. public function resetParameters()
  93. {
  94. $this->_params = array();
  95. }
  96. /**
  97. * @return string url
  98. */
  99. public function getQueryUrl()
  100. {
  101. if ($this->_url == null) {
  102. $url = $this->_defaultFeedUri;
  103. } else {
  104. $url = $this->_url;
  105. }
  106. if ($this->getCategory() !== null) {
  107. $url .= '/-/' . $this->getCategory();
  108. }
  109. $url .= $this->getQueryString();
  110. return $url;
  111. }
  112. /**
  113. * @param string $name
  114. * @param string $value
  115. * @return Zend_Gdata_Query Provides a fluent interface
  116. */
  117. public function setParam($name, $value)
  118. {
  119. $this->_params[$name] = $value;
  120. return $this;
  121. }
  122. /**
  123. * @param string $name
  124. */
  125. public function getParam($name)
  126. {
  127. return $this->_params[$name];
  128. }
  129. /**
  130. * @param string $value
  131. * @return Zend_Gdata_Query Provides a fluent interface
  132. */
  133. public function setAlt($value)
  134. {
  135. if ($value != null) {
  136. $this->_params['alt'] = $value;
  137. } else {
  138. unset($this->_params['alt']);
  139. }
  140. return $this;
  141. }
  142. /**
  143. * @param int $value
  144. * @return Zend_Gdata_Query Provides a fluent interface
  145. */
  146. public function setMaxResults($value)
  147. {
  148. if ($value != null) {
  149. $this->_params['max-results'] = $value;
  150. } else {
  151. unset($this->_params['max-results']);
  152. }
  153. return $this;
  154. }
  155. /**
  156. * @param string $value
  157. * @return Zend_Gdata_Query Provides a fluent interface
  158. */
  159. public function setQuery($value)
  160. {
  161. if ($value != null) {
  162. $this->_params['q'] = $value;
  163. } else {
  164. unset($this->_params['q']);
  165. }
  166. return $this;
  167. }
  168. /**
  169. * @param int $value
  170. * @return Zend_Gdata_Query Provides a fluent interface
  171. */
  172. public function setStartIndex($value)
  173. {
  174. if ($value != null) {
  175. $this->_params['start-index'] = $value;
  176. } else {
  177. unset($this->_params['start-index']);
  178. }
  179. return $this;
  180. }
  181. /**
  182. * @param string $value
  183. * @return Zend_Gdata_Query Provides a fluent interface
  184. */
  185. public function setUpdatedMax($value)
  186. {
  187. if ($value != null) {
  188. $this->_params['updated-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
  189. } else {
  190. unset($this->_params['updated-max']);
  191. }
  192. return $this;
  193. }
  194. /**
  195. * @param string $value
  196. * @return Zend_Gdata_Query Provides a fluent interface
  197. */
  198. public function setUpdatedMin($value)
  199. {
  200. if ($value != null) {
  201. $this->_params['updated-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
  202. } else {
  203. unset($this->_params['updated-min']);
  204. }
  205. return $this;
  206. }
  207. /**
  208. * @param string $value
  209. * @return Zend_Gdata_Query Provides a fluent interface
  210. */
  211. public function setPublishedMax($value)
  212. {
  213. if ($value !== null) {
  214. $this->_params['published-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
  215. } else {
  216. unset($this->_params['published-max']);
  217. }
  218. return $this;
  219. }
  220. /**
  221. * @param string $value
  222. * @return Zend_Gdata_Query Provides a fluent interface
  223. */
  224. public function setPublishedMin($value)
  225. {
  226. if ($value != null) {
  227. $this->_params['published-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
  228. } else {
  229. unset($this->_params['published-min']);
  230. }
  231. return $this;
  232. }
  233. /**
  234. * @param string $value
  235. * @return Zend_Gdata_Query Provides a fluent interface
  236. */
  237. public function setAuthor($value)
  238. {
  239. if ($value != null) {
  240. $this->_params['author'] = $value;
  241. } else {
  242. unset($this->_params['author']);
  243. }
  244. return $this;
  245. }
  246. /**
  247. * @return string rss or atom
  248. */
  249. public function getAlt()
  250. {
  251. if (array_key_exists('alt', $this->_params)) {
  252. return $this->_params['alt'];
  253. } else {
  254. return null;
  255. }
  256. }
  257. /**
  258. * @return int maxResults
  259. */
  260. public function getMaxResults()
  261. {
  262. if (array_key_exists('max-results', $this->_params)) {
  263. return intval($this->_params['max-results']);
  264. } else {
  265. return null;
  266. }
  267. }
  268. /**
  269. * @return string query
  270. */
  271. public function getQuery()
  272. {
  273. if (array_key_exists('q', $this->_params)) {
  274. return $this->_params['q'];
  275. } else {
  276. return null;
  277. }
  278. }
  279. /**
  280. * @return int startIndex
  281. */
  282. public function getStartIndex()
  283. {
  284. if (array_key_exists('start-index', $this->_params)) {
  285. return intval($this->_params['start-index']);
  286. } else {
  287. return null;
  288. }
  289. }
  290. /**
  291. * @return string updatedMax
  292. */
  293. public function getUpdatedMax()
  294. {
  295. if (array_key_exists('updated-max', $this->_params)) {
  296. return $this->_params['updated-max'];
  297. } else {
  298. return null;
  299. }
  300. }
  301. /**
  302. * @return string updatedMin
  303. */
  304. public function getUpdatedMin()
  305. {
  306. if (array_key_exists('updated-min', $this->_params)) {
  307. return $this->_params['updated-min'];
  308. } else {
  309. return null;
  310. }
  311. }
  312. /**
  313. * @return string publishedMax
  314. */
  315. public function getPublishedMax()
  316. {
  317. if (array_key_exists('published-max', $this->_params)) {
  318. return $this->_params['published-max'];
  319. } else {
  320. return null;
  321. }
  322. }
  323. /**
  324. * @return string publishedMin
  325. */
  326. public function getPublishedMin()
  327. {
  328. if (array_key_exists('published-min', $this->_params)) {
  329. return $this->_params['published-min'];
  330. } else {
  331. return null;
  332. }
  333. }
  334. /**
  335. * @return string author
  336. */
  337. public function getAuthor()
  338. {
  339. if (array_key_exists('author', $this->_params)) {
  340. return $this->_params['author'];
  341. } else {
  342. return null;
  343. }
  344. }
  345. /**
  346. * @param string $value
  347. * @return Zend_Gdata_Query Provides a fluent interface
  348. */
  349. public function setCategory($value)
  350. {
  351. $this->_category = $value;
  352. return $this;
  353. }
  354. /*
  355. * @return string id
  356. */
  357. public function getCategory()
  358. {
  359. return $this->_category;
  360. }
  361. public function __get($name)
  362. {
  363. $method = 'get'.ucfirst($name);
  364. if (method_exists($this, $method)) {
  365. return call_user_func(array(&$this, $method));
  366. } else {
  367. require_once 'Zend/Gdata/App/Exception.php';
  368. throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
  369. }
  370. }
  371. public function __set($name, $val)
  372. {
  373. $method = 'set'.ucfirst($name);
  374. if (method_exists($this, $method)) {
  375. return call_user_func(array(&$this, $method), $val);
  376. } else {
  377. require_once 'Zend/Gdata/App/Exception.php';
  378. throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
  379. }
  380. }
  381. }