public function IpGeoLocGlobal::isInRange in IP Geolocation Views & Maps 8
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)
mixed $view_args: The value to check in $range.
Return value
bool TRUE if the value is in range
File
- src/
Services/ IpGeoLocGlobal.php, line 409
Class
- IpGeoLocGlobal
- Class IpGeoLocGlobal.
Namespace
Drupal\ip_geoloc\ServicesCode
public function isInRange($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;
}