You are here

function workbench_access_rebuild_user in Workbench Access 7

Rebuild the user access tables.

Parameters

$uid: The user id being updated.

$sections: An array of section ids to set for the user.

1 call to workbench_access_rebuild_user()
workbench_access_user_form_submit in ./workbench_access.admin.inc
Save user assignments.

File

./workbench_access.module, line 1045
Workbench Access module file.

Code

function workbench_access_rebuild_user($uid, $sections = array()) {

  // Get the user and scheme data.
  $account = user_load($uid);
  $user_sections = array_keys($account->workbench_access);
  $access_scheme = variable_get('workbench_access');

  // Check to see if any sections have been removed.
  $removed = array_diff($user_sections, $sections);
  foreach ($removed as $access_id) {
    workbench_access_user_section_delete($uid, $access_id, $access_scheme);
  }

  // Add the new sections.
  $added = array_diff($sections, $user_sections);
  foreach ($added as $access_id) {
    workbench_access_user_section_save($uid, $access_id, $access_scheme);
  }
}