From fce7d3d3d0794c14d9cf598238c3688098a3aa7e Mon Sep 17 00:00:00 2001
Date: Sat, 12 Mar 2011 19:21:13 +1000
Subject: [PATCH 1/2] Expose any data columns of a CCK field to feeds.

---
 mappers/content.inc |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/mappers/content.inc b/mappers/content.inc
index 5a64d92..851381b 100644
--- a/mappers/content.inc
+++ b/mappers/content.inc
@@ -18,6 +18,17 @@ function content_feeds_node_processor_targets_alter(&$targets, $content_type) {
       if (in_array($field['type'], array('text', 'number_integer', 'number_decimal', 'number_float'))) {
         $fields[$field_name] = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
       }
+      elseif (is_array($keys = array_keys($field['columns']))) {
+        $name = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
+        foreach ($keys as $key) {
+          $targets[$field_name .':'. $key] = array(
+            'name' => t('!field_name (!key)', array('!field_name' => $name, '!key' => $key)),
+            'callback' => 'content_subfield_feeds_set_target',
+            'description' => t('The column !key for the CCK !name field of the node.', array('!key' => $key, '!name' => $name)),
+            'real_target' => $field_name,
+          );
+        }
+      }
     }
   }
   foreach ($fields as $k => $name) {
@@ -56,3 +67,37 @@ function content_feeds_set_target($node, $target, $value) {
 
   $node->$target = $field;
 }
+
+/**
+ * Callback for mapping to subfields of a CCK field.
+ *
+ * @param $node
+ *   Reference to the node object we are working on.
+ * @param $target
+ *   The selected subfield of a CCK field.
+ * @param $value
+ *   The value to assign to the subfield of a CCK field.
+ */
+function content_subfield_feeds_set_target($node, $target, $value) {
+  if (!empty($value)) {
+    static $defaults = array();
+    list($field_name, $sub_field) = split(':', $target);
+    $field_data = isset($node->$field_name) ? $node->$field_name : array();
+
+    if (!is_array($value)) {
+      $value = array($value);
+    }
+
+    $i = 0;
+    foreach ($value as $v) {
+      if ($v instanceof FeedsEnclosure) {
+        $v = $v->getValue();
+      }
+      $field_data[$i][$sub_field] = $v;
+      $i++;
+    }
+
+    $node->$field_name = $field_data;
+  }
+}
+
-- 
1.7.1


From 7d86197cc75953c9b7e7798e9f0f236966501c93 Mon Sep 17 00:00:00 2001
Date: Sat, 12 Mar 2011 20:01:49 +1000
Subject: [PATCH 2/2] Added generic support for mapping of multiple CCK field columns.

---
 mappers/content.inc |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/mappers/content.inc b/mappers/content.inc
index 851381b..dbeef1c 100644
--- a/mappers/content.inc
+++ b/mappers/content.inc
@@ -11,6 +11,9 @@
  * @see FeedsNodeProcessor::getMappingTargets().
  */
 function content_feeds_node_processor_targets_alter(&$targets, $content_type) {
+  // Exclude field types that already have a more specific mapper in feeds from column mapping, such as link.
+  $exclude_column_mapping = array('example_type');
+
   $info = content_types($content_type);
   $fields = array();
   if (isset($info['fields']) && count($info['fields'])) {
@@ -18,11 +21,11 @@ function content_feeds_node_processor_targets_alter(&$targets, $content_type) {
       if (in_array($field['type'], array('text', 'number_integer', 'number_decimal', 'number_float'))) {
         $fields[$field_name] = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
       }
-      elseif (is_array($keys = array_keys($field['columns']))) {
+      elseif (is_array($keys = array_keys($field['columns'])) && !in_array($field['type'], $exclude_column_mapping)) {
         $name = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
         foreach ($keys as $key) {
-          $targets[$field_name .':'. $key] = array(
-            'name' => t('!field_name (!key)', array('!field_name' => $name, '!key' => $key)),
+          $targets[$field_name .':column:'. $key] = array(
+            'name' => t('!field_name (!key column)', array('!field_name' => $name, '!key' => $key)),
             'callback' => 'content_subfield_feeds_set_target',
             'description' => t('The column !key for the CCK !name field of the node.', array('!key' => $key, '!name' => $name)),
             'real_target' => $field_name,
@@ -81,7 +84,8 @@ function content_feeds_set_target($node, $target, $value) {
 function content_subfield_feeds_set_target($node, $target, $value) {
   if (!empty($value)) {
     static $defaults = array();
-    list($field_name, $sub_field) = split(':', $target);
+    list($field_name, $col, $sub_field) = split(':', $target);
+
     $field_data = isset($node->$field_name) ? $node->$field_name : array();
 
     if (!is_array($value)) {
-- 
1.7.1

