You are here

function ip_geoloc_better_statistics_fields in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 plugins/ip_geoloc.statistics.inc \ip_geoloc_better_statistics_fields()

Implements hook_better_statistics_fields().

File

plugins/ip_geoloc.statistics.inc, line 11
Capture IP Geoloc statistics in the access log.

Code

function ip_geoloc_better_statistics_fields() {
  $fields = array();

  // Pass all user-facing strings through t(), but always use English when first
  // declaring fields. They will be run through t() normally on output.
  $en = array(
    'langcode' => 'en',
  );
  $fields['geoloc_latitude'] = array(
    'schema' => array(
      'description' => 'Latitude',
    ),
    'views_field' => array(
      'title' => t('Latitude', array(), $en),
      'help' => t('Geographic latitude.', array(), $en),
    ),
  );
  $fields['geoloc_longitude'] = array(
    'schema' => array(
      'description' => 'Longitude',
    ),
    'views_field' => array(
      'title' => t('Longitude', array(), $en),
      'help' => t('Geographic longitude.', array(), $en),
    ),
  );
  $fields['geoloc_country'] = array(
    'schema' => array(
      'description' => 'Country',
    ),
    'views_field' => array(
      'title' => t('Country', array(), $en),
      'help' => t('Country.', array(), $en),
    ),
  );
  $fields['geoloc_country_code'] = array(
    'schema' => array(
      'description' => 'ISO 3166 2-Character Country Code',
    ),
    'views_field' => array(
      'title' => t('Country code', array(), $en),
      'help' => t('ISO 3166 2-Character Country Code.', array(), $en),
    ),
  );
  $fields['geoloc_region'] = array(
    'schema' => array(
      'description' => 'Region',
    ),
    'views_field' => array(
      'title' => t('Region', array(), $en),
      'help' => t('Region.', array(), $en),
    ),
  );
  $fields['geoloc_region_code'] = array(
    'schema' => array(
      'description' => '2-Character Region Code',
    ),
    'views_field' => array(
      'title' => t('Region code', array(), $en),
      'help' => t('2-Character Region Code.', array(), $en),
    ),
  );
  $fields['geoloc_city'] = array(
    'schema' => array(
      'description' => 'City',
    ),
    'views_field' => array(
      'title' => t('City', array(), $en),
      'help' => t('City.', array(), $en),
    ),
  );
  $fields['geoloc_postal_code'] = array(
    'schema' => array(
      'description' => 'Post code',
    ),
    'views_field' => array(
      'title' => t('Post code', array(), $en),
      'help' => t('Post code.', array(), $en),
    ),
  );
  $fields['geoloc_locality'] = array(
    'schema' => array(
      'description' => 'Suburb',
    ),
    'views_field' => array(
      'title' => t('Suburb', array(), $en),
      'help' => t('Suburb.', array(), $en),
    ),
  );
  $fields['geoloc_street'] = array(
    'schema' => array(
      'description' => 'Street',
    ),
    'views_field' => array(
      'title' => t('Street', array(), $en),
      'help' => t('Street.', array(), $en),
    ),
  );
  $fields['geoloc_street_number'] = array(
    'schema' => array(
      'description' => 'Street number',
    ),
    'views_field' => array(
      'title' => t('Street number', array(), $en),
      'help' => t('Street number.', array(), $en),
    ),
  );
  $fields['geoloc_admin_area_level_1'] = array(
    'schema' => array(
      'description' => 'State or province',
    ),
    'views_field' => array(
      'title' => t('State or province', array(), $en),
      'help' => t('State or province.', array(), $en),
    ),
  );
  $fields['geoloc_admin_area_level_2'] = array(
    'schema' => array(
      'description' => 'Area level 2',
    ),
    'views_field' => array(
      'title' => t('Area level 2', array(), $en),
      'help' => t('Area level 2.', array(), $en),
    ),
  );
  $fields['geoloc_admin_area_level_3'] = array(
    'schema' => array(
      'description' => 'Area level 3',
    ),
    'views_field' => array(
      'title' => t('Area level 3', array(), $en),
      'help' => t('Area level 3.', array(), $en),
    ),
  );
  $fields['geoloc_formatted_address'] = array(
    'schema' => array(
      'description' => 'Address',
    ),
    'views_field' => array(
      'title' => t('Address', array(), $en),
      'help' => t('Address.', array(), $en),
    ),
  );
  $fields['geoloc_provider'] = array(
    'schema' => array(
      'description' => 'Provider',
    ),
    'views_field' => array(
      'title' => t('Provider', array(), $en),
      'help' => t('Provider.', array(), $en),
    ),
  );
  $fields['geoloc_accuracy'] = array(
    'schema' => array(
      'description' => 'Accuracy',
    ),
    'views_field' => array(
      'title' => t('Accuracy', array(), $en),
      'help' => t('Accuracy.', array(), $en),
    ),
  );

  // Cycles through definitions to update schema type/size/legth.
  foreach ($fields as $field_name => &$field) {
    $field['callback'] = '_ip_geoloc_get_field_value';
    $field['schema']['not null'] = FALSE;
    list($ip_geoloc_key, $type, $size) = _ip_geoloc_key_map($field_name);
    switch ($type) {
      case 'boolean':
        $field['schema']['type'] = 'int';
        $field['schema']['size'] = 'tiny';
        break;
      case 'string':
        if ($size) {
          $field['schema']['type'] = 'varchar';
          $field['schema']['length'] = $size;
        }
        else {
          $field['schema']['type'] = 'text';
        }
        break;
      case 'float':
      case 'int':
        $field['schema']['type'] = $type;
        if ($size) {
          $field['schema']['size'] = $size;
        }
        break;
    }
  }
  return $fields;
}