De-coupling geobrowser from location module

NicolasH - September 2, 2008 - 04:11
Project:Geobrowser
Version:5.x-7.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Given that the location module seems to be simply used for storage of lat/lon data against a node, how about making this a bit more flexible so other modules can provide this simple data set via a custom query?

Currently one would need to hack the geobrowser module to change where the lat/lon data comes from, but by exposing a hook that could be left to other modules.

<?php
// Call a hook that'll let modules define their own location node queries.
     
foreach (module_implements('geobrowser_get_nodes_sql') as $module) {
       
$function = $module .'_geobrowser_get_nodes_sql';
       
$get_nodes = $function($view);
      }
       
     
// If no other module offered a query, use the standard location module to retrieve geo data from.
     
if (!$get_nodes) {
       
$get_nodes = "
          SELECT
          {location}.latitude AS geobrowser_lat,
          {location}.longitude AS geobrowser_lon,
          {location}.eid AS geobrowser_vid,
          {node}.nid AS geobrowser_nid,
          tid"
.$_REQUEST['current_tree']." as term_node_tid,
          {node}.title AS node_revisions_title,
          {votingapi_vote}.value IS NULL AS isnull
       
          FROM  {location}
          INNER JOIN {node} ON {node}.vid = {location}.eid
          $layers_sql
          LEFT JOIN {votingapi_vote} ON {node}.nid = {votingapi_vote}.content_id
       
          WHERE
        "
;
       
       
$get_nodes .= "{location}.longitude < %s AND {location}.longitude > %s AND {location}.latitude < %s AND {location}.latitude > %s"; //filtering so that we are only selecting nodes within our view screen.
     
}
?>

#1

phayes - September 2, 2008 - 20:07

THis is great! Thank you

#2

NicolasH - September 4, 2008 - 07:21

Ooops, I copied that loop from the views module...

$get_nodes = $function($view);

should only be

$get_nodes = $function();

where that function then returns the appropriate SQL - no need for any arguments really.

 
 

Drupal is a registered trademark of Dries Buytaert.