You are here

function workbench_access_get_access_tree in Workbench Access 7

Get the access hierarchy for a user.

Parameters

$account_access: The access rules for the user performing the action.

Return value

An array of access rules.

1 call to workbench_access_get_access_tree()
workbench_access_in_tree in ./workbench_access.module
Check to see if an access check is in a given hierarchy.
1 string reference to 'workbench_access_get_access_tree'
workbench_access_reset_tree in ./workbench_access.module
Reset tree data stored in statics.

File

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

Code

function workbench_access_get_access_tree($account_access = array()) {
  $trees =& drupal_static(__FUNCTION__);
  if (empty($account_access)) {
    $account = $GLOBALS['user'];
    workbench_access_user_load_data($account);
    $account_access = array_keys($account->workbench_access);
  }
  $key = implode($account_access);
  if (isset($trees[$key])) {
    return $trees[$key];
  }
  $trees[$key] = array();
  if (empty($account_access)) {
    return $trees[$key];
  }
  $access_scheme = db_select('workbench_access', 'wa')
    ->addTag('workbench_access')
    ->fields('wa', array(
    'access_id',
    'access_type',
    'access_scheme',
    'access_type_id',
  ))
    ->condition('wa.access_id', $account_access, 'IN')
    ->condition('wa.access_type', variable_get('workbench_access'))
    ->execute()
    ->fetchAllAssoc('access_id', PDO::FETCH_ASSOC);
  foreach ($access_scheme as $id => $info) {
    $trees[$key][$id] = workbench_access_tree($info, TRUE);
  }
  return $trees[$key];
}