|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00031 class Zend_Service_DeveloperGarden_LocalSearch_SearchParameters 00032 { 00038 private $_parameters = array( 00039 'what' => null, 00040 'dymwhat' => null, 00041 'dymrelated' => null, 00042 'hits' => null, 00043 'collapse' => null, 00044 'where' => null, 00045 'dywhere' => null, 00046 'radius' => null, 00047 'lx' => null, 00048 'ly' => null, 00049 'rx' => null, 00050 'ry' => null, 00051 'transformgeocode' => null, 00052 'sort' => null, 00053 'spatial' => null, 00054 'sepcomm' => null, 00055 'filter' => null, // can be ONLINER or OFFLINER 00056 'openingtime' => null, // can be now or HH::MM 00057 'kategorie' => null, // @see http://www.suchen.de/kategorie-katalog 00058 'site' => null, 00059 'typ' => null, 00060 'name' => null, 00061 'page' => null, 00062 'city' => null, 00063 'plz' => null, 00064 'strasse' => null, 00065 'bundesland' => null, 00066 ); 00067 00073 private $_possibleCollapseValues = array( 00074 true, 00075 false, 00076 'ADDRESS_COMPANY', 00077 'DOMAIN' 00078 ); 00079 00087 public function setSearchValue($searchValue) 00088 { 00089 return $this->setWhat($searchValue); 00090 } 00091 00098 public function setWhat($searchValue) 00099 { 00100 $this->_parameters['what'] = $searchValue; 00101 return $this; 00102 } 00103 00109 public function enableDidYouMeanWhat() 00110 { 00111 $this->_parameters['dymwhat'] = 'true'; 00112 return $this; 00113 } 00114 00120 public function disableDidYouMeanWhat() 00121 { 00122 $this->_parameters['dymwhat'] = 'false'; 00123 return $this; 00124 } 00125 00131 public function enableDidYouMeanWhere() 00132 { 00133 $this->_parameters['dymwhere'] = 'true'; 00134 return $this; 00135 } 00136 00142 public function disableDidYouMeanWhere() 00143 { 00144 $this->_parameters['dymwhere'] = 'false'; 00145 return $this; 00146 } 00147 00153 public function enableDidYouMeanRelated() 00154 { 00155 $this->_parameters['dymrelated'] = 'true'; 00156 return $this; 00157 } 00158 00164 public function disableDidYouMeanRelated() 00165 { 00166 $this->_parameters['dymrelated'] = 'true'; 00167 return $this; 00168 } 00169 00176 public function setHits($hits = 10) 00177 { 00178 require_once 'Zend/Validate/Between.php'; 00179 $validator = new Zend_Validate_Between(0, 1000); 00180 if (!$validator->isValid($hits)) { 00181 $message = $validator->getMessages(); 00182 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; 00183 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); 00184 } 00185 $this->_parameters['hits'] = $hits; 00186 return $this; 00187 } 00188 00199 public function setCollapse($value) 00200 { 00201 if (!in_array($value, $this->_possibleCollapseValues, true)) { 00202 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; 00203 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception('Not a valid value provided.'); 00204 } 00205 $this->_parameters['collapse'] = $value; 00206 return $this; 00207 } 00208 00222 public function setWhere($where) 00223 { 00224 require_once 'Zend/Validate/NotEmpty.php'; 00225 00226 $validator = new Zend_Validate_NotEmpty(); 00227 if (!$validator->isValid($where)) { 00228 $message = $validator->getMessages(); 00229 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; 00230 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); 00231 } 00232 $this->_parameters['where'] = $where; 00233 return $this; 00234 } 00235 00241 public function getWhere() 00242 { 00243 return $this->_parameters['where']; 00244 } 00245 00251 public function enableSpatial() 00252 { 00253 $this->_parameters['spatial'] = 'true'; 00254 return $this; 00255 } 00256 00262 public function disableSpatial() 00263 { 00264 $this->_parameters['spatial'] = 'false'; 00265 return $this; 00266 } 00267 00274 public function setRadius($radius) 00275 { 00276 require_once 'Zend/Validate/Int.php'; 00277 00278 $validator = new Zend_Validate_Int(); 00279 if (!$validator->isValid($radius)) { 00280 $message = $validator->getMessages(); 00281 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; 00282 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); 00283 } 00284 $this->_parameters['radius'] = $radius; 00285 $this->_parameters['transformgeocode'] = 'false'; 00286 00287 return $this; 00288 } 00289 00303 public function setRectangle($lx, $ly, $rx, $ry) 00304 { 00305 $this->_parameters['lx'] = $lx; 00306 $this->_parameters['ly'] = $ly; 00307 $this->_parameters['rx'] = $rx; 00308 $this->_parameters['ry'] = $ry; 00309 00310 return $this; 00311 } 00312 00318 public function setTransformGeoCode() 00319 { 00320 $this->_parameters['transformgeocode'] = 'true'; 00321 $this->_parameters['radius'] = null; 00322 00323 return $this; 00324 } 00325 00333 public function setSort($sort) 00334 { 00335 if (!in_array($sort, array('relevance', 'distance'))) { 00336 require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; 00337 throw new Zend_Service_DeveloperGarden_LocalSearch_Exception('Not a valid sort value provided.'); 00338 } 00339 00340 $this->_parameters['sort'] = $sort; 00341 return $this; 00342 } 00343 00349 public function enablePhoneSeparation() 00350 { 00351 $this->_parameters['sepcomm'] = 'true'; 00352 return $this; 00353 } 00354 00360 public function disablePhoneSeparation() 00361 { 00362 $this->_parameters['sepcomm'] = 'true'; 00363 return $this; 00364 } 00365 00371 public function setFilterOnliner() 00372 { 00373 $this->_parameters['filter'] = 'ONLINER'; 00374 return $this; 00375 } 00376 00382 public function setFilterOffliner() 00383 { 00384 $this->_parameters['filter'] = 'OFFLINER'; 00385 return $this; 00386 } 00387 00388 00394 public function disableFilter() 00395 { 00396 $this->_parameters['filter'] = null; 00397 return $this; 00398 } 00399 00409 public function setOpeningTime($time = null) 00410 { 00411 $this->_parameters['openingtime'] = $time; 00412 return $this; 00413 } 00414 00422 public function setCategory($category = null) 00423 { 00424 $this->_parameters['kategorie'] = $category; 00425 return $this; 00426 } 00427 00435 public function setSite($site) 00436 { 00437 $this->_parameters['site'] = $site; 00438 return $this; 00439 } 00440 00448 public function setDocumentType($type) 00449 { 00450 $this->_parameters['typ'] = $type; 00451 return $this; 00452 } 00453 00461 public function setName($name) 00462 { 00463 $this->_parameters['name'] = $name; 00464 return $this; 00465 } 00466 00473 public function setZipCode($zip) 00474 { 00475 $this->_parameters['plz'] = $zip; 00476 return $this; 00477 } 00478 00485 public function setStreet($street) 00486 { 00487 $this->_parameters['strasse'] = $street; 00488 return $this; 00489 } 00490 00497 public function setCounty($county) 00498 { 00499 $this->_parameters['bundesland'] = $county; 00500 return $this; 00501 } 00502 00510 public function setRawParameter($key, $value) 00511 { 00512 $this->_parameters[$key] = $value; 00513 return $this; 00514 } 00515 00521 public function getSearchParameters() 00522 { 00523 $retVal = array(); 00524 foreach ($this->_parameters as $key => $value) { 00525 if (is_null($value)) { 00526 continue; 00527 } 00528 $param = array( 00529 'parameter' => $key, 00530 'value' => $value 00531 ); 00532 $retVal[] = $param; 00533 } 00534 return $retVal; 00535 } 00536 }