function getlocations_fields_load_location in Get Locations 7
Same name and namespace in other branches
- 7.2 modules/getlocations_fields/getlocations_fields.module \getlocations_fields_load_location()
Parameters
int $glid: Location ID
2 calls to getlocations_fields_load_location()
- getlocations_fields_field_load in modules/
getlocations_fields/ getlocations_fields.module - Implements hook_field_load(). Define custom load behavior for this module's field types. http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
- getlocations_load_location in ./
getlocations.module - Function to fetch a location
File
- modules/
getlocations_fields/ getlocations_fields.module, line 2518 - getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_fields_load_location($glid) {
global $user;
$roles = $user->roles;
$location = array();
if ($glid) {
module_load_include('inc', 'getlocations_fields', 'getlocations_fields.functions');
$getlocations_fields_defaults = getlocations_fields_defaults();
$fields = array(
'glid',
'name',
'street',
'additional',
'city',
'province',
'postal_code',
'country',
'address',
'latitude',
'longitude',
'marker',
);
if (getlocations_fields_column_check('data')) {
$fields[] = 'data';
}
$query = db_select('getlocations_fields', 'f');
$query
->fields('f', $fields);
$query
->fields('e', array(
'nid',
'vid',
'uid',
'tid',
'cid',
));
$query
->join('getlocations_fields_entities', 'e', 'f.glid=e.glid');
# if (! in_array('administrator', $roles)) {
# if ($key == 'nid') {
# $query->join('node', 'n', 'n.nid = e.nid');
# $query->condition('e.nid', $id)->condition('n.status', 0, '>');
# }
# elseif ($key == 'vid') {
# $query->join('node_revision', 'n', 'n.vid = e.vid');
# $query->condition('e.vid', $id)->condition('n.status', 0, '>');
# }
# elseif ($key == 'uid') {
# $query->join('users', 'n', 'n.uid = e.uid');
# $query->condition('e.uid', $id)->condition('n.status', 0, '>');
# }
# elseif (module_exists('comment') && $key == 'cid') {
# $query->join('comment', 'n', 'n.cid = e.cid');
# $query->condition('e.cid', $id)->condition('n.status', 0, '>');
# }
# }
$query
->condition('f.glid', $glid);
$row = $query
->execute()
->fetchObject();
if ($row) {
$location['glid'] = $row->glid;
$location['lid'] = $row->glid;
$location['name'] = $row->name;
$location['street'] = $row->street;
$location['additional'] = $row->additional;
$location['city'] = $row->city;
$location['province'] = $row->province;
$location['province_name'] = $row->province;
$location['postal_code'] = $row->postal_code;
if ($getlocations_fields_defaults['country_full'] && drupal_strlen($row->country) == 2) {
$location['country_name'] = getlocations_get_country_name($row->country);
}
else {
$location['country_name'] = $row->country;
}
$location['country'] = $row->country;
$location['address'] = $row->address;
$location['latitude'] = $row->latitude;
$location['longitude'] = $row->longitude;
$location['marker'] = $row->marker;
$data = isset($row->data) && !empty($row->data) ? unserialize($row->data) : '';
$keys = getlocations_fields_data_keys('d');
if (is_array($data) && isset($data['data']['map_settings_allow'])) {
$map_settings_allow = $data['data']['map_settings_allow'];
}
else {
$map_settings_allow = getlocations_fields_map_settings_allow();
}
foreach ($keys as $key => $dval) {
$location[$key] = $dval;
if (is_array($data) && isset($data['data'][$key])) {
if (!$map_settings_allow && ($key == 'mapzoom' || $key == 'map_maptype')) {
continue;
}
$location[$key] = $data['data'][$key];
}
}
// what3words
$what3words_lic = variable_get('getlocations_what3words_lic', array(
'key' => '',
'url' => 'http://api.what3words.com',
));
if ($what3words_lic['key'] && is_array($data) && isset($data['data']['what3words'])) {
$location['what3words'] = $data['data']['what3words'];
}
$location['nid'] = $row->nid;
$location['vid'] = $row->vid;
$location['uid'] = $row->uid;
$location['tid'] = $row->tid;
$location['cid'] = $row->cid;
if ($row->nid) {
$location['type'] = 'node';
}
elseif ($row->uid) {
$location['type'] = 'user';
}
elseif ($row->tid) {
$location['type'] = 'vocabulary';
}
elseif ($row->cid) {
$location['type'] = 'comment';
}
}
}
return $location;
}