[ZF-6295] Generic:
[zend.git] / library / Zend / Gdata / Query.php
blob43988f5a44be36a14c89f304a886e58924790057
1 <?php
3 /**
4 * Zend Framework
6 * LICENSE
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.
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage Gdata
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
23 /**
24 * Zend_Gdata_App_Util
26 require_once 'Zend/Gdata/App/Util.php';
28 /**
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
31 * as an extension.
33 * @category Zend
34 * @package Zend_Gdata
35 * @subpackage Gdata
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
42 /**
43 * Query parameters.
45 * @var array
47 protected $_params = array();
49 /**
50 * Default URL
52 * @var string
54 protected $_defaultFeedUri = null;
56 /**
57 * Base URL
58 * TODO: Add setters and getters
60 * @var string
62 protected $_url = null;
64 /**
65 * Category for the query
67 * @var string
69 protected $_category = null;
71 /**
72 * Create Gdata_Query object
74 public function __construct($url = null)
76 $this->_url = $url;
79 /**
80 * @return string querystring
82 public function getQueryString()
84 $queryArray = array();
85 foreach ($this->_params as $name => $value) {
86 if (substr($name, 0, 1) == '_') {
87 continue;
89 $queryArray[] = urlencode($name) . '=' . urlencode($value);
91 if (count($queryArray) > 0) {
92 return '?' . implode('&', $queryArray);
93 } else {
94 return '';
98 /**
101 public function resetParameters()
103 $this->_params = array();
107 * @return string url
109 public function getQueryUrl()
111 if ($this->_url == null) {
112 $url = $this->_defaultFeedUri;
113 } else {
114 $url = $this->_url;
116 if ($this->getCategory() !== null) {
117 $url .= '/-/' . $this->getCategory();
119 $url .= $this->getQueryString();
120 return $url;
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;
131 return $this;
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;
150 } else {
151 unset($this->_params['alt']);
153 return $this;
157 * @param int $value
158 * @return Zend_Gdata_Query Provides a fluent interface
160 public function setMaxResults($value)
162 if ($value != null) {
163 $this->_params['max-results'] = $value;
164 } else {
165 unset($this->_params['max-results']);
167 return $this;
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;
178 } else {
179 unset($this->_params['q']);
181 return $this;
185 * @param int $value
186 * @return Zend_Gdata_Query Provides a fluent interface
188 public function setStartIndex($value)
190 if ($value != null) {
191 $this->_params['start-index'] = $value;
192 } else {
193 unset($this->_params['start-index']);
195 return $this;
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);
206 } else {
207 unset($this->_params['updated-max']);
209 return $this;
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);
220 } else {
221 unset($this->_params['updated-min']);
223 return $this;
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);
234 } else {
235 unset($this->_params['published-max']);
237 return $this;
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);
248 } else {
249 unset($this->_params['published-min']);
251 return $this;
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;
262 } else {
263 unset($this->_params['author']);
265 return $this;
269 * @return string rss or atom
271 public function getAlt()
273 if (array_key_exists('alt', $this->_params)) {
274 return $this->_params['alt'];
275 } else {
276 return null;
281 * @return int maxResults
283 public function getMaxResults()
285 if (array_key_exists('max-results', $this->_params)) {
286 return intval($this->_params['max-results']);
287 } else {
288 return null;
293 * @return string query
295 public function getQuery()
297 if (array_key_exists('q', $this->_params)) {
298 return $this->_params['q'];
299 } else {
300 return null;
305 * @return int startIndex
307 public function getStartIndex()
309 if (array_key_exists('start-index', $this->_params)) {
310 return intval($this->_params['start-index']);
311 } else {
312 return null;
317 * @return string updatedMax
319 public function getUpdatedMax()
321 if (array_key_exists('updated-max', $this->_params)) {
322 return $this->_params['updated-max'];
323 } else {
324 return null;
329 * @return string updatedMin
331 public function getUpdatedMin()
333 if (array_key_exists('updated-min', $this->_params)) {
334 return $this->_params['updated-min'];
335 } else {
336 return null;
341 * @return string publishedMax
343 public function getPublishedMax()
345 if (array_key_exists('published-max', $this->_params)) {
346 return $this->_params['published-max'];
347 } else {
348 return null;
353 * @return string publishedMin
355 public function getPublishedMin()
357 if (array_key_exists('published-min', $this->_params)) {
358 return $this->_params['published-min'];
359 } else {
360 return null;
365 * @return string author
367 public function getAuthor()
369 if (array_key_exists('author', $this->_params)) {
370 return $this->_params['author'];
371 } else {
372 return null;
377 * @param string $value
378 * @return Zend_Gdata_Query Provides a fluent interface
380 public function setCategory($value)
382 $this->_category = $value;
383 return $this;
387 * @return string id
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));
400 } else {
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);
411 } else {
412 require_once 'Zend/Gdata/App/Exception.php';
413 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');