You are here

function workbench_access_rebuild_scheme in Workbench Access 7

Rebuild the section access tables.

Parameters

$access_scheme: The access scheme to use.

$sections: The sections to add to the table.

1 call to workbench_access_rebuild_scheme()
workbench_access_section_form_submit in ./workbench_access.admin.inc
Save the active section definitions.

File

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

Code

function workbench_access_rebuild_scheme($access_scheme, $sections = array()) {

  // Check to see if any sections have been removed.
  $access_ids = workbench_access_get_ids_by_scheme($access_scheme, TRUE);
  $removed = array_diff($access_ids, array_keys($sections));
  foreach ($removed as $access_id) {
    $record = $access_scheme;
    $record['access_id'] = $access_id;
    if (isset($sections[$access_id]['access_type_id'])) {
      $record['access_type_id'] = $sections[$access_id]['access_type_id'];
    }
    workbench_access_section_delete($record);
  }

  // Add the new sections.
  $added = array_diff(array_keys($sections), $access_ids);
  foreach ($added as $access_id) {
    $record = $access_scheme;
    $record['access_id'] = $access_id;
    if (isset($sections[$access_id]['access_type_id'])) {
      $record['access_type_id'] = $sections[$access_id]['access_type_id'];
    }
    workbench_access_section_save($record);
  }
}