You are here

function domain_update_users in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain.module \domain_update_users()
  2. 7.2 domain.module \domain_update_users()

FormsAPI to handle the batch update of users.

1 string reference to 'domain_update_users'
domain_form_user_admin_account_alter in ./domain.module
Implements hook_form_alter().

File

./domain.module, line 842
Core module functions for the Domain Access suite.

Code

function domain_update_users($form, &$form_state) {
  $values = $form_state['values'];
  if ($values['operation'] != 'domain') {
    return;
  }

  // Get the domains for this user, but ignore roles unless told to use them.
  $add_roles = variable_get('domain_add_roles', 0);

  // Loop through the selected accounts.
  $domains = array_filter($values['domains']);
  foreach ($values['accounts'] as $uid) {

    // If appending values, do so here.
    if (!empty($form_state['values']['behavior'])) {
      $account = new stdClass();
      $account->uid = $uid;
      $current = domain_get_user_domains($account, $add_roles);

      // Behavior 1: add new domains.
      if ($form_state['values']['behavior'] == 1) {
        $domains += $current;
      }
      else {
        foreach ($domains as $domain_id) {
          if (isset($current[$domain_id])) {
            unset($current[$domain_id]);
          }
        }
        $domains = $current;
      }
    }
    db_delete('domain_editor')
      ->condition('uid', $uid)
      ->execute();
    foreach ($domains as $domain_id) {
      db_insert('domain_editor')
        ->fields(array(
        'uid' => $uid,
        'domain_id' => $domain_id,
      ))
        ->execute();
    }
  }
}