You are here

function janrain_capture_mapping_janrain_capture_profile_sync in Janrain Registration 7.4

Same name and namespace in other branches
  1. 7 janrain_capture_mapping/janrain_capture_mapping.module \janrain_capture_mapping_janrain_capture_profile_sync()
  2. 7.2 janrain_capture_mapping/janrain_capture_mapping.module \janrain_capture_mapping_janrain_capture_profile_sync()
  3. 7.3 janrain_capture_mapping/janrain_capture_mapping.module \janrain_capture_mapping_janrain_capture_profile_sync()

Implements hook_janrain_capture_profile_sync().

File

janrain_capture_mapping/janrain_capture_mapping.module, line 75
This module implements a data mapping UI for Janrain Capture

Code

function janrain_capture_mapping_janrain_capture_profile_sync($account, $profile) {
  $map = variable_get('janrain_capture_mapping_map', array());
  $wrapper = entity_metadata_wrapper('user', $account);
  $capture_fields = db_query("SELECT fid, path FROM {janrain_capture_mapping_field}")
    ->fetchAllKeyed();
  foreach ($map as $mapping) {
    try {
      $fields = explode('.', $capture_fields[$mapping['fid']]);
      $profile_current = $profile;
      foreach ($fields as $field) {
        if (array_key_exists($field, $profile_current)) {
          $profile_current = $profile_current[$field];
        }
        else {
          throw new EntityMetadataWrapperException();
        }
      }
      $value = $profile_current;

      // Date fields must be properly formatted as a timestamp
      if ($wrapper->{$mapping['field']}
        ->type() == 'date') {
        $value = $value ?: strtotime($value);
      }
      $wrapper->{$mapping['field']} = $value;
    } catch (EntityMetadataWrapperException $e) {
      watchdog('janrain_capture_mapping', 'Attempt to map attr @attr to field @field failed', array(
        '@attr' => $field,
        '@field' => $mapping['field'],
      ));
    }
  }
}