8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
27 require_once 'Zend/Gdata/App/Util.php';
30 * Provides a mechanism to build a query URL for Gdata services.
31 * Queries are not defined for APP, but are provided by Gdata services
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license http://framework.zend.com/license/new-bsd New BSD License
40 class Zend_Gdata_Query
48 protected $_params = array();
55 protected $_defaultFeedUri = null;
59 * TODO: Add setters and getters
63 protected $_url = null;
66 * Category for the query
70 protected $_category = null;
73 * Create Gdata_Query object
75 public function __construct($url = null)
81 * @return string querystring
83 public function getQueryString()
85 $queryArray = array();
86 foreach ($this->_params
as $name => $value) {
87 if (substr($name, 0, 1) == '_') {
90 $queryArray[] = urlencode($name) . '=' . urlencode($value);
92 if (count($queryArray) > 0) {
93 return '?' . implode('&', $queryArray);
102 public function resetParameters()
104 $this->_params
= array();
110 public function getQueryUrl()
112 if ($this->_url
== null) {
113 $url = $this->_defaultFeedUri
;
117 if ($this->getCategory() !== null) {
118 $url .= '/-/' . $this->getCategory();
120 $url .= $this->getQueryString();
125 * @param string $name
126 * @param string $value
127 * @return Zend_Gdata_Query Provides a fluent interface
129 public function setParam($name, $value)
131 $this->_params
[$name] = $value;
136 * @param string $name
138 public function getParam($name)
140 return $this->_params
[$name];
144 * @param string $value
145 * @return Zend_Gdata_Query Provides a fluent interface
147 public function setAlt($value)
149 if ($value != null) {
150 $this->_params
['alt'] = $value;
152 unset($this->_params
['alt']);
159 * @return Zend_Gdata_Query Provides a fluent interface
161 public function setMaxResults($value)
163 if ($value != null) {
164 $this->_params
['max-results'] = $value;
166 unset($this->_params
['max-results']);
172 * @param string $value
173 * @return Zend_Gdata_Query Provides a fluent interface
175 public function setQuery($value)
177 if ($value != null) {
178 $this->_params
['q'] = $value;
180 unset($this->_params
['q']);
187 * @return Zend_Gdata_Query Provides a fluent interface
189 public function setStartIndex($value)
191 if ($value != null) {
192 $this->_params
['start-index'] = $value;
194 unset($this->_params
['start-index']);
200 * @param string $value
201 * @return Zend_Gdata_Query Provides a fluent interface
203 public function setUpdatedMax($value)
205 if ($value != null) {
206 $this->_params
['updated-max'] = Zend_Gdata_App_Util
::formatTimestamp($value);
208 unset($this->_params
['updated-max']);
214 * @param string $value
215 * @return Zend_Gdata_Query Provides a fluent interface
217 public function setUpdatedMin($value)
219 if ($value != null) {
220 $this->_params
['updated-min'] = Zend_Gdata_App_Util
::formatTimestamp($value);
222 unset($this->_params
['updated-min']);
228 * @param string $value
229 * @return Zend_Gdata_Query Provides a fluent interface
231 public function setPublishedMax($value)
233 if ($value !== null) {
234 $this->_params
['published-max'] = Zend_Gdata_App_Util
::formatTimestamp($value);
236 unset($this->_params
['published-max']);
242 * @param string $value
243 * @return Zend_Gdata_Query Provides a fluent interface
245 public function setPublishedMin($value)
247 if ($value != null) {
248 $this->_params
['published-min'] = Zend_Gdata_App_Util
::formatTimestamp($value);
250 unset($this->_params
['published-min']);
256 * @param string $value
257 * @return Zend_Gdata_Query Provides a fluent interface
259 public function setAuthor($value)
261 if ($value != null) {
262 $this->_params
['author'] = $value;
264 unset($this->_params
['author']);
270 * @return string rss or atom
272 public function getAlt()
274 if (array_key_exists('alt', $this->_params
)) {
275 return $this->_params
['alt'];
282 * @return int maxResults
284 public function getMaxResults()
286 if (array_key_exists('max-results', $this->_params
)) {
287 return intval($this->_params
['max-results']);
294 * @return string query
296 public function getQuery()
298 if (array_key_exists('q', $this->_params
)) {
299 return $this->_params
['q'];
306 * @return int startIndex
308 public function getStartIndex()
310 if (array_key_exists('start-index', $this->_params
)) {
311 return intval($this->_params
['start-index']);
318 * @return string updatedMax
320 public function getUpdatedMax()
322 if (array_key_exists('updated-max', $this->_params
)) {
323 return $this->_params
['updated-max'];
330 * @return string updatedMin
332 public function getUpdatedMin()
334 if (array_key_exists('updated-min', $this->_params
)) {
335 return $this->_params
['updated-min'];
342 * @return string publishedMax
344 public function getPublishedMax()
346 if (array_key_exists('published-max', $this->_params
)) {
347 return $this->_params
['published-max'];
354 * @return string publishedMin
356 public function getPublishedMin()
358 if (array_key_exists('published-min', $this->_params
)) {
359 return $this->_params
['published-min'];
366 * @return string author
368 public function getAuthor()
370 if (array_key_exists('author', $this->_params
)) {
371 return $this->_params
['author'];
378 * @param string $value
379 * @return Zend_Gdata_Query Provides a fluent interface
381 public function setCategory($value)
383 $this->_category
= $value;
390 public function getCategory()
392 return $this->_category
;
396 public function __get($name)
398 $method = 'get'.ucfirst($name);
399 if (method_exists($this, $method)) {
400 return call_user_func(array(&$this, $method));
402 require_once 'Zend/Gdata/App/Exception.php';
403 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
407 public function __set($name, $val)
409 $method = 'set'.ucfirst($name);
410 if (method_exists($this, $method)) {
411 return call_user_func(array(&$this, $method), $val);
413 require_once 'Zend/Gdata/App/Exception.php';
414 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');