Community

Combine geofields of nodes and user in a single view

I'm using the ip_geoloc module (http://drupal.org/project/ip_geoloc) to display a geofield attached to my node-contents.
In my usecase the users should also be visible on this map - users and nodes share the same field for the address and geo-coordinates.

How can i combine these two different types in just one view?

I already tried hook_views_pre_execute() described in http://drupal.org/node/748844#comment-7070234 but could not get it working in my view cause i was not able to create the same query views builds to retrieve the geofield-data.

<?php
/**
* Implements hook_views_pre_execute()
*/
function costum_map_views_pre_execute(&$view) {

 
// Add additional query to get users in map.
 
if ($view->name == 'user_event_map') {

   
//extracts my nodes
   
$query2 = db_select('users', 'users');
   
$query2->join('field_data_field_geofield','user_geo','user_geo.entity_id = users.uid');
   
//created and nid are the same fields used by my_view query
   
$query2->addField('users', 'name', 'node_title');
   
$query2->addField('users', 'uid', 'uid');
   
$query2->addField('user_geo', 'bundle', 'field_data_field_geofield_node_entity_type');

   
//set some conditions if necessary
   
$query2->condition('users.uid', '1', '>');

   
//union custom query with my_view default query
   
$query2->union($view->build_info['query'], 'UNION ALL');

   
//in order to prevent Cardinality violation errors i have to make a "total" query
   
$total_query = db_select($query2, 'total')->fields('total');

   
//update views query and count_query with my new query.
   
$view->build_info['query'] = $total_query;
   
$view->build_info['count_query'] = $view->build_info['query']; //count_query is necessary for the pager
 
}
}
?>

SteffenR

nobody click here