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-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
26 require_once 'Zend/Gdata/App/Util.php';
29 * Provides a mechanism to build a query URL for Gdata services.
30 * Queries are not defined for APP, but are provided by Gdata services
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_Gdata_Query
47 protected $_params = array();
54 protected $_defaultFeedUri = null;
58 * TODO: Add setters and getters
62 protected $_url = null;
65 * Category for the query
69 protected $_category = null;
72 * Create Gdata_Query object
74 public function __construct($url = null)
80 * @return string querystring
82 public function getQueryString()
84 $queryArray = array();
85 foreach ($this->_params
as $name => $value) {
86 if (substr($name, 0, 1) == '_') {
89 $queryArray[] = urlencode($name) . '=' . urlencode($value);
91 if (count($queryArray) > 0) {
92 return '?' . implode('&', $queryArray);
101 public function resetParameters()
103 $this->_params
= array();
109 public function getQueryUrl()
111 if ($this->_url
== null) {
112 $url = $this->_defaultFeedUri
;
116 if ($this->getCategory() !== null) {
117 $url .= '/-/' . $this->getCategory();
119 $url .= $this->getQueryString();
124 * @param string $name
125 * @param string $value
126 * @return Zend_Gdata_Query Provides a fluent interface
128 public function setParam($name, $value)
130 $this->_params
[$name] = $value;
135 * @param string $name
137 public function getParam($name)
139 return $this->_params
[$name];
143 * @param string $value
144 * @return Zend_Gdata_Query Provides a fluent interface
146 public function setAlt($value)
148 if ($value != null) {
149 $this->_params
['alt'] = $value;
151 unset($this->_params
['alt']);
158 * @return Zend_Gdata_Query Provides a fluent interface
160 public function setMaxResults($value)
162 if ($value != null) {
163 $this->_params
['max-results'] = $value;
165 unset($this->_params
['max-results']);
171 * @param string $value
172 * @return Zend_Gdata_Query Provides a fluent interface
174 public function setQuery($value)
176 if ($value != null) {
177 $this->_params
['q'] = $value;
179 unset($this->_params
['q']);
186 * @return Zend_Gdata_Query Provides a fluent interface
188 public function setStartIndex($value)
190 if ($value != null) {
191 $this->_params
['start-index'] = $value;
193 unset($this->_params
['start-index']);
199 * @param string $value
200 * @return Zend_Gdata_Query Provides a fluent interface
202 public function setUpdatedMax($value)
204 if ($value != null) {
205 $this->_params
['updated-max'] = Zend_Gdata_App_Util
::formatTimestamp($value);
207 unset($this->_params
['updated-max']);
213 * @param string $value
214 * @return Zend_Gdata_Query Provides a fluent interface
216 public function setUpdatedMin($value)
218 if ($value != null) {
219 $this->_params
['updated-min'] = Zend_Gdata_App_Util
::formatTimestamp($value);
221 unset($this->_params
['updated-min']);
227 * @param string $value
228 * @return Zend_Gdata_Query Provides a fluent interface
230 public function setPublishedMax($value)
232 if ($value !== null) {
233 $this->_params
['published-max'] = Zend_Gdata_App_Util
::formatTimestamp($value);
235 unset($this->_params
['published-max']);
241 * @param string $value
242 * @return Zend_Gdata_Query Provides a fluent interface
244 public function setPublishedMin($value)
246 if ($value != null) {
247 $this->_params
['published-min'] = Zend_Gdata_App_Util
::formatTimestamp($value);
249 unset($this->_params
['published-min']);
255 * @param string $value
256 * @return Zend_Gdata_Query Provides a fluent interface
258 public function setAuthor($value)
260 if ($value != null) {
261 $this->_params
['author'] = $value;
263 unset($this->_params
['author']);
269 * @return string rss or atom
271 public function getAlt()
273 if (array_key_exists('alt', $this->_params
)) {
274 return $this->_params
['alt'];
281 * @return int maxResults
283 public function getMaxResults()
285 if (array_key_exists('max-results', $this->_params
)) {
286 return intval($this->_params
['max-results']);
293 * @return string query
295 public function getQuery()
297 if (array_key_exists('q', $this->_params
)) {
298 return $this->_params
['q'];
305 * @return int startIndex
307 public function getStartIndex()
309 if (array_key_exists('start-index', $this->_params
)) {
310 return intval($this->_params
['start-index']);
317 * @return string updatedMax
319 public function getUpdatedMax()
321 if (array_key_exists('updated-max', $this->_params
)) {
322 return $this->_params
['updated-max'];
329 * @return string updatedMin
331 public function getUpdatedMin()
333 if (array_key_exists('updated-min', $this->_params
)) {
334 return $this->_params
['updated-min'];
341 * @return string publishedMax
343 public function getPublishedMax()
345 if (array_key_exists('published-max', $this->_params
)) {
346 return $this->_params
['published-max'];
353 * @return string publishedMin
355 public function getPublishedMin()
357 if (array_key_exists('published-min', $this->_params
)) {
358 return $this->_params
['published-min'];
365 * @return string author
367 public function getAuthor()
369 if (array_key_exists('author', $this->_params
)) {
370 return $this->_params
['author'];
377 * @param string $value
378 * @return Zend_Gdata_Query Provides a fluent interface
380 public function setCategory($value)
382 $this->_category
= $value;
389 public function getCategory()
391 return $this->_category
;
395 public function __get($name)
397 $method = 'get'.ucfirst($name);
398 if (method_exists($this, $method)) {
399 return call_user_func(array(&$this, $method));
401 require_once 'Zend/Gdata/App/Exception.php';
402 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
406 public function __set($name, $val)
408 $method = 'set'.ucfirst($name);
409 if (method_exists($this, $method)) {
410 return call_user_func(array(&$this, $method), $val);
412 require_once 'Zend/Gdata/App/Exception.php';
413 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');