Enable Location_Type search

Wed, 08/08/2007 - 14:13
Submitted by angela

*******************************************
* set up location_type select option box: *
*******************************************

/modules/location/location.inc
function location_location_type_select_options($value = '', $required = FALSE)
$option_list= array();
$result = db_query('SELECT `tid`, `name` FROM {term_data} WHERE `vid` = 7');
#print_r(db_fetch_array($result));
while ($row = db_fetch_array($result)){

$option_list[$row[tid]] = $row[name];

}
return $option_list;
}

returns array:
Array
(
[19] => Farm Stand
[20] => PYO
[21] => Restaurant
[22] => CSA
[23] => Wholesale
[24] => Online
[36] => Vineyard
[37] => Farmers' Market
[38] => Retailer
)

which comprises the select option list on the proximity search form

*********************************************
* edits to function location_search_results *
*********************************************

/modules/location/location.module
function location_search_results($location_params, $proximity_params)

...edits to db queries to use Al's View instead of node table)
Line 185: $count_query = 'SELECT COUNT(DISTINCT Node_ID) AS count FROM {View_Pre_Radius_Query} v INNER JOIN {location} l ON v.Node_ID = l.eid WHERE v.Location_Type_ID = ' . $proximity_params['location_type'] . ' AND l.type =\'node\' AND l.latitude > %f AND l.latitude < %f AND l.longitude > %f AND l.longitude < %f AND '. earth_distance_sql($latlon['lon'], $latlon['lat']) .' < %f';

Line 189: $query = 'SELECT v.Node_ID, l.*, '. earth_distance_sql($latlon['lon'], $latlon['lat'], 'l') .' as distance FROM {View_Pre_Radius_Query} v INNER JOIN {location} l ON v.Node_ID = l.eid WHERE v.Location_Type_ID = ' . $proximity_params['location_type'] . ' AND l.type =\'node\' AND l.latitude > %f AND l.latitude < %f AND l.longitude > %f AND l.longitude < %f AND '. earth_distance_sql($latlon['lon'], $latlon['lat']) .' < %f GROUP BY v.Node_ID ORDER by distance';

...

Line 205: $pager_count_query = 'SELECT COUNT(DISTINCT Node_ID) AS count FROM {View_Pre_Radius_Query} v INNER JOIN {location} l ON v.Node_ID = l.eid WHERE v.Location_Type_ID = ' . $proximity_params['location_type'] . ' AND l.type =\'node\' AND l.latitude > '. $latrange[0] .' AND l.latitude < '. $latrange[1] .' AND l.longitude > '. $lonrange[0] .' AND l.longitude < '. $lonrange[1] .' AND '. earth_distance_sql($latlon['lon'], $latlon['lat']) .' < '. $distance_float;

Line 209: $pager_query = 'SELECT v.Node_ID, l.*, '. earth_distance_sql($latlon['lon'], $latlon['lat'], 'l') .' AS distance FROM {View_Pre_Radius_Query} v INNER JOIN {location} l ON v.Node_ID = l.eid WHERE v.Location_Type_ID = ' . $proximity_params['location_type'] . ' AND l.type =\'node\' AND l.latitude > '. $latrange[0] .' AND l.latitude < '. $latrange[1] .' AND l.longitude > '. $lonrange[0] .' AND l.longitude < '. $lonrange[1] .' AND '. earth_distance_sql($latlon['lon'], $latlon['lat']) .' < '. $distance_float .' GROUP BY v.Node_ID ORDER by distance';

......
edit to final output to use the View's Node_ID instead of the now non-existent nid from node

Line 274-9: $node = node_load($row->Node_ID);
$output .= theme(
'search_item',
array(
'link' => url('node/'. $row->Node_ID),

Post new comment

  • Allowed HTML tags: <a> <b> <address> <blockquote> <br> <caption> <center> <code> <dd> <del> <div> <dl> <dt> <em> <font> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <li> <ol> <p> <pre> <span> <strong> <sub> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <u> <ul> <tr>
  • Insert Google Map macro.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options