You are here

function salesforce_api_fieldmap_export_create in Salesforce Suite 5.2

Same name and namespace in other branches
  1. 6.2 salesforce_api/salesforce_api.module \salesforce_api_fieldmap_export_create()
  2. 7 salesforce_api/salesforce_api.module \salesforce_api_fieldmap_export_create()
  3. 7.2 salesforce_api/salesforce_api.module \salesforce_api_fieldmap_export_create()

Creates an object for export to Salesforce based on the supplied source object and fieldmap.

Parameters

$index: The index of the fieldmap used to filter the source object into the export.

$source: The source object used to generate the export.

Return value

An object of the source type ready for export to Salesforce or FALSE if the operation failed.

3 calls to salesforce_api_fieldmap_export_create()
salesforce_api_demo in salesforce_api/salesforce_api.module
Demonstrates some of the API functionality through the Salesforce class and fieldmap functionality.
sf_node_export in sf_node/sf_node.module
Exports a node to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the node.
sf_user_export in sf_user/sf_user.module
Exports a user to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the user.

File

salesforce_api/salesforce_api.module, line 720
Defines an API that enables modules to interact with the Salesforce server.

Code

function salesforce_api_fieldmap_export_create($index, $source = NULL) {

  // Load the fieldmap from the database.
  $map = salesforce_api_fieldmap_load($index);

  // Fail if the fieldmap does not exist.
  if (!$map) {
    return FALSE;
  }

  // Load the source object definition so we know how to get values for its
  // various fields.
  if ($map['action'] == 'import') {
    $source_object = salesforce_api_fieldmap_objects_load('salesforce', $map['salesforce']);
  }
  else {
    $source_object = salesforce_api_fieldmap_objects_load('drupal', $map['drupal']);
  }
  $object = new stdClass();

  // Loop through the fields on the fieldmap.
  foreach ($map['fields'] as $key => $value) {

    // If a handler is specified for retrieving a value for the source field...
    if (isset($source_object['fields'][$value]['export'])) {

      // Get the value for the field from the handler function.
      $object->{$key} = $source_object['fields'][$value]['export']($source, $value);
    }
    elseif (isset($source->{$value})) {

      // Otherwise set the field on the export object to the value of the source
      // field if it's present on the source object.
      $object->{$key} = $source->{$value};
    }
  }
  return $object;
}