From a5120dde2c526cf8184a6eeeb9bf5374b160fe9a Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 5 Aug 2016 14:59:26 +0200 Subject: [PATCH] [Castorus] Allow filter via ZIP code or city name --- bridges/CastorusBridge.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bridges/CastorusBridge.php b/bridges/CastorusBridge.php index 69d89614..55ff7b75 100644 --- a/bridges/CastorusBridge.php +++ b/bridges/CastorusBridge.php @@ -6,6 +6,30 @@ class CastorusBridge extends BridgeAbstract { $this->uri = $this->getURI(); $this->description = "Returns the latest changes"; $this->update = "2016-08-05"; + + $this->parameters["Get latest changes"] = '[]'; + $this->parameters["Get latest changes via ZIP code"] = + '[ + { + "name": "ZIP code", + "identifier" : "zip", + "type" : "text", + "required" : "true", + "exampleValue" : "74910, 74", + "title" : "Insert ZIP code (complete or partial)" + } + ]'; + $this->parameters["Get latest changes via city name"] = + '[ + { + "name": "City name", + "identifier" : "city", + "type" : "text", + "required" : "true", + "exampleValue" : "Seyssel, Seys", + "title" : "Insert city name (complete or partial)" + } + ]'; } // Extracts the tile from an actitiy @@ -55,6 +79,12 @@ class CastorusBridge extends BridgeAbstract { } public function collectData(array $params){ + if(isset($params['zip'])) + $zip_filter = trim($params['zip']); + + if(isset($params['city'])) + $city_filter = trim($params['city']); + $html = $this->file_get_html($this->getURI()); if(!$html) @@ -74,6 +104,14 @@ class CastorusBridge extends BridgeAbstract { $item->content = '' . $item->title . '

' . $this->ExtractActivityPrice($activity) . '

'; + if(isset($zip_filter) && !(substr($item->title, 0, strlen($zip_filter)) === $zip_filter)){ + continue; // Skip this item + } + + if(isset($city_filter) && !(substr($item->title, strpos($item->title, ' ') + 1, strlen($city_filter)) === $city_filter)){ + continue; // Skip this item + } + $this->items[] = $item; } }