GeoProximityFilter.php in Geolocation Field 8.3
File
modules/geolocation_geometry/src/Plugin/views/filter/GeoProximityFilter.php
View source
<?php
namespace Drupal\geolocation_geometry\Plugin\views\filter;
use Drupal\geolocation\Plugin\views\filter\ProximityFilter;
use Drupal\geolocation_geometry\GeometryProximityTrait;
class GeoProximityFilter extends ProximityFilter {
use GeometryProximityTrait;
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;
}
$expression = self::getGeometryProximityQueryFragment($table, $this->realField, $center['lat'], $center['lng']);
$info = $this
->operators();
if (!empty($info[$this->operator]['method']) && method_exists($this, $info[$this->operator]['method'])) {
$this
->{$info[$this->operator]['method']}($expression);
}
}
}