You are here

function sms_user_user_load in SMS Framework 7

Implements hook_user_load().

Load user mobile data into the user object.

See also

sms_user_user()

File

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

Code

function sms_user_user_load($users) {
  $result = db_select('sms_user', 'u')
    ->fields('u', array(
    'uid',
    'number',
    'status',
    'code',
    'gateway',
    'sleep_enabled',
    'sleep_start_time',
    'sleep_end_time',
    'sms_user_opt_out',
  ))
    ->condition('uid', array_keys($users), 'IN')
    ->execute();
  foreach ($result as $record) {
    if (!empty($record->uid)) {
      $record->gateway = unserialize($record->gateway);
      $users[$record->uid]->sms_user = (array) $record;

      // @todo The following is BC-shim to support messaging that expects
      // account details with a delta of 0.
      $users[$record->uid]->sms_user[0] = (array) $record;
    }
  }

  // Initialize users without records with an empty info array.
  foreach ($users as $id => $user) {
    if (!isset($user->sms_user)) {
      $users[$id]->sms_user = array(
        'uid' => $id,
        'number' => '',
        'status' => 0,
        'code' => 0,
        'gateway' => '',
        'sleep_enabled' => 0,
        'sleep_start_time' => 0,
        'sleep_end_time' => 0,
        'sms_user_opt_out' => 0,
      );

      // @todo The following is a BC-shim to support code that expects account
      // details with a delta of 0.
      $users[$id]->sms_user[0] = $users[$id]->sms_user;
    }
  }
}