[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Gdata / Query.php
blob2b35357fa05e5df88d4d9ef47554253f33946353
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-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id$
24 /**
25 * Zend_Gdata_App_Util
27 require_once 'Zend/Gdata/App/Util.php';
29 /**
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
32 * as an extension.
34 * @category Zend
35 * @package Zend_Gdata
36 * @subpackage Gdata
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
43 /**
44 * Query parameters.
46 * @var array
48 protected $_params = array();
50 /**
51 * Default URL
53 * @var string
55 protected $_defaultFeedUri = null;
57 /**
58 * Base URL
59 * TODO: Add setters and getters
61 * @var string
63 protected $_url = null;
65 /**
66 * Category for the query
68 * @var string
70 protected $_category = null;
72 /**
73 * Create Gdata_Query object
75 public function __construct($url = null)
77 $this->_url = $url;
80 /**
81 * @return string querystring
83 public function getQueryString()
85 $queryArray = array();
86 foreach ($this->_params as $name => $value) {
87 if (substr($name, 0, 1) == '_') {
88 continue;
90 $queryArray[] = urlencode($name) . '=' . urlencode($value);
92 if (count($queryArray) > 0) {
93 return '?' . implode('&', $queryArray);
94 } else {
95 return '';
99 /**
102 public function resetParameters()
104 $this->_params = array();
108 * @return string url
110 public function getQueryUrl()
112 if ($this->_url == null) {
113 $url = $this->_defaultFeedUri;
114 } else {
115 $url = $this->_url;
117 if ($this->getCategory() !== null) {
118 $url .= '/-/' . $this->getCategory();
120 $url .= $this->getQueryString();
121 return $url;
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;
132 return $this;
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;
151 } else {
152 unset($this->_params['alt']);
154 return $this;
158 * @param int $value
159 * @return Zend_Gdata_Query Provides a fluent interface
161 public function setMaxResults($value)
163 if ($value != null) {
164 $this->_params['max-results'] = $value;
165 } else {
166 unset($this->_params['max-results']);
168 return $this;
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;
179 } else {
180 unset($this->_params['q']);
182 return $this;
186 * @param int $value
187 * @return Zend_Gdata_Query Provides a fluent interface
189 public function setStartIndex($value)
191 if ($value != null) {
192 $this->_params['start-index'] = $value;
193 } else {
194 unset($this->_params['start-index']);
196 return $this;
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);
207 } else {
208 unset($this->_params['updated-max']);
210 return $this;
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);
221 } else {
222 unset($this->_params['updated-min']);
224 return $this;
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);
235 } else {
236 unset($this->_params['published-max']);
238 return $this;
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);
249 } else {
250 unset($this->_params['published-min']);
252 return $this;
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;
263 } else {
264 unset($this->_params['author']);
266 return $this;
270 * @return string rss or atom
272 public function getAlt()
274 if (array_key_exists('alt', $this->_params)) {
275 return $this->_params['alt'];
276 } else {
277 return null;
282 * @return int maxResults
284 public function getMaxResults()
286 if (array_key_exists('max-results', $this->_params)) {
287 return intval($this->_params['max-results']);
288 } else {
289 return null;
294 * @return string query
296 public function getQuery()
298 if (array_key_exists('q', $this->_params)) {
299 return $this->_params['q'];
300 } else {
301 return null;
306 * @return int startIndex
308 public function getStartIndex()
310 if (array_key_exists('start-index', $this->_params)) {
311 return intval($this->_params['start-index']);
312 } else {
313 return null;
318 * @return string updatedMax
320 public function getUpdatedMax()
322 if (array_key_exists('updated-max', $this->_params)) {
323 return $this->_params['updated-max'];
324 } else {
325 return null;
330 * @return string updatedMin
332 public function getUpdatedMin()
334 if (array_key_exists('updated-min', $this->_params)) {
335 return $this->_params['updated-min'];
336 } else {
337 return null;
342 * @return string publishedMax
344 public function getPublishedMax()
346 if (array_key_exists('published-max', $this->_params)) {
347 return $this->_params['published-max'];
348 } else {
349 return null;
354 * @return string publishedMin
356 public function getPublishedMin()
358 if (array_key_exists('published-min', $this->_params)) {
359 return $this->_params['published-min'];
360 } else {
361 return null;
366 * @return string author
368 public function getAuthor()
370 if (array_key_exists('author', $this->_params)) {
371 return $this->_params['author'];
372 } else {
373 return null;
378 * @param string $value
379 * @return Zend_Gdata_Query Provides a fluent interface
381 public function setCategory($value)
383 $this->_category = $value;
384 return $this;
388 * @return string id
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));
401 } else {
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);
412 } else {
413 require_once 'Zend/Gdata/App/Exception.php';
414 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');