SearchParameters.php 14 KB

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