Index: mappers/location.inc =================================================================== RCS file: mappers/location.inc diff -N mappers/location.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ mappers/location.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,75 @@ + 0) { + // We need the collect settings + $subfields = $settings['form']['fields']; + // locpick is a compound field. So split it + $subfields['locpick][user_latitude'] = $subfields['locpick']; + $subfields['locpick][user_longitude'] = $subfields['locpick']; + unset($subfields['locpick']); + + // We need the labels + $location_fields= location_field_names(TRUE); + unset($location_fields['locpick']); + $location_fields['locpick][user_latitude'] = t("Latitude"); + $location_fields['locpick][user_longitude'] = t("Longitude"); + + foreach ($subfields as $subfield => $values) { + // Note: we warn the user for non collect fields + $targets[ 'locations' . ':' . $subfield] = array( + 'name' => t('Location module !label', array('!label' => $location_fields[$subfield] . ($values['collect'] ? "" : ' ' . t('not collected')))), + 'callback' => 'location_feeds_set_target', + 'description' => t('The !label for the location of the node.', array('!label' => $subfield)), + ); + } + } +} + +/** + * Implementation of feed_set_target + * + * @param object $node + * @param string $target + * When targeting sub arrays the '][' is used to drill down. + * Note that this implementation is lazy ... we assume just depth=2 + * @param $value + * @return object + */ +function location_feeds_set_target($node, $target, $value) { + list($field_name, $sub_field) = split(':', $target); + if (strpos($sub_field, '][') > 0) { + // TODO : this should be done better but it works + list($sub_field, $last_field) = split('\]\[', $sub_field, 2); + } + + if (!is_array($value)) { + $value = array($value); + } + + foreach ($value as $i => $val) { + if (isset($last_field)) { + $node->locations[$i][$sub_field][$last_field] = $val; + } + else { + $node->locations[$i][$sub_field] = $val; + } + } + return $node; +} Index: mappers/location_cck.inc =================================================================== RCS file: mappers/location_cck.inc diff -N mappers/location_cck.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ mappers/location_cck.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,64 @@ + $field) { + if (in_array($field['type'], array('location'))) { + $subfields = array( + 'street' => 'street', + 'city' => 'city', + 'province' => 'state/province', + 'postal_code' => 'postal/zip code', + 'locpick][user_latitude' => 'latitude', + 'locpick][user_longitude' => 'longitude', + ); + $name = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name; + foreach ($subfields as $subfield => $label) { + $targets[$field_name .':' . $subfield] = array( + 'name' => t('!field_name (!label)', array('!field_name' => $name, '!label' => $label)), + 'callback' => 'location_cck_feeds_set_target', + 'description' => t('The !label for the CCK !name field of the node.', array('!name' => $name, '!label' => $label)), + ); + } + } + } + } +} + +/** + * Settings the mapping values for location CCK + */ + +function location_cck_feeds_set_target($node, $target, $value) { + list($field_name, $sub_field) = split(':', $target); + + if (strpos($sub_field, '][') > 0) { + // TODO : this should be done better but it works + list($sub_field, $last_field) = split('\]\[', $sub_field, 2); + } + if (is_array($value)) { + foreach ($value as $i => $val) { + if (isset($last_field)) { + $node->{$field_name}[$i][$sub_field][$last_field] = $val; + } + else { + $node->{$field_name}[$i][$sub_field] = $val; + } + } + } else { + $node->{$field_name}[0][$sub_field] = $value; + } + return $node; +}