You are here

function sms_user_login_metadata in SMS Framework 7

Same name and namespace in other branches
  1. 6.2 modules/sms_user/sms_user.module \sms_user_login_metadata()

Stores metadata related to SMS users registering/logging in.

Drupal core does not really provide a way to pass user metadata around that's related to a user registering (meaning during the registration cycle), so we provide a storage mechanism here.

Since it seems sloppy to handle registration cycles with one method and logins with another, this function handles all SMS-related metadata related to logging in and registering.

The data is placed in this storage mechansim for the duration of the page load, and is placed here before the user hooks are invoked by sms_user, therefore it should be available to all modules that need it.

Parameters

int $uid: (optional) The uid of the user to store/fetch. Defaults to null, in which case returns all cached accounts.

array $metadata: (optional) The metadata to store, or the metadata to fetch if NULL or not supplied. The metadata is stored/retrieved as an associative array with the following key/value pairs:

  • register: bool Indicates that the user is just registering.
  • login: bool Indicates that the user is logging in.
  • number: string The SMS number the message was sent from.
  • message: string The SMS message sent with the registration/login.
  • options: array The SMS message metadata passed from the gateway.

bool $reset: If true, reset the accounts cache.

Return value

mixed No uid set: An array, key = uid, value = An associative array of account metadata. uid set, no metadata set: An associative array of account metadata. uid set, metadata set: Cache the metadata for the user, return TRUE.

2 calls to sms_user_login_metadata()
sms_user_register_new_user in modules/sms_user/sms_user.module
Registers a new user via SMS
sms_user_sms_incoming in modules/sms_user/sms_user.module
Implements hook_sms_incoming().

File

modules/sms_user/sms_user.module, line 984
Provides integration between the SMS Framework and Drupal users.

Code

function sms_user_login_metadata($uid = NULL, $metadata = NULL, $reset = FALSE) {
  static $accounts = array();
  if ($reset) {
    $accounts = array();
  }
  if (!isset($uid)) {
    return $accounts;
  }
  if (isset($metadata)) {
    $accounts[$uid] = $metadata;
    return TRUE;
  }
  elseif (isset($accounts[$uid])) {
    return $accounts[$uid];
  }
  else {
    return FALSE;
  }
}