source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/Query.php@ 44

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