You are here

function getlocations_get_type_from_lid in Get Locations 7

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

Function to get entity type from getlocations_fields_entities or location_instance table.

Parameters

int $lid:

Return value

Returns entity type.

2 calls to getlocations_get_type_from_lid()
getlocations_getinfo in ./getlocations.module
getlocations_load_location in ./getlocations.module
Function to fetch a location

File

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

Code

function getlocations_get_type_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();
      $type = '';
      if (isset($row['nid']) && $row['nid'] > 0) {
        $type = 'node';
      }
      elseif (isset($row['uid']) && $row['uid'] > 0) {
        $type = 'user';
      }
      elseif (isset($row['tid']) && $row['tid'] > 0 && module_exists('taxonomy')) {
        $type = 'vocabulary';
      }
      elseif (isset($row['cid']) && $row['cid'] > 0 && module_exists('comment')) {
        $type = 'comment';
      }
      return $type;
    }
  }
  return FALSE;
}