*** C:/date.inc Thu Nov 26 23:12:51 2009 --- C:/date.inc Thu Nov 26 23:12:31 2009 *************** *** 0 **** --- 1,67 ---- + $field) { + + // Check to see if the field type is a date (CCK). + if ($field['type'] == 'date') { + + // Set the name for the source label to be the label of the field or the field name if no label exists + $name = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name; + + //Sets the targets to map + $targets[$field_name.'#date'] = array( + 'name' => $name . ' (' . t('date').')', + 'callback' => 'date_feeds_set_target', + 'description' => t('The Date for the CCK !name field of the node.', array('!name' => $name)), + ); + + } + } + } + } + + /** + * Callback for mapping. Here is where the actual mapping happens. + * + * When the callback is invoked, $target contains the name of the field the + * user has decided to map to and $value contains the value of the feed item + * element the user has picked as a source. + * + * In plain English, maps the source elemnts to the target. + */ + function date_feeds_set_target(&$node, $target, $values) { + //For argument sake, $target = field_date#date + + //Seperate out component parts. $field_name should be set to field_date, $sub_field to date. + list($field_name, $sub_field) = split('#', $target); + + //Set $field to $node->field_date OR a blank array... + $field = isset($node->$field_name) ? $node->$field_name : array(); + + // Handle multiple value fields. + if (is_array($values)) { + $field[0]['value'] = $values['DATE']['DTSTART']['datetime']; + $field[0]['value2'] = $values['DATE']['DTEND']['datetime']; + } + else { + $field[0]['value'] = $values; + } + + $node->$field_name = $field; + }