You are here

function _sf_notifications_parse_message in Salesforce Suite 6.2

Same name and namespace in other branches
  1. 7.2 sf_notifications/sf_notifications.module \_sf_notifications_parse_message()

Parse SOAP message into its component args.

Parameters

(object) $domDoc: A DOMDocument representation of the outbound SOAP message from SalesForce.

Return value

(array) $result An array with two sub-arrays, keyed as: 'drupal': A sequential array containing relevant salesforce_ids records. We don't index on drupal_id because there could be overlap. 'salesforce': An indexed array mapping sfids to SObject records from SalesForce.

1 call to _sf_notifications_parse_message()
sf_notifications_endpoint in sf_notifications/sf_notifications.module
Menu callback for SalesForce notifications endpoint @todo Add authentication. see "Downloading the Salesforce.com Client Certificate" at http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax...

File

sf_notifications/sf_notifications.module, line 372

Code

function _sf_notifications_parse_message($domDoc) {
  $result = array(
    'salesforce' => array(),
    'drupal' => array(),
  );
  $sfids = array();

  // Create sObject array and fill fields provided in notification
  $objects = $domDoc
    ->getElementsByTagName('sObject');
  foreach ($objects as $sObjectNode) {
    $sObjType = $sObjectNode
      ->getAttribute('xsi:type');
    if (substr_count($sObjType, 'sf:')) {
      $sObjType = substr($sObjType, 3);
    }
    $obj = new SObject();
    $obj->type = $sObjType;
    $elements = $sObjectNode
      ->getElementsByTagNameNS('urn:sobject.enterprise.soap.sforce.com', '*');
    $obj->fieldnames = array();
    foreach ($elements as $node) {
      if ($node->localName == 'Id') {

        // "Id" is a property of the SObject as well as SObject->fields
        $sfids[] = $obj->Id = $node->textContent;
      }
      $fieldname = $node->localName;
      $obj->fields->{$fieldname} = $node->nodeValue;
      array_push($obj->fieldnames, $fieldname);
    }
    $result['salesforce'][$obj->Id] = $obj;
  }
  $dbresult = db_query('SELECT name, oid, sfid, drupal_type FROM {salesforce_object_map} WHERE sfid IN (' . db_placeholders($sfids, 'varchar') . ')', $sfids);
  while ($row = db_fetch_array($dbresult)) {
    $result['drupal'][] = $row;
  }
  return $result;
}