You are here

function getlocations_entity_type_map in Get Locations 7.2

Page callback: displays a map.

Parameters

string $type:

int $entity_id:

Return value

Returns a map of locations of an entity

1 call to getlocations_entity_type_map()
getlocations_box in ./getlocations.module
Function for colorbox and suchlike
1 string reference to 'getlocations_entity_type_map'
getlocations_menu in ./getlocations.module
Implements hook_menu().

File

./getlocations.module, line 290
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_entity_type_map($type, $entity_id) {
  $entity_type = getlocations_get_entity_type_from_path($type);
  $locations = getlocations_load_locations($entity_id, $entity_type);
  $entity_get_info = entity_get_info($entity_type);
  $load_hook = $entity_get_info['load hook'];
  $object = $load_hook($entity_id);
  $entity_link = '';
  $uri_callback = '';
  if (isset($entity_get_info['uri callback'])) {
    $uri_callback = $entity_get_info['uri callback'];
    $entity_link = $uri_callback($object);
  }
  $entity_title = '';
  $title = 'name';
  if (isset($entity_get_info['entity keys']['label'])) {
    $title = $entity_get_info['entity keys']['label'];
  }
  if (isset($object->{$title})) {
    $entity_title = $object->{$title};
  }
  $getlocations_defaults = getlocations_defaults();
  $marker = $getlocations_defaults['map_marker'];
  if (isset($getlocations_defaults[$entity_type . '_map_marker'])) {
    $marker = $getlocations_defaults[$entity_type . '_map_marker'];
  }
  $getlocations_markers = variable_get('getlocations_markers', array());
  if (isset($getlocations_markers[$entity_type]['enable']) && $getlocations_markers[$entity_type]['enable']) {
    $type_markers = getlocations_get_type_markers();
    foreach ($type_markers as $et => $bundles) {
      if ($et == $entity_type) {
        foreach ($bundles as $bundle => $field_names) {
          foreach ($field_names as $field_name => $marker_data) {
            if (isset($getlocations_markers[$entity_type][$bundle][$field_name]['marker']) && $getlocations_markers[$entity_type][$bundle][$field_name]['marker']) {
              $marker = $getlocations_markers[$entity_type][$bundle][$field_name]['marker'];
            }
          }
        }
      }
    }
  }
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $ct = 0;
  $extra_info = array();
  $sv_info = FALSE;
  $map_info = FALSE;
  $module = getlocations_get_current_supported_module();
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if ($latlon = getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $ll = explode(',', $latlon);
        $location['latitude'] = $ll[0];
        $location['longitude'] = $ll[1];
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        $location['entity_id'] = $entity_id;
        $location['entity_type'] = $entity_type;

        // TODO term markers
        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }
        $name = '';
        if (isset($location['name']) && $location['name']) {
          $name = htmlspecialchars_decode(strip_tags($location['name']), ENT_QUOTES);
        }
        elseif ($entity_title) {
          $name = htmlspecialchars_decode(strip_tags($entity_title), ENT_QUOTES);
        }
        $latlons[$ct] = array(
          $location['latitude'],
          $location['longitude'],
          $location['entity_id'],
          $name,
          $marker,
          $location['entity_type'],
          '',
          '',
        );
        $sv_info = FALSE;
        if ($module == 'getlocations_fields' && count($locations) == 1) {
          if (getlocations_fields_streetview_settings_allow()) {
            $sv_info = getlocations_fields_svinfo($location);
          }
          if (getlocations_fields_map_settings_allow()) {
            $map_info = getlocations_fields_mapinfo($location);
          }
        }
        $ct++;
      }
    }
  }
  if ($ct < 2) {
    unset($minmaxes);
    $minmaxes = '';
  }

  #drupal_set_title(t('View !t locations', array('!t' => $entity_title)));
  $entity_info = array(
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
    'entity_title' => $entity_title,
    'entity_link' => $entity_link,
  );
  if ($sv_info) {
    $extra_info = array_merge($extra_info, $sv_info);
  }
  if ($map_info) {
    $extra_info = array_merge($extra_info, $map_info);
  }
  return getlocations_setlocations($latlons, $minmaxes, $entity_info, $object, $extra_info);
}