You are here

function ip_geoloc_is_in_range in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 ip_geoloc.module \ip_geoloc_is_in_range()

Determines if a value is within the supplied numeric or alphabetical range.

String comparison is based on the ASCII/UTF8 order, so is case-sensitive.

Parameters

string $value: The value to check in $range

string $range: Of the form '1.5--4.5' (range is inclusive of end points)

Return value

bool TRUE if the value is in range

3 calls to ip_geoloc_is_in_range()
ip_geoloc_plugin_style_leaflet::render in views/ip_geoloc_plugin_style_leaflet.inc
Transform the View result in a list of marker locations and render on map.
_ip_geoloc_plugin_style_find_association_by_differentiator_value in views/ip_geoloc_plugin_style.inc
_ip_geoloc_plugin_style_set_marker_color in views/ip_geoloc_plugin_style.inc
Set the marker color based on the differentiator, if any.

File

./ip_geoloc.module, line 741
IPGV&M is a mapping engine for Views that contain locations of entities and/or visitors. Google Maps, Leaflet and OpenLayers2 maps are all supported. and available through this module. Using a number of optional sources IPGV&M also retrieves…

Code

function ip_geoloc_is_in_range($value, $range, $view_args = NULL) {
  if (!isset($value) || !isset($range)) {
    return FALSE;
  }

  // Defensive programming to make sure we have a string.
  if (is_array($range)) {
    $range = reset($range);
  }
  $from_to = explode(IP_GEOLOC_RANGE_SEPARATOR1, $range);
  if (count($from_to) < 2) {
    $from_to = explode(IP_GEOLOC_RANGE_SEPARATOR2, $range);
  }
  if (($from = _ip_geoloc_extract_value($from_to[0], $view_args)) === NULL) {
    return FALSE;
  }
  if (count($from_to) == 1) {

    // Single value.
    return trim($value) == trim($from);
  }
  if (($to = _ip_geoloc_extract_value($from_to[1], $view_args)) === NULL) {
    return FALSE;
  }
  if ($from == '' && $to == '') {

    // Range separator without values.
    return TRUE;
  }
  if ($from != '' && $to != '') {
    return $value >= $from && $value <= $to;
  }
  if ($from != '') {
    return $value >= $from;
  }
  return $value <= $to;
}