You are here

public function GeoProximityFilter::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 ProximityFilter::query

File

modules/geolocation_geometry/src/Plugin/views/filter/GeoProximityFilter.php, line 22

Class

GeoProximityFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation_geometry\Plugin\views\filter

Code

public function query() {
  $table = $this
    ->ensureMyTable();
  $this->value['value'] = self::convertDistance($this->value['value'], $this->options['unit']);
  if (array_key_exists('lat', $this->value) && array_key_exists('lng', $this->value)) {
    $center = [
      'lat' => (double) $this->value['lat'],
      'lng' => (double) $this->value['lng'],
    ];
  }
  else {
    $center = $this->locationInputManager
      ->getCoordinates((array) $this->value['center'], $this->options['location_input'], $this);
  }
  if (empty($center) || !is_numeric($center['lat']) || !is_numeric($center['lng']) || empty($this->value['value'])) {
    return;
  }

  // Build the query expression.
  $expression = self::getGeometryProximityQueryFragment($table, $this->realField, $center['lat'], $center['lng']);

  // Get operator info.
  $info = $this
    ->operators();

  // Make sure a callback exists and add a where expression for the chosen
  // operator.
  if (!empty($info[$this->operator]['method']) && method_exists($this, $info[$this->operator]['method'])) {
    $this
      ->{$info[$this->operator]['method']}($expression);
  }
}