You are here

public function ProximityArgument::getParsedReferenceLocation 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::getParsedReferenceLocation()
  2. 8.2 src/Plugin/views/argument/ProximityArgument.php \Drupal\geolocation\Plugin\views\argument\ProximityArgument::getParsedReferenceLocation()

Processes the passed argument into an array of relevant geolocation data.

Return value

array|bool The calculated values.

1 call to ProximityArgument::getParsedReferenceLocation()
ProximityArgument::getFormula in src/Plugin/views/argument/ProximityArgument.php

File

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

Class

ProximityArgument
Argument handler for geolocation proximity.

Namespace

Drupal\geolocation\Plugin\views\argument

Code

public function getParsedReferenceLocation() {

  // Cache the vales so this only gets processed once.
  static $values;
  if (!isset($values)) {

    // Process argument values into an array.
    preg_match('/^([0-9\\-.]+),+([0-9\\-.]+)([<>=]+)([0-9.]+)(.*$)/', $this
      ->getValue(), $values);

    // Validate and return the passed argument.
    $values = is_array($values) ? [
      'lat' => isset($values[1]) && is_numeric($values[1]) && $values[1] >= -90 && $values[1] <= 90 ? floatval($values[1]) : FALSE,
      'lng' => isset($values[2]) && is_numeric($values[2]) && $values[2] >= -180 && $values[2] <= 180 ? floatval($values[2]) : FALSE,
      'operator' => isset($values[3]) && in_array($values[3], [
        '<>',
        '=',
        '>=',
        '<=',
        '>',
        '<',
      ]) ? $values[3] : '<=',
      'distance' => isset($values[4]) ? floatval($values[4]) : FALSE,
      'units' => isset($values[5]) && strpos(strtolower($values[5]), 'mile') !== FALSE ? 'mile' : 'km',
    ] : FALSE;
  }
  return $values;
}