You are here

function getlocations_fields_load_location in Get Locations 7.2

Same name and namespace in other branches
  1. 7 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 2312
getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_fields_load_location($glid) {
  $location = array();
  if ($glid) {
    module_load_include('inc', 'getlocations_fields', 'getlocations_fields.functions');
    $getlocations_fields_defaults = getlocations_fields_defaults();
    $getlocations_defaults = getlocations_defaults();
    $fields = array(
      'glid',
      'name',
      'street',
      'additional',
      'city',
      'province',
      'postal_code',
      'country',
      'address',
      'latitude',
      'longitude',
      'marker',
      'field_name',
    );
    if (getlocations_fields_column_check('data')) {
      $fields[] = 'data';
    }
    $query = db_select('getlocations_fields', 'f');
    $query
      ->fields('f', $fields);
    $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;
      $location['field_name'] = $row->field_name;
      $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'];
      }

      // need to find entity_type and entity_id and bundle
      $entity_info = getlocations_get_entity_info_from_glid($location['glid']);
      $location['entity_type'] = $entity_info['entity_type'];
      $location['entity_id'] = $entity_info['entity_id'];
      $location['bundle'] = $entity_info['bundle'];
      $entity_get_info = entity_get_info($location['entity_type']);
      if (!isset($entity_get_info['entity keys']['id'])) {
        return;
      }
      $location['entity_key'] = $entity_get_info['entity keys']['id'];

      // figure out the marker
      if (empty($location['marker'])) {
        $marker = $getlocations_defaults['map_marker'];
        $markertype = $location['entity_type'] . '_map_marker';
        if (isset($getlocations_defaults[$markertype]) && $getlocations_defaults[$markertype]) {
          $marker = $getlocations_defaults[$markertype];
        }
        $getlocations_markers = variable_get('getlocations_markers', array());
        if (isset($getlocations_markers[$location['entity_type']]['enable']) && $getlocations_markers[$location['entity_type']]['enable']) {
          if (isset($getlocations_markers[$location['entity_type']][$location['bundle']][$location['field_name']]['marker']) && $getlocations_markers[$location['entity_type']][$location['bundle']][$location['field_name']]['marker']) {
            $marker = $getlocations_markers[$location['entity_type']][$location['bundle']][$location['field_name']]['marker'];
          }
        }
        $location['marker'] = $marker;
      }
    }
  }
  return $location;
}