You are here

public function ProximityArgument::getFormula in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/argument/ProximityArgument.php \Drupal\geolocation\Plugin\views\argument\ProximityArgument::getFormula()
  2. 8.2 src/Plugin/views/argument/ProximityArgument.php \Drupal\geolocation\Plugin\views\argument\ProximityArgument::getFormula()

Overrides Formula::getFormula

1 call to ProximityArgument::getFormula()
ProximityArgument::query in src/Plugin/views/argument/ProximityArgument.php
Build the query based upon the formula

File

src/Plugin/views/argument/ProximityArgument.php, line 77

Class

ProximityArgument
Argument handler for geolocation proximity.

Namespace

Drupal\geolocation\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 ($values && $values['lat'] && $values['lng'] && $values['distance']) {

    // Get the earth radius in from the units.
    $earth_radius = $values['units'] === 'mile' ? GeolocationCore::EARTH_RADIUS_MILE : GeolocationCore::EARTH_RADIUS_KM;

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

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