You are here

function lti_tool_provider_create_account in LTI Tool Provider 7

Provision a user account from the lti_info.

Parameters

string $lti_user: The lti user name.

array $lti_info: The lti context info.

Return value

object The user account object or FALSE if the account creation failed.

2 calls to lti_tool_provider_create_account()
lti_tool_provider_launch in ./lti_tool_provider.operations.inc
LTI launch.
lti_tool_provider_memberships_add_member in lti_tool_provider_memberships/lti_tool_provider_memberships.module
Add a membership for a new user.

File

./lti_tool_provider.module, line 644
lti_tool_provider hook implementations and support functions.

Code

function lti_tool_provider_create_account($lti_user, $lti_info) {

  // If a user image is supplied create a managed file,
  // and attach it to the user account.
  if (isset($context_info['user_image'])) {
    $file = (object) array(
      'uid' => 1,
      'uri' => $context_info['user_image'],
      'filename' => drupal_basename($lti_info['user_image']),
      'filemime' => file_get_mimetype($filepath),
      'status' => 1,
    );
    $file = file_save($file);
    $picture = $file->fid;
  }
  else {
    $picture = 0;
  }

  // Construct the userinfo to be used to create the account.
  $user_attribute_settings = variable_get('lti_tool_provider_user_attribute_mapping', array());
  $fields = _lti_tool_provider_retrieve_user_field_types('TEXT');
  $userinfo = array(
    'name' => $lti_user,
    'pass' => user_password(20),
    'init' => $lti_info['lis_person_contact_email_primary'],
    'mail' => $lti_info['lis_person_contact_email_primary'],
    'picture' => $picture,
    'status' => 1,
    'access' => REQUEST_TIME,
  );
  foreach ($user_attribute_settings as $variable => $field) {
    if ($field != 'none' && isset($fields[$field]) && isset($lti_info[$variable])) {
      $userinfo[$field] = array(
        LANGUAGE_NONE => array(
          '0' => array(
            'value' => $lti_info[$variable],
          ),
        ),
      );
    }
  }
  $account = user_save(drupal_anonymous_user(), $userinfo);

  // Allow other modules to alter the newly provisioned lti user account.
  drupal_alter('lti_tool_provider_create_account', $account, $lti_info);
  return $account;
}