Skip to content

Commit

Permalink
#326 - Filter tags for searching in polygon area.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed May 6, 2021
1 parent 21c4ce5 commit 2e72498
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/app/scripts/php/libs/Filter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,45 @@ public function lower($name, $than, $orEqual = false) {
$this->greateOrLower($name, $than, $orEqual, "<");
}

public function geoContains(callable $template, $latitudeName, $longitudeName) {
$parent = $this->current->peek();

$instance = new FilterModel();
$this->current->push($instance);
$template();
$this->current->pop();

$area = $instance[0];
if (!empty($area)) {
$latitudeName = $this->formatColumnName($parent, $latitudeName);
$longitudeName = $this->formatColumnName($parent, $longitudeName);
$parent[] = "ST_CONTAINS($area, point($latitudeName, $longitudeName))";
}
}

public function geoPolygon(callable $template) {
$instance = $this->current->peek();

$parentPoints = $this->points;
$this->points = [];

$template();

$points = implode(", ", $this->points);
if (!empty($points)) {
$instance[] = "ST_GEOMFROMTEXT('POLYGON(($points))')";
}

$this->points = $parentPoints;
}

private $points;

public function geoPoint($latitude, $longitude) {
$this->points[] = "$latitude $longitude";
}


public function getProperty($name) {
return $this->instances[$name];
}
Expand Down
39 changes: 39 additions & 0 deletions src/app/scripts/php/libs/Filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,45 @@
<comment>Zda stejná hodnota má být zahrnuta ve výsledku.</comment>
</attribute>
</tag>
<fulltag>
<name>geoContains</name>
<function>geoContains</function>
<comment>Volání funkce ST_CONTAINS. V těle je možné používat "filter:geoPolygon".</comment>
<attribute>
<name>latitudeName</name>
<type>string</type>
<comment>Název sloupce obsahující "latitude" hodnotu záznamu.</comment>
<required />
</attribute>
<attribute>
<name>longitudeName</name>
<type>string</type>
<comment>Název sloupce obsahující "longitude" hodnotu záznamu.</comment>
<required />
</attribute>
</fulltag>
<fulltag>
<name>geoPolygon</name>
<function>geoPolygon</function>
<comment>Volání funkce POLYGON. V těle je možné používat "filter:geoPoint".</comment>
</fulltag>
<tag>
<name>geoPoint</name>
<function>geoPoint</function>
<comment>Přidá do aktuální kolekce points nové souřadnice.</comment>
<attribute>
<name>latitude</name>
<type>string</type>
<comment>Hodnota "latitude".</comment>
<required />
</attribute>
<attribute>
<name>longitude</name>
<type>string</type>
<comment>Hodnota "longitude".</comment>
<required />
</attribute>
</tag>
<anyProperty>
<comment>Slouží k získání dříve deklarovaného filtru. Název proměnné odpovídá názvu při deklaraci.</comment>
</anyProperty>
Expand Down

0 comments on commit 2e72498

Please sign in to comment.