You are here

public function ProximityFilter::query in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 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

File

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

Class

ProximityFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\Plugin\views\filter

Code

public function query() {
  $table = $this
    ->ensureMyTable();

  // Get the field alias.
  $lat = $this
    ->getLatitudeValue();
  $lng = $this
    ->getLongitudeValue();
  if (!is_numeric($lat) || !is_numeric($lng) || isset($this->value['value']) && !is_numeric($this->value['value']) || isset($this->value['min']) && !is_numeric($this->value['min']) || isset($this->value['max']) && !is_numeric($this->value['max'])) {
    return;
  }

  // Get the earth radius from the units.
  $earth_radius = $this
    ->getProximityUnit() === 'mile' ? GeolocationCore::EARTH_RADIUS_MILE : GeolocationCore::EARTH_RADIUS_KM;

  // Build the query expression.
  $expression = $this->geolocationCore
    ->getProximityQueryFragment($table, $this->realField, $lat, $lng, $earth_radius);

  // 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);
  }
}