You are here

function _tac_lite_user_tids in Taxonomy Access Control Lite 7

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. 6 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_node_grants in ./tac_lite.module
Implementation of hook_node_grants().
tac_lite_query_term_access_alter in ./tac_lite.module
Implements hook_query_TAG_alter().

File

./tac_lite.module, line 633
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->data[$realm]) && count($account->data[$realm])) {

    // $account->$realm is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access
    foreach ($account->data[$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;
}