You are here

function getlocations_get_path_from_lid in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \getlocations_get_path_from_lid()

Function to get entity path from getlocations_fields_entities or location_instance table.

Parameters

int $lid:

Return value

Returns entity path as url.

1 call to getlocations_get_path_from_lid()
theme_getlocations_lidinfo in ./getlocations.module
Returns HTML of a url, requested by ajax.

File

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

Code

function getlocations_get_path_from_lid($lid) {
  if (is_numeric($lid) && $lid) {
    $query = FALSE;
    if (module_exists('getlocations_fields')) {
      $query = db_select('getlocations_fields_entities', 'i')
        ->fields('i', array(
        'nid',
        'uid',
        'tid',
        'cid',
      ))
        ->condition('i.glid', $lid);
    }
    elseif (module_exists('location') && (module_exists('location_cck') || module_exists('location_node') || module_exists('location_user'))) {
      $query = db_select('location_instance', 'i')
        ->fields('i', array(
        'nid',
        'uid',
      ))
        ->condition('i.lid', $lid);
    }
    if ($query) {
      $row = $query
        ->execute()
        ->fetchAssoc();
      $path = '';
      if (isset($row['nid']) && $row['nid'] > 0) {
        $path = url('node/' . $row['nid']);
      }
      elseif (isset($row['uid']) && $row['uid'] > 0) {
        $path = url('user/' . $row['uid']);
      }
      elseif (isset($row['tid']) && $row['tid'] > 0 && module_exists('taxonomy')) {
        $path = url('taxonomy/term/' . $row['tid']);
      }
      elseif (isset($row['cid']) && $row['cid'] > 0 && module_exists('comment')) {
        $path = url('comment/' . $row['cid']);
      }
      return $path;
    }
  }
  return FALSE;
}