You are here

public function GeolocationSearchApiFilterBoundary::query in Geolocation Field 8.3

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides BoundaryFilter::query

File

modules/geolocation_search_api/src/Plugin/views/filter/GeolocationSearchApiFilterBoundary.php, line 22

Class

GeolocationSearchApiFilterBoundary
Defines a filter for filtering on boundary.

Namespace

Drupal\geolocation_search_api\Plugin\views\filter

Code

public function query() {

  /** @var \Drupal\search_api\Plugin\views\query\SearchApiQuery $query */
  $query = $this
    ->getQuery();
  if ($query
    ->shouldAbort()) {
    return;
  }
  if (empty($this->value)) {
    return;
  }

  // Get the field alias.
  $lat_north_east = $this->value['lat_north_east'];
  $lng_north_east = $this->value['lng_north_east'];
  $lat_south_west = $this->value['lat_south_west'];
  $lng_south_west = $this->value['lng_south_west'];
  if (!is_numeric($lat_north_east) || !is_numeric($lng_north_east) || !is_numeric($lat_south_west) || !is_numeric($lng_south_west)) {
    return;
  }
  $query
    ->addCondition($this->realField, [
    $lat_south_west . ',' . $lng_south_west,
    $lat_north_east . ',' . $lng_north_east,
  ], 'BETWEEN', $this->options['group']);
}