You are here

function getlocations_fields_handler_argument_bbox::query in Get Locations 7.2

Same name and namespace in other branches
  1. 7 modules/getlocations_fields/handlers/getlocations_fields_handler_argument_bbox.inc \getlocations_fields_handler_argument_bbox::query()

Use the filter to modify the query.

Overrides views_handler_argument::query

File

modules/getlocations_fields/handlers/getlocations_fields_handler_argument_bbox.inc, line 62
getlocations_fields_handler_argument_bbox.inc @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Class

getlocations_fields_handler_argument_bbox
Argument handler to accept bbox

Code

function query($group_by = FALSE) {
  $this
    ->ensure_my_table();
  if (empty($this->argument) || $this->view->base_field == 'search_api_id') {
    return;
  }
  if (!($bbox = $this
    ->_convert_bbox_coords($this->argument))) {
    return;
  }
  $table_alias = empty($this->table_alias) ? '' : $this->table_alias . '.';
  $this->query
    ->ensure_table($table_alias);
  if ($bbox['right'] > $bbox['left']) {
    $where = $table_alias . "latitude > :minlat\n      AND " . $table_alias . "latitude < :maxlat\n      AND ((" . $table_alias . "longitude < 180\n      AND " . $table_alias . "longitude > :minlon)\n      OR (" . $table_alias . "longitude < :maxlon\n      AND " . $table_alias . "longitude > -180))";
  }
  else {
    $where = $table_alias . "latitude > :minlat\n      AND " . $table_alias . "latitude < :maxlat\n      AND " . $table_alias . "longitude > :minlon\n      AND " . $table_alias . "longitude < :maxlon";
  }
  $group = $this->query
    ->set_where_group('AND');
  $this->query
    ->add_where_expression($group, $where, array(
    ':minlat' => $bbox['bottom'],
    ':maxlat' => $bbox['top'],
    ':minlon' => $bbox['right'],
    ':maxlon' => $bbox['left'],
  ));
}