geo/modules/geo_data/geo_data.module, line 182
- Versions
- 6
geo_data_field($op, &$node, $field, &$items, $teaser, $page)
Implementation of hook_field().
Code
<?php
function geo_data_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'load':
$table = $field['geo_data_table'];
$select = array();
$select[] = geo('field_select', 'geo');
$select[] = $key = db_escape_string(check_plain($field['geo_data_key']));
if (is_array($field['geo_data_value'])) {
foreach ($field['geo_data_value'] as $val) {
$select[] = db_escape_string(check_plain($val));
}
}
foreach ($items as $delta => $item) {
$ret[$delta] = $item;
$sql = "SELECT ". join(',', $select) ." FROM {". $table ."}";
$sql .= " WHERE $key = '%s'";
$res = db_query(db_distinct_field($table, $key, $sql), $item['value']);
while ($row = db_fetch_array($res)) {
foreach ($row as $k => $v) {
$key = 'geo_data_'. $k;
// Simply use the Geo values instead.
if (substr($k, 0, 4) == 'geo_') $key = substr($k, 4);
$ret[$delta][$key] = $v;
if (!isset($ret[$delta]['label']) && in_array($k, $field['geo_data_value'])) {
$ret[$delta]['label'] = $v;
}
}
}
}
// Identify ourselves on the node level for RSS and other postprocessing.
if (!isset($node->geo_fields)) {
$node->geo_fields = array();
}
$node->geo_fields[] = $field['field_name'];
return array($field['field_name'] => $ret, 'geo_fields' => $node->geo_fields);
case 'validate':
return;
}
}
?> 