|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service |
|
17 * @subpackage DeveloperGarden |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: SearchParameters.php 22662 2010-07-24 17:37:36Z mabe $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @category Zend |
|
25 * @package Zend_Service |
|
26 * @subpackage DeveloperGarden |
|
27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
28 * @author Marco Kaiser |
|
29 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
30 */ |
|
31 class Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
32 { |
|
33 /** |
|
34 * possible search parameters, incl. default values |
|
35 * |
|
36 * @var array |
|
37 */ |
|
38 private $_parameters = array( |
|
39 'what' => null, |
|
40 'dymwhat' => null, |
|
41 'dymrelated' => null, |
|
42 'hits' => null, |
|
43 'collapse' => null, |
|
44 'where' => null, |
|
45 'dywhere' => null, |
|
46 'radius' => null, |
|
47 'lx' => null, |
|
48 'ly' => null, |
|
49 'rx' => null, |
|
50 'ry' => null, |
|
51 'transformgeocode' => null, |
|
52 'sort' => null, |
|
53 'spatial' => null, |
|
54 'sepcomm' => null, |
|
55 'filter' => null, // can be ONLINER or OFFLINER |
|
56 'openingtime' => null, // can be now or HH::MM |
|
57 'kategorie' => null, // @see http://www.suchen.de/kategorie-katalog |
|
58 'site' => null, |
|
59 'typ' => null, |
|
60 'name' => null, |
|
61 'page' => null, |
|
62 'city' => null, |
|
63 'plz' => null, |
|
64 'strasse' => null, |
|
65 'bundesland' => null, |
|
66 ); |
|
67 |
|
68 /** |
|
69 * possible collapse values |
|
70 * |
|
71 * @var array |
|
72 */ |
|
73 private $_possibleCollapseValues = array( |
|
74 true, |
|
75 false, |
|
76 'ADDRESS_COMPANY', |
|
77 'DOMAIN' |
|
78 ); |
|
79 |
|
80 /** |
|
81 * sets a new search word |
|
82 * alias for setWhat |
|
83 * |
|
84 * @param string $searchValue |
|
85 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
86 */ |
|
87 public function setSearchValue($searchValue) |
|
88 { |
|
89 return $this->setWhat($searchValue); |
|
90 } |
|
91 |
|
92 /** |
|
93 * sets a new search word |
|
94 * |
|
95 * @param string $searchValue |
|
96 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
97 */ |
|
98 public function setWhat($searchValue) |
|
99 { |
|
100 $this->_parameters['what'] = $searchValue; |
|
101 return $this; |
|
102 } |
|
103 |
|
104 /** |
|
105 * enable the did you mean what feature |
|
106 * |
|
107 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
108 */ |
|
109 public function enableDidYouMeanWhat() |
|
110 { |
|
111 $this->_parameters['dymwhat'] = 'true'; |
|
112 return $this; |
|
113 } |
|
114 |
|
115 /** |
|
116 * disable the did you mean what feature |
|
117 * |
|
118 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
119 */ |
|
120 public function disableDidYouMeanWhat() |
|
121 { |
|
122 $this->_parameters['dymwhat'] = 'false'; |
|
123 return $this; |
|
124 } |
|
125 |
|
126 /** |
|
127 * enable the did you mean where feature |
|
128 * |
|
129 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
130 */ |
|
131 public function enableDidYouMeanWhere() |
|
132 { |
|
133 $this->_parameters['dymwhere'] = 'true'; |
|
134 return $this; |
|
135 } |
|
136 |
|
137 /** |
|
138 * disable the did you mean where feature |
|
139 * |
|
140 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
141 */ |
|
142 public function disableDidYouMeanWhere() |
|
143 { |
|
144 $this->_parameters['dymwhere'] = 'false'; |
|
145 return $this; |
|
146 } |
|
147 |
|
148 /** |
|
149 * enable did you mean related, if true Kihno will be corrected to Kino |
|
150 * |
|
151 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
152 */ |
|
153 public function enableDidYouMeanRelated() |
|
154 { |
|
155 $this->_parameters['dymrelated'] = 'true'; |
|
156 return $this; |
|
157 } |
|
158 |
|
159 /** |
|
160 * diable did you mean related, if false Kihno will not be corrected to Kino |
|
161 * |
|
162 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
163 */ |
|
164 public function disableDidYouMeanRelated() |
|
165 { |
|
166 $this->_parameters['dymrelated'] = 'true'; |
|
167 return $this; |
|
168 } |
|
169 |
|
170 /** |
|
171 * set the max result hits for this search |
|
172 * |
|
173 * @param integer $hits |
|
174 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
175 */ |
|
176 public function setHits($hits = 10) |
|
177 { |
|
178 require_once 'Zend/Validate/Between.php'; |
|
179 $validator = new Zend_Validate_Between(0, 1000); |
|
180 if (!$validator->isValid($hits)) { |
|
181 $message = $validator->getMessages(); |
|
182 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; |
|
183 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); |
|
184 } |
|
185 $this->_parameters['hits'] = $hits; |
|
186 return $this; |
|
187 } |
|
188 |
|
189 /** |
|
190 * If true, addresses will be collapsed for a single domain, common values |
|
191 * are: |
|
192 * ADDRESS_COMPANY – to collapse by address |
|
193 * DOMAIN – to collapse by domain (same like collapse=true) |
|
194 * false |
|
195 * |
|
196 * @param mixed $value |
|
197 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
198 */ |
|
199 public function setCollapse($value) |
|
200 { |
|
201 if (!in_array($value, $this->_possibleCollapseValues, true)) { |
|
202 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; |
|
203 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception('Not a valid value provided.'); |
|
204 } |
|
205 $this->_parameters['collapse'] = $value; |
|
206 return $this; |
|
207 } |
|
208 |
|
209 /** |
|
210 * set a specific search location |
|
211 * examples: |
|
212 * +47°54’53.10”, 11° 10’ 56.76” |
|
213 * 47°54’53.10;11°10’56.76” |
|
214 * 47.914750,11.182533 |
|
215 * +47.914750 ; +11.1824 |
|
216 * Darmstadt |
|
217 * Berlin |
|
218 * |
|
219 * @param string $where |
|
220 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
221 */ |
|
222 public function setWhere($where) |
|
223 { |
|
224 require_once 'Zend/Validate/NotEmpty.php'; |
|
225 |
|
226 $validator = new Zend_Validate_NotEmpty(); |
|
227 if (!$validator->isValid($where)) { |
|
228 $message = $validator->getMessages(); |
|
229 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; |
|
230 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); |
|
231 } |
|
232 $this->_parameters['where'] = $where; |
|
233 return $this; |
|
234 } |
|
235 |
|
236 /** |
|
237 * returns the defined search location (ie city, country) |
|
238 * |
|
239 * @return string |
|
240 */ |
|
241 public function getWhere() |
|
242 { |
|
243 return $this->_parameters['where']; |
|
244 } |
|
245 |
|
246 /** |
|
247 * enable the spatial search feature |
|
248 * |
|
249 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
250 */ |
|
251 public function enableSpatial() |
|
252 { |
|
253 $this->_parameters['spatial'] = 'true'; |
|
254 return $this; |
|
255 } |
|
256 |
|
257 /** |
|
258 * disable the spatial search feature |
|
259 * |
|
260 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
261 */ |
|
262 public function disableSpatial() |
|
263 { |
|
264 $this->_parameters['spatial'] = 'false'; |
|
265 return $this; |
|
266 } |
|
267 |
|
268 /** |
|
269 * sets spatial and the given radius for a circle search |
|
270 * |
|
271 * @param integer $radius |
|
272 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
273 */ |
|
274 public function setRadius($radius) |
|
275 { |
|
276 require_once 'Zend/Validate/Int.php'; |
|
277 |
|
278 $validator = new Zend_Validate_Int(); |
|
279 if (!$validator->isValid($radius)) { |
|
280 $message = $validator->getMessages(); |
|
281 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; |
|
282 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); |
|
283 } |
|
284 $this->_parameters['radius'] = $radius; |
|
285 $this->_parameters['transformgeocode'] = 'false'; |
|
286 |
|
287 return $this; |
|
288 } |
|
289 |
|
290 /** |
|
291 * sets the values for a rectangle search |
|
292 * lx = longitude left top |
|
293 * ly = latitude left top |
|
294 * rx = longitude right bottom |
|
295 * ry = latitude right bottom |
|
296 * |
|
297 * @param $lx |
|
298 * @param $ly |
|
299 * @param $rx |
|
300 * @param $ry |
|
301 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
302 */ |
|
303 public function setRectangle($lx, $ly, $rx, $ry) |
|
304 { |
|
305 $this->_parameters['lx'] = $lx; |
|
306 $this->_parameters['ly'] = $ly; |
|
307 $this->_parameters['rx'] = $rx; |
|
308 $this->_parameters['ry'] = $ry; |
|
309 |
|
310 return $this; |
|
311 } |
|
312 |
|
313 /** |
|
314 * if set, the service returns the zipcode for the result |
|
315 * |
|
316 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
317 */ |
|
318 public function setTransformGeoCode() |
|
319 { |
|
320 $this->_parameters['transformgeocode'] = 'true'; |
|
321 $this->_parameters['radius'] = null; |
|
322 |
|
323 return $this; |
|
324 } |
|
325 |
|
326 /** |
|
327 * sets the sort value |
|
328 * possible values are: 'relevance' and 'distance' (only with spatial enabled) |
|
329 * |
|
330 * @param string $sort |
|
331 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
332 */ |
|
333 public function setSort($sort) |
|
334 { |
|
335 if (!in_array($sort, array('relevance', 'distance'))) { |
|
336 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; |
|
337 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception('Not a valid sort value provided.'); |
|
338 } |
|
339 |
|
340 $this->_parameters['sort'] = $sort; |
|
341 return $this; |
|
342 } |
|
343 |
|
344 /** |
|
345 * enable the separation of phone numbers |
|
346 * |
|
347 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
348 */ |
|
349 public function enablePhoneSeparation() |
|
350 { |
|
351 $this->_parameters['sepcomm'] = 'true'; |
|
352 return $this; |
|
353 } |
|
354 |
|
355 /** |
|
356 * disable the separation of phone numbers |
|
357 * |
|
358 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
359 */ |
|
360 public function disablePhoneSeparation() |
|
361 { |
|
362 $this->_parameters['sepcomm'] = 'true'; |
|
363 return $this; |
|
364 } |
|
365 |
|
366 /** |
|
367 * if this filter is set, only results with a website are returned |
|
368 * |
|
369 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
370 */ |
|
371 public function setFilterOnliner() |
|
372 { |
|
373 $this->_parameters['filter'] = 'ONLINER'; |
|
374 return $this; |
|
375 } |
|
376 |
|
377 /** |
|
378 * if this filter is set, only results without a website are returned |
|
379 * |
|
380 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
381 */ |
|
382 public function setFilterOffliner() |
|
383 { |
|
384 $this->_parameters['filter'] = 'OFFLINER'; |
|
385 return $this; |
|
386 } |
|
387 |
|
388 |
|
389 /** |
|
390 * removes the filter value |
|
391 * |
|
392 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
393 */ |
|
394 public function disableFilter() |
|
395 { |
|
396 $this->_parameters['filter'] = null; |
|
397 return $this; |
|
398 } |
|
399 |
|
400 /** |
|
401 * set a filter to get just results who are open at the given time |
|
402 * possible values: |
|
403 * now = open right now |
|
404 * HH:MM = at the given time (ie 20:00) |
|
405 * |
|
406 * @param string $time |
|
407 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
408 */ |
|
409 public function setOpeningTime($time = null) |
|
410 { |
|
411 $this->_parameters['openingtime'] = $time; |
|
412 return $this; |
|
413 } |
|
414 |
|
415 /** |
|
416 * sets a category filter |
|
417 * |
|
418 * @see http://www.suchen.de/kategorie-katalog |
|
419 * @param $category |
|
420 * @return unknown_type |
|
421 */ |
|
422 public function setCategory($category = null) |
|
423 { |
|
424 $this->_parameters['kategorie'] = $category; |
|
425 return $this; |
|
426 } |
|
427 |
|
428 /** |
|
429 * sets the site filter |
|
430 * ie: www.developergarden.com |
|
431 * |
|
432 * @param string $site |
|
433 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
434 */ |
|
435 public function setSite($site) |
|
436 { |
|
437 $this->_parameters['site'] = $site; |
|
438 return $this; |
|
439 } |
|
440 |
|
441 /** |
|
442 * sets a filter to the given document type |
|
443 * ie: pdf, html |
|
444 * |
|
445 * @param string $type |
|
446 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
447 */ |
|
448 public function setDocumentType($type) |
|
449 { |
|
450 $this->_parameters['typ'] = $type; |
|
451 return $this; |
|
452 } |
|
453 |
|
454 /** |
|
455 * sets a filter for the company name |
|
456 * ie: Deutsche Telekom |
|
457 * |
|
458 * @param string $name |
|
459 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
460 */ |
|
461 public function setName($name) |
|
462 { |
|
463 $this->_parameters['name'] = $name; |
|
464 return $this; |
|
465 } |
|
466 |
|
467 /** |
|
468 * sets a filter for the zip code |
|
469 * |
|
470 * @param string $zip |
|
471 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
472 */ |
|
473 public function setZipCode($zip) |
|
474 { |
|
475 $this->_parameters['plz'] = $zip; |
|
476 return $this; |
|
477 } |
|
478 |
|
479 /** |
|
480 * sets a filter for the street |
|
481 * |
|
482 * @param string $street |
|
483 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
484 */ |
|
485 public function setStreet($street) |
|
486 { |
|
487 $this->_parameters['strasse'] = $street; |
|
488 return $this; |
|
489 } |
|
490 |
|
491 /** |
|
492 * sets a filter for the county |
|
493 * |
|
494 * @param string $county |
|
495 * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters |
|
496 */ |
|
497 public function setCounty($county) |
|
498 { |
|
499 $this->_parameters['bundesland'] = $county; |
|
500 return $this; |
|
501 } |
|
502 |
|
503 /** |
|
504 * sets a raw parameter with the value |
|
505 * |
|
506 * @param string $key |
|
507 * @param mixed $value |
|
508 * @return unknown_type |
|
509 */ |
|
510 public function setRawParameter($key, $value) |
|
511 { |
|
512 $this->_parameters[$key] = $value; |
|
513 return $this; |
|
514 } |
|
515 |
|
516 /** |
|
517 * returns the parameters as an array |
|
518 * |
|
519 * @return array |
|
520 */ |
|
521 public function getSearchParameters() |
|
522 { |
|
523 $retVal = array(); |
|
524 foreach ($this->_parameters as $key => $value) { |
|
525 if ($value === null) { |
|
526 continue; |
|
527 } |
|
528 $param = array( |
|
529 'parameter' => $key, |
|
530 'value' => $value |
|
531 ); |
|
532 $retVal[] = $param; |
|
533 } |
|
534 return $retVal; |
|
535 } |
|
536 } |