You are here

public function GeofieldProximityArgument::query in Geofield 8

Build the query based upon the formula

Overrides Formula::query

File

src/Plugin/views/argument/GeofieldProximityArgument.php, line 157

Class

GeofieldProximityArgument
Argument handler for geofield proximity.

Namespace

Drupal\geofield\Plugin\views\argument

Code

public function query($group_by = FALSE) {
  $this
    ->ensureMyTable();
  $lat_alias = $this->realField . '_lat';
  $lon_alias = $this->realField . '_lon';
  try {

    /** @var \Drupal\geofield\Plugin\GeofieldProximitySourceInterface $source_plugin */
    $values = $this
      ->getParsedReferenceLocation();
    if (!empty($values)) {
      $source_configuration = [
        'origin' => [
          'lat' => $values['lat'],
          'lon' => $values['lon'],
        ],
      ];
      $this->sourcePlugin = $this->proximitySourceManager
        ->createInstance('geofield_context_filter', $source_configuration);
      $this->sourcePlugin
        ->setViewHandler($this);
      $this->sourcePlugin
        ->setUnits($values['units']);
      if ($haversine_options = $this->sourcePlugin
        ->getHaversineOptions()) {
        $haversine_options['destination_latitude'] = $this->tableAlias . '.' . $lat_alias;
        $haversine_options['destination_longitude'] = $this->tableAlias . '.' . $lon_alias;
        $this
          ->operator($haversine_options, $values['distance'], $values['operator']);
      }
    }
  } catch (\Exception $e) {
    watchdog_exception('geofield', $e);
  }
}