You are here

function taxonomy_access_preserve_terms in Taxonomy Access Control 5.2

Same name and namespace in other branches
  1. 5 taxonomy_access.module \taxonomy_access_preserve_terms()
  2. 6 taxonomy_access.module \taxonomy_access_preserve_terms()
1 call to taxonomy_access_preserve_terms()
taxonomy_access_form_alter in ./taxonomy_access.module
Implementation of hook_form_alter()

File

./taxonomy_access.module, line 392
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_preserve_terms($nid = FALSE) {

  // prepare/cache return value
  static $tids = array();

  // a valid numeric nid is required
  if (!is_numeric($nid)) {
    return array();
  }

  // use cached values if possible
  if (isset($tids[$nid])) {
    return $tids[$nid];
  }

  // get a list of terms this user has access to/over
  // (invokes hook_db_rewrite_sql() to limit access)
  $user_terms = taxonomy_node_get_terms($nid);

  // get a list of all terms this node is in regardless of user's
  // access settings. Don't use db_rewrite_sql() api call here (or
  // any other API call, the taxonomy API functions all use
  // db_rewrite_sql() so we must query the database tables directly)
  $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $nid);
  while ($row = db_fetch_array($result)) {

    // only include those terms the current user does not have access to
    if (!isset($user_terms[$row['tid']])) {
      $tids[$nid][$row['tid']] = $row['tid'];
    }
  }

  // return only terms current user does not have access
  // to and therefore need restoring after edit/update
  return $tids[$nid];
}