You are here

function _ip_geoloc_key_map in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 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 = array(
      'geoloc_latitude' => array(
        'latitude',
        'float',
        'big',
      ),
      'geoloc_longitude' => array(
        'longitude',
        'float',
        'big',
      ),
      'geoloc_country' => array(
        'country',
        'string',
        64,
      ),
      'geoloc_country_code' => array(
        'country_code',
        'string',
        3,
      ),
      'geoloc_region' => array(
        'region',
        'string',
        64,
      ),
      'geoloc_region_code' => array(
        'region_code',
        'string',
        3,
      ),
      'geoloc_city' => array(
        'city',
        'string',
        64,
      ),
      'geoloc_postal_code' => array(
        'postal_code',
        'string',
        12,
      ),
      'geoloc_locality' => array(
        'locality',
        'string',
        64,
      ),
      'geoloc_street' => array(
        'route',
        'string',
        64,
      ),
      'geoloc_street_number' => array(
        'street_number',
        'string',
        32,
      ),
      'geoloc_admin_area_level_1' => array(
        'administrative_area_level_1',
        'string',
        64,
      ),
      'geoloc_admin_area_level_2' => array(
        'administrative_area_level_2',
        'string',
        64,
      ),
      'geoloc_admin_area_level_3' => array(
        'administrative_area_level_3',
        'string',
        64,
      ),
      'geoloc_formatted_address' => array(
        'formatted_address',
        'string',
        128,
      ),
      'geoloc_provider' => array(
        'provider',
        'string',
        64,
      ),
      'geoloc_accuracy' => array(
        '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;
  }
}