You are here

public function ProximityFilter::query in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/views/filter/ProximityFilter.php \Drupal\geolocation\Plugin\views\filter\ProximityFilter::query()
  2. 8.2 src/Plugin/views/filter/ProximityFilter.php \Drupal\geolocation\Plugin\views\filter\ProximityFilter::query()

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 NumericFilter::query

1 method overrides ProximityFilter::query()
GeoProximityFilter::query in modules/geolocation_geometry/src/Plugin/views/filter/GeoProximityFilter.php
Add this filter to the query.

File

src/Plugin/views/filter/ProximityFilter.php, line 185

Class

ProximityFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\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::getProximityQueryFragment($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);
  }
}