You are here

public function GeoProximityArgument::getFormula in Geolocation Field 8.3

Get the formula for this argument.

Overrides ProximityArgument::getFormula

File

modules/geolocation_geometry/src/Plugin/views/argument/GeoProximityArgument.php, line 25

Class

GeoProximityArgument
Argument handler for geolocation proximity.

Namespace

Drupal\geolocation_geometry\Plugin\views\argument

Code

public function getFormula() {

  // Parse argument for reference location.
  $values = $this
    ->getParsedReferenceLocation();

  // Make sure we have enough information to start with.
  if (!empty($values) && isset($values['lat']) && isset($values['lng']) && isset($values['distance'])) {
    $distance = self::convertDistance((double) $values['distance'], $values['unit']);

    // Build a formula for the where clause.
    $formula = self::getGeometryProximityQueryFragment($this->tableAlias, $this->realField, $values['lat'], $values['lng']);

    // Set the operator and value for the query.
    $this->operator = $values['operator'];
    $this->distance = $distance;
    return !empty($formula) ? str_replace('***table***', $this->tableAlias, $formula) : FALSE;
  }
  else {
    return FALSE;
  }
}