function _ip_geoloc_key_map in IP Geolocation Views & Maps 8
Same name and namespace in other branches
- 7 plugins/ip_geoloc.statistics.inc \_ip_geoloc_key_map()
Helper function to map db fields to array keys.
Maps accesslog db fields as exposed by hook_better_statistics_fields() to the corresponding array key of the array returned by ip_geoloc_get_visitor_location(), inclusive of expected type and size and vice-versa.
Parameters
string $db_field_name: The name of the db field for which to return the corresponding array key.
string $ip_geoloc_key: The name of the array key for which to return the corresponding db field.
Return value
mixed Either way, the an array containing ip_geoloc array key, type and size, or a string with the db field name. If no arguments specified, return the entire mapping array.
3 calls to _ip_geoloc_key_map()
- ip_geoloc_better_statistics_fields in plugins/
ip_geoloc.statistics.inc - Implements hook_better_statistics_fields().
- _ip_geoloc_get_location_field_value in plugins/
ip_geoloc.statistics.inc - Return the value of an ip_geoloc key, for the target database field name.
- _ip_geoloc_statistics_backfill in plugins/
ip_geoloc.statistics.inc - Backfills position information to past {accesslog} entries.
File
- plugins/
ip_geoloc.statistics.inc, line 242 - Capture IP Geoloc statistics in the access log.
Code
function _ip_geoloc_key_map($db_field_name = NULL, $ip_geoloc_key = NULL) {
static $keys;
if (!isset($keys)) {
$keys = [
'geoloc_latitude' => [
'latitude',
'float',
'big',
],
'geoloc_longitude' => [
'longitude',
'float',
'big',
],
'geoloc_country' => [
'country',
'string',
64,
],
'geoloc_country_code' => [
'country_code',
'string',
3,
],
'geoloc_region' => [
'region',
'string',
64,
],
'geoloc_region_code' => [
'region_code',
'string',
3,
],
'geoloc_city' => [
'city',
'string',
64,
],
'geoloc_postal_code' => [
'postal_code',
'string',
12,
],
'geoloc_locality' => [
'locality',
'string',
64,
],
'geoloc_street' => [
'route',
'string',
64,
],
'geoloc_street_number' => [
'street_number',
'string',
32,
],
'geoloc_admin_area_level_1' => [
'administrative_area_level_1',
'string',
64,
],
'geoloc_admin_area_level_2' => [
'administrative_area_level_2',
'string',
64,
],
'geoloc_admin_area_level_3' => [
'administrative_area_level_3',
'string',
64,
],
'geoloc_formatted_address' => [
'formatted_address',
'string',
128,
],
'geoloc_provider' => [
'provider',
'string',
64,
],
'geoloc_accuracy' => [
'accuracy',
'float',
'big',
],
];
}
if ($db_field_name) {
return isset($keys[$db_field_name]) ? $keys[$db_field_name] : NULL;
}
elseif ($ip_geoloc_key) {
foreach ($keys as $key => $item) {
if ($item[0] == $ip_geoloc_key) {
return $key;
}
}
return NULL;
}
else {
return $keys;
}
}