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