[Castorus] Allow filter via ZIP code or city name

This commit is contained in:
logmanoriginal 2016-08-05 14:59:26 +02:00
parent db95a2afca
commit a5120dde2c

View file

@ -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 = '<a href="' . $item->uri . '">' . $item->title . '</a><br><p>'
. $this->ExtractActivityPrice($activity) . '</p>';
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;
}
}