function ip_geoloc_better_statistics_fields in IP Geolocation Views & Maps 8
Same name and namespace in other branches
- 7 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 = [];
// 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 = [
'langcode' => 'en',
];
$fields['geoloc_latitude'] = [
'schema' => [
'description' => 'Latitude',
],
'views_field' => [
'title' => t('Latitude', [], $en),
'help' => t('Geographic latitude.', [], $en),
],
];
$fields['geoloc_longitude'] = [
'schema' => [
'description' => 'Longitude',
],
'views_field' => [
'title' => t('Longitude', [], $en),
'help' => t('Geographic longitude.', [], $en),
],
];
$fields['geoloc_country'] = [
'schema' => [
'description' => 'Country',
],
'views_field' => [
'title' => t('Country', [], $en),
'help' => t('Country.', [], $en),
],
];
$fields['geoloc_country_code'] = [
'schema' => [
'description' => 'ISO 3166 2-Character Country Code',
],
'views_field' => [
'title' => t('Country code', [], $en),
'help' => t('ISO 3166 2-Character Country Code.', [], $en),
],
];
$fields['geoloc_region'] = [
'schema' => [
'description' => 'Region',
],
'views_field' => [
'title' => t('Region', [], $en),
'help' => t('Region.', [], $en),
],
];
$fields['geoloc_region_code'] = [
'schema' => [
'description' => '2-Character Region Code',
],
'views_field' => [
'title' => t('Region code', [], $en),
'help' => t('2-Character Region Code.', [], $en),
],
];
$fields['geoloc_city'] = [
'schema' => [
'description' => 'City',
],
'views_field' => [
'title' => t('City', [], $en),
'help' => t('City.', [], $en),
],
];
$fields['geoloc_postal_code'] = [
'schema' => [
'description' => 'Post code',
],
'views_field' => [
'title' => t('Post code', [], $en),
'help' => t('Post code.', [], $en),
],
];
$fields['geoloc_locality'] = [
'schema' => [
'description' => 'Suburb',
],
'views_field' => [
'title' => t('Suburb', [], $en),
'help' => t('Suburb.', [], $en),
],
];
$fields['geoloc_street'] = [
'schema' => [
'description' => 'Street',
],
'views_field' => [
'title' => t('Street', [], $en),
'help' => t('Street.', [], $en),
],
];
$fields['geoloc_street_number'] = [
'schema' => [
'description' => 'Street number',
],
'views_field' => [
'title' => t('Street number', [], $en),
'help' => t('Street number.', [], $en),
],
];
$fields['geoloc_admin_area_level_1'] = [
'schema' => [
'description' => 'State or province',
],
'views_field' => [
'title' => t('State or province', [], $en),
'help' => t('State or province.', [], $en),
],
];
$fields['geoloc_admin_area_level_2'] = [
'schema' => [
'description' => 'Area level 2',
],
'views_field' => [
'title' => t('Area level 2', [], $en),
'help' => t('Area level 2.', [], $en),
],
];
$fields['geoloc_admin_area_level_3'] = [
'schema' => [
'description' => 'Area level 3',
],
'views_field' => [
'title' => t('Area level 3', [], $en),
'help' => t('Area level 3.', [], $en),
],
];
$fields['geoloc_formatted_address'] = [
'schema' => [
'description' => 'Address',
],
'views_field' => [
'title' => t('Address', [], $en),
'help' => t('Address.', [], $en),
],
];
$fields['geoloc_provider'] = [
'schema' => [
'description' => 'Provider',
],
'views_field' => [
'title' => t('Provider', [], $en),
'help' => t('Provider.', [], $en),
],
];
$fields['geoloc_accuracy'] = [
'schema' => [
'description' => 'Accuracy',
],
'views_field' => [
'title' => t('Accuracy', [], $en),
'help' => t('Accuracy.', [], $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;
}