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