You are here

public static function BoundaryTrait::getBoundaryQueryFragment in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/BoundaryTrait.php \Drupal\geolocation\BoundaryTrait::getBoundaryQueryFragment()

Gets the query fragment for adding a boundary field to a query.

Parameters

string $table_name: The proximity table name.

string $field_id: The proximity field ID.

string $filter_lat_north_east: The latitude to filter for.

string $filter_lng_north_east: The longitude to filter for.

string $filter_lat_south_west: The latitude to filter for.

string $filter_lng_south_west: The longitude to filter for.

Return value

string The fragment to enter to actual query.

2 calls to BoundaryTrait::getBoundaryQueryFragment()
BoundaryArgument::query in src/Plugin/views/argument/BoundaryArgument.php
Set up the query for this argument.
BoundaryFilter::query in src/Plugin/views/filter/BoundaryFilter.php
Add this filter to the query.

File

src/BoundaryTrait.php, line 29

Class

BoundaryTrait
Trait BoundaryTrait.

Namespace

Drupal\geolocation

Code

public static function getBoundaryQueryFragment($table_name, $field_id, $filter_lat_north_east, $filter_lng_north_east, $filter_lat_south_west, $filter_lng_south_west) {

  // Define the field name.
  $field_lat = "{$table_name}.{$field_id}_lat";
  $field_lng = "{$table_name}.{$field_id}_lng";

  /*
   * Map shows a map, not a globe. Therefore it will never flip over
   * the poles, but it will move across -180°/+180° longitude.
   * So latitude will always have north larger than south, but east not
   * necessarily larger than west.
   */
  return "({$field_lat} BETWEEN {$filter_lat_south_west} AND {$filter_lat_north_east})\n      AND\n      (\n        ({$filter_lng_south_west} < {$filter_lng_north_east} AND {$field_lng} BETWEEN {$filter_lng_south_west} AND {$filter_lng_north_east})\n        OR\n        (\n          {$filter_lng_south_west} > {$filter_lng_north_east} AND (\n            {$field_lng} BETWEEN {$filter_lng_south_west} AND 180 OR {$field_lng} BETWEEN -180 AND {$filter_lng_north_east}\n          )\n        )\n      )\n    ";
}