You are here

function _tac_lite_user_tids in Taxonomy Access Control Lite 6

Same name and namespace in other branches
  1. 8 tac_lite.module \_tac_lite_user_tids()
  2. 5 tac_lite.module \_tac_lite_user_tids()
  3. 7 tac_lite.module \_tac_lite_user_tids()

Return the term ids of terms this user is allowed to access.

Users are granted access to terms either because of who they are, or because of the roles they have.

3 calls to _tac_lite_user_tids()
tac_lite_create_form_alter in ./tac_lite_create.module
Implementation of hook_form_alter().
tac_lite_db_rewrite_sql in ./tac_lite.module
tac_lite_node_grants in ./tac_lite.module
Implementation of hook_node_grants().

File

./tac_lite.module, line 456
Control access to site content based on taxonomy, roles and users.

Code

function _tac_lite_user_tids($account, $scheme) {

  // grant id 0 is reserved for nodes which were not given a grant id when they were created. By adding 0 to the grant id, we let the user view those nodes.
  $grants = array(
    0,
  );
  $config = _tac_lite_config($scheme);
  $realm = $config['realm'];
  if (isset($account->{$realm}) && count($account->{$realm})) {

    // $account->$realm is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access
    foreach ($account->{$realm} as $tids) {
      if (count($tids)) {
        $grants = array_merge($grants, $tids);
      }
    }
  }

  // add per-role grants in addition to per-user grants
  $defaults = variable_get('tac_lite_grants_scheme_' . $scheme, array());
  foreach ($account->roles as $rid => $role_name) {
    if (isset($defaults[$rid]) && count($defaults[$rid])) {
      foreach ($defaults[$rid] as $tids) {
        if (count($tids)) {
          $grants = array_merge($grants, $tids);
        }
      }
    }
  }

  // Because of some flakyness in the form API and the form we insert under
  // user settings, we may have a bogus entry with vid set
  // to ''. Here we make sure not to return that.
  unset($grants['']);
  return $grants;
}